1.安装依赖包
1 yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
2.下载安装包
1 cd /usr/local 2 wget https://www.php.net/distributions/php-7.1.31.tar.gz
3.解压
1 tar -zxvf php-7.1.31.tar.gz
4.检查当前的环境是否满足要安装软件的依赖关系
cd php-7.1.31
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --enable-ftp --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --without-pear --disable-phar --enable-sockets --with-freetype-dir=/usr --with-zlib --with-libxml-dir=/usr --with-xmlrpc --enable-zip --enable-fpm --enable-xml --enable-sockets --with-gd --with-zlib --with-iconv --enable-zip --with-freetype-dir=/usr/lib/ --enable-soap --enable-pcntl --enable-cli --with-curl
5.编译安装
make make install
6.在之前编译的源码包中,找到 php.ini-production,复制到/usr/local/php下,并改名为php.ini:
cp php.ini-production /usr/local/php/php.ini
[可选项] 设置让PHP错误信息打印在页面上
vi /usr/local/php/php.ini
将Off改成On
8.复制启动脚本
$ cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
$ chmod +x /etc/init.d/php-fpm
修改php-fpm配置文件:
$ cd /usr/local/php/etc
$ cp php-fpm.conf.default php-fpm.conf
$ vi php-fpm.conf
去掉 pid = run/php-fpm.pid 前面的分号
$ cd php-fpm.d
$ cp www.conf.default www.conf
$ vi www.conf
修改user和group的用户为当前用户(也可以不改,默认会添加nobody这个用户和用户组)
9.启动PHP
$ /etc/init.d/php-fpm start #php-fpm启动命令
$ /etc/init.d/php-fpm stop #php-fpm停止命令
$ /etc/init.d/php-fpm restart #php-fpm重启命令
$ ps -ef | grep php 或者 ps -A | grep -i php #查看是否已经成功启动PHP
10.开机自启动
vi /etc/rc.local
将 /etc/init.d/php-fpm start 添加进去
chmod +x /etc/rc.d/rc.local