Linux下配置Nginx支援PHP-FPM
阿新 • • 發佈:2018-12-20
配置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