让Nginx支持PHP

By | 2018-11-27

环境: ubuntu 17.04

1)先安装以下套件:

apt-get install gcc libxml2-dev

apt install linuxbrew-wrapper

2)下载和编译PHP源码

wget http://hk2.php.net/distributions/php-7.2.3.tar.gz

tar zxvf php-7.2.3.tar.gz

cd php-7.2.3/

./configure –enable-fpm –prefix=/usr/local/php –with-zlib –with-freetype –enable-magic-quotes –enable-fastcgi –with-mysql=/usr/local/server/mysql/ –enable-track-vars –enable-ftp –with-config-file-path=/usr/local/php/etc –with-zip –enable-force-cgi-redirect

make && make install

3)配置php-fpm

cd /usr/local/php/etc

cp php-fpm.conf.default php-fpm.conf

cd /usr/local/php/etc/php-fpm.d

cp php-fpm.conf.default php-fpm.conf

4)运行php-fpm

/usr/local/sbin/php-fpm

如果报错:

ERROR: failed to open configuration file ‘/usr/local/etc/php-fpm.conf’: No such file or directory (2)
ERROR: failed to load configuration file ‘/usr/local/etc/php-fpm.conf’
ERROR: FPM initialization failed

修改/usr/local/sbin/php-fpm/www.conf

修改user和group为 www-data

再运行 php-fpm ,应该不会报错了!

5)查看php-fpm是否在运行
     ps aux | grep ‘php-fpm’

發佈回覆