Linux下配置Nginx支持PHP-FPM
配置Nginx支持php-fpm模块需要有Nginx环境,如果有童鞋不知道Nginx如何安装的话可以参考前一篇文章Centos6.9安装Nginx1.10.3
PHP的安装
解决PHP软件的依赖关系
yum install zlib-devel libxml2-devel libjpeg-devel libjpeg-turbo-devel -y yum install freetype-devel libpng-devel gd-devel libcurl-devel libxslt-devel libxslt-devel -y
下载libiconv解决字符集转换问题
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxf libiconv-1.14.tar.gz && cd libiconv-1.14 ./configure --prefix=/usr/local/libiconv make make install
下载与数据加密有关的三个软件
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum -y install libmcrypt-devel mhash mcrypt rpm -qa libmcrypt-devel mhash mcrypt
下载安装php
mkdir /application && cd /application wget http://mirrors.sohu.com/php/php-5.5.32.tar.gz tar xf php-5.5.32.tar.gz
cd php-5.5.32 ./configure \ --prefix=/application/php-5.5.32 \ --with-pdo-mysql=mysqlnd \ --with-iconv-dir=/usr/local/libiconv \ --with-freetype-dir \ --with-jpeg-dir \ --with-png-dir \ --with-zlib \ --with-libxml-dir=/usr \ --enable-xml \ --disable-rpath \ --enable-bcmath \ --enable-shmop \ --enable-sysvsem \ --enable-inline-optimization \ --with-curl \ --enable-mbregex \ --enable-fpm \ --enable-mbstring \ --with-mcrypt \ --with-gd \ --enable-gd-native-ttf \ --with-openssl \ --with-mhash \ --enable-pcntl \ --enable-sockets \ --with-xmlrpc \ --enable-soap \ --enable-short-tags \ --enable-static \ --with-xsl \ --with-fpm-user=www \ --with-fpm-group=www \ --enable-ftp \ --enable-opcache=no
make && make install
修改php解析文件、php-fpm配置文件
cp php.ini-production lib/php.ini cd /application/php-5.5.32/etc/ cp php-fpm.conf.default php-fpm.conf
启动php-fpm
php-5.5.31/sbin/php-fpm lsof -i :9000 ps -ef|grep php-fpm
检测Nginx与php关联性
修改Nginx配置文件
cd /applicationn/nginx-1.10.3/ grep -Ev '#|^$' nginx.conf.default > nginx.conf
vim nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root html/php_test; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~* .*\.(php|php5)?$ { root html/php_test; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } } }
创建主页文件
mkdir /application/nginx-1.10.3/html/php_test vim /application/nginx-1.10.3/html/php_test/php_test.php
检查Nginx配置文件语法检查
/application/nginx-1.10.3/sbin/nginx -t
重启Nginx并访问php文件
/application/ngins-1.10.3/sbin/nginx -s reload
访问测试
10.0.0.200/php_test.php