centos7 离线安装PHP及PHP相关扩展

1、安装PHP7  

下载地址 http://hk1.php.net/get/php-7.2.0.tar.gz/from/this/mirror

下载php7(php-7.1.12.tar.gz)包导入centos7 /data/rj

2.解压包

 tar -zxvf php-7.1.12.tar.gz   

3.安装php 之前需要安装mcrypt

 

1).下载Libmcrypt,mhash,mcrypt安装包

libmcrypt-2.5.8.tar.gz
#http://sourceforge.net/project/showfiles.php?group_id=87941&package_id=91774&release_id=487459
mhash-0.9.9.tar.gz
#http://sourceforge.net/project/showfiles.php?group_id=4286&package_id=4300&release_id=645636
mcrypt-2.6.8.tar.gz
# http://sourceforge.net/project/showfiles.php?group_id=87941&package_id=91948&release_id=642101 

2) .先安装Libmcrypt

tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
###/usr/local/php5/bin/phpize #动态编译php模块,使其可以使用configure编译。
./configure
make
make install     # libmcript默认安装在/usr/local

3).安装mhash

tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install

4).安装mcrypt

tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure 
make
make install

注: 可能会出现的错误   configure: error: *** libmcrypt was not found解决方案
()安装到mcrypt的时候出现了问题  
./configure  
提示出错,首先提示  
*** Could not run libmcrypt test program, checking why…  
*** The test program failed to compile or link. See the file config.log for the  
*** exact error that occured. This usually means LIBMCRYPT was incorrectly installed  
*** or that you have moved LIBMCRYPT since it was installed. In the latter case, you  
*** may want to edit the libmcrypt-config script: no  
configure: error: *** libmcrypt was not found  
找了相关资料,得出解决方法明明我安装了libmcrypt 2.5.8 ,可是竟然提示没有发现!然后在/usr/local/bin/找到了LIBMCRYPT_CONFIG ,这一步明确了是PATH变量的问题 !  
方法是ln -s   /usr/local/bin/libmcrypt_config   /usr/bin/libmcrypt_config  
之后继续进行./configure  
仍然报错:  
*** Could not run libmcrypt test program, checking why…  
*** The test program compiled, but did not run. This usually means  
*** that the run-time linker is not finding LIBMCRYPT or finding the wrong  
*** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you’ll need to set your  
*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point  
*** to the installed location   Also, make sure you have run ldconfig if that  
*** is required on your system  
***  
*** If you have an old version installed, it is best to remove it, although  
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH  
***  
configure: error: *** libmcrypt was not found  
  
继续查找,还是变量的问题  
解决方法如下:运行
export LD_LIBRARY_PATH=/usr/local/lib: LD_LIBRARY_PATH  
然后make ; make install  
完成 

4.下载php及PHP扩展相关的包

 

这里需要的包很多就不一一列出了, 可以查看我的链接

链接: php相关扩展包  (https://pan.baidu.com/s/1XTowCqLTE4hDiGpE9hYmQw) 密码: sqwr

也可以通过centos的镜像包中查找相关的rpm包

将已下载的相关包放到/data/other

rpm -Uvh /data/other/*.rpm --nodeps --force
注:--nodeps就是安装时不检查依赖关系,比如你这个rpm需要A,但是你没装A,这样你的包就装不上,
用了--nodeps你就能装上了。--force就是强制安装,比如你装过这个rpm的版本1,如果你想装这个
rpm的版本2,就需要用--force强制安装
 

5. 切换到 php7解压包后的目录   

cd php-7.1.12

如果已安装mysql 可以加 --with-mysqli=/usr/bin/mysql_config   --with-pdo-mysql=/usr/bin/mysql

 

./configure --prefix=/usr/local/php7  --with-config-file-path=/etc  --with-bz2  --with-curl --with-gd    --with-openssl  -with-gettext  --with-xsl --with-zlib-dir --enable-pcntl   --enable-sockets --enable-calendar  --enable-exif  --enable-ftp  --enable-mbstring --enable-fpm   --enable-zip --with-mcrypt   --with-mysqli=/usr/bin/mysql_config --with-pdo-mysql=/usr/bin/mysql

其中:###
--prefix=/usr/local/php7  将php7安装到指定目录
--enable-fpm    编译 PHP 时需要 --enable-fpm 配置选项来激活 FPM 支持。

如果安装mysql

--with-mysqli=--with-mysqli=/usr/bin/mysql_config(查看mysql_config位置)

--with-pdo-mysql=/usr/bin/mysql(查看mysql安装位置)
####
出现(Thank you for using PHP.即为成功)

make    (如果看到Don't forget to run 'make test' 编译成功)
make install
 

6. 测试PHP安装是否成功

cd 
vi test.php
phpinfo();

使用PHP命令执行test.php文件
/usr/local/php7/bin/php  test.php
cd /usr/local/php7/bin/
./php -m  查看PHP已安装的扩展包
 

配置环境变量

将 PHP放入环境变量才能执行 php xxx.php  否则执行php为   /usr/local/php7/bin/php  test.php
vi /etc/profile

export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
export PATH=$PATH:/usr/local/php7/bin
保存后
source /etc/profile

php -v
php  -m 

重启nginx 
systemctl  restart nginx
 

配置PHP

cp php.ini-production /usr/local/php7/etc/php.ini
vi /usr/local/php7/etc/php.ini
zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/opcache.so

复制php-fpm.conf
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
vim /usr/local/php7/etc/php-fpm.conf
把pid 改成 /run/php-fpm.pid

编辑php-fpm配置www.conf会加载在php-fpm.conf中
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
 

加php-fpm管理器到systemctl中

vi /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target
保存退出

重启php
systemctl start php-fpm.service
systemctl enable php-fpm.service
systemctl is-enabled php-fpm.service

systemctl指令
systemctl enable *.service #开机运行服务
systemctl disable *.service #取消开机运行
systemctl is-enabled *.service #服务是否开机运行
systemctl start *.service #启动服务
systemctl stop *.service #停止服务
systemctl restart *.service #重启服务
systemctl reload *.service #重新加载服务配置文件
systemctl status *.service #查询服务运行状态
systemctl --failed #显示启动失败的服务

可以查看:http://bbs.qcloud.com/thread-9907-1-1.html
 

修改php.ini

vi /usr/local/php7/etc/php.ini
expose_php=Off   ##为了防止黑客获取服务器中php版本的信息,可以关闭该信息斜路在http头中
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE

 

你可能感兴趣的:(centos7,php)