nginx使用的事php-fpm,所以我们不仅要安装php,还需要安装php-fpm。
使用命令
tar -zxvf php-7.1.8.tar.gz
解压源码包
修改红框标注的位置:开启nginx与php的联系。
源码包地址:
http://php.net/releases/
将php源码包放在linux
/usr/local/src
目录下


解压完成后出现文件夹
php-7.1.8

使用
cd php-7.1.8
进入
php-7.1.8
目录
使用
./configure --prefix=/usr/local/php --enable-fpm
命令配置信息 该命令会在/usr/local目录下自动生成php文件夹

出现下图情况,缺少libxml2,需要安装libxml2
使用命令:
yum -y install
libxml2
通过yum方式安装libxml2

libxml2安装完成后,继续使用
./configure --prefix=/usr/local/php --enable-fpm
配置信息

再次出现同样错误,需要安装libxml2-devel
使用命令:yum install libxml2-devel 通过yum安装libxml2-devel

libxml2-devel安装完成后,继续使用
./configure --prefix=/usr/local/php --enable-fpm
配置信息

配置信息完毕之后,使用命令:
make && make install
安装php

出现以下信息,php安装完成

安装完成后,需要创建PHP配置文件
创建
php.ini文件:
在源码包目录下使用命令:
cp php.ini-production /usr/local/php/etc/php.ini
将
php.ini-production文件复制到
/usr/local/php/etc目录下,并且重命名为
php.ini

创建
php-fpm.conf文件:
使用命令:
cd /usr/local/php/etc 进入/usr/local/php/etc目录下
在目录下使用命令:
cp php-fpm.conf.default php-fpm.conf 将该目录下的
php-fpm.conf.default文件复制到同目录下并改名为
php-fpm.conf

创建
www.conf文件:
使用命令:
cd /usr/local/php/etc/php-fpm.d进入/usr/local/php/etc/php-fpm.d目录下
在目录下使用命令:
cp www.conf.default www.conf 将该目录下的
www.conf.default文件复制到同目录下并改名为
www.conf

创建
lib目录下的
php.ini文件
使用命令:
cd /usr/local/php/etc
进入/usr/local/php/etc目录下
在目录下使用命令:
cp php.ini /usr/local/php/lib/php.ini
将该目录下的
php.ini
文件复制到
/usr/local/php/lib
目录下

配置文件创建完毕!
配置文件创建完毕后需要修改nginx.conf将php与nginx连接起来
使用命令:
cd /usr/local/nginx/conf 进入nginx配置文件目录下
使用命令:
vi nginx.conf 编辑配置文件
修改红框标注的位置:将服务器根目录配置到/www下,默认访问文件加入index.php。

↓


↓

修改nginx配置之后,需要重启nginx。
以上php安装完成!
php-fpm启动命令:
/usr/local/php/sbin/php-fpm
php-fpm查看进程:
ps -ef | grep php-fpm (通过kill pid可停止php)
