CentOS 7 编译安装 php-7.1.6
1、安装下面程序包为即将开始的PHP安装配置系统环境
[[email protected]~]#yum install libxml2 libxml2-developenssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeglibjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devellibmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
2、从网上下载PHP安装包,截止2017.7.4能从官网上找到的最新的稳定版本的PHP是PHP-7.1.6.tar.gz 使用如下指令下载:
[[email protected]~]#wget http://cn2.php.net/distributions/php-7.1.6.tar.gz
3、解压php安装包,并进入安装文件路径
[[email protected]~]# tar -zxvf php-7.1.6.tar.gz
[[email protected]~]#cd php-7.1.6
4、为PHP的安装创建目录
[[email protected] php-7.1.6]# mkdir /usr/src/php
5、接着执行下面指令(一定要在PHP安装包的目录中执行):
[[email protected] php-7.1.6]# ./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
6、make编译和测试
[[email protected] php-7.1.6]# make
[[email protected] php-7.1.6]# make test
7、上一步没有问题后开始安装
[[email protected] php-7.1.6]# make install
8、编译安装完成后清理编译文件
[[email protected] php-7.1.6]# make clean
9、将源代码目录中(php-7.1.6)的php.ini-production文件copy到/usr/local/php/etc/目录下,并将文件名修改为php.ini,如下操作:
[[email protected] php-7.1.6]# cp php.ini-production /usr/local/php/etc/php.ini
10、创建php-fpm的配置文件php-fpm.conf 文件,如下操作:
[[email protected] php-7.1.6]# cd /usr/local/php/etc/
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf
11、创建php-fpm的扩展配置文件www.conf ,如下操作:
[[email protected] etc]# cd php-fpm.d/
[[email protected] php-fpm.d]# cp www.conf.default www.conf
12、创建php-fpm的启动文件并赋予可执行权限,如下操作:
[[email protected] php-fpm.d]#cd
[[email protected]~]#cd php-7.1.6
[[email protected] php-7.1.6]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] php-7.1.6]# chmod a+x /etc/init.d/php-fpm
13、启动php-fpm服务
[[email protected] php-7.1.6]# /etc/init.d/php-fpm start
Starting php-fpm done
上一行的输出信息表示php-fpm已成功启动。
14、测试php-fpm,如下操作:
[[email protected] php-7.1.6]#cd /usr/local/php/sbin
[[email protected] sbin]# ./php-fpm -t
[08-Jul-2017 19:45:03] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
看到上面输出信息中的“successful”就OK了。
15、配置default.conf文件让nginx支持PHP(需先安装好nginx),如下操作:
[[email protected] sbin]# vi /etc/nginx/conf.d/default.conf
这个配置文件需要修改的地方参见图1:
图1
16、按上图修改完default.conf这个配置文件后保存退出。使用指令netstat –ntl查看nginx和php-fpm是否已运行,如图2:图2
如果TCP80端口没有出现,使用下面指令开启nginx服务:
[[email protected] sbin]# systemctl start nginx
17、进入网站根目录,新建一个名为index.php的测试文件。
[[email protected] sbin]# cd /usr/share/nginx/html
[[email protected] html]# ls
50x.html index.html
[[email protected] html]# vi index.php
将以下代码复制到index.php中,保存退出(:wq):
<?php
phpinfo();
?>
18、为/usr/share/nginx/html下的文件或文件夹赋予可执行权限
[[email protected] html]# chmod –R 755 /usr/share/nginx/html
19、打开浏览器测试PHP,http://localhost/index.php 如图3所示,PHP安装成功。
图3