nginx本身不能處理PHP,當接收到php請求後,則發給php解釋器處理,並把結果返回給客戶端。
nginx一般是把請求發fastcgi管理進程處理,fascgi管理進程選擇cgi子進程處理結果並返回被nginx
本文介紹如何使用nginx支持PHP
安裝php-fpm
下載源碼包
http://www.php.net/downloads.php
http://at1.php.net/distributions/php-5.6.29.tar.gz
[root@bogon ~]# tar zxvf php-5.6.29.tar.gz
[root@bogon ~]# cd php-5.6.29
安裝前 先安裝phpa安裝所依賴的庫文件
[root@bogon php-5.6.29]# yum -y install gcc automake autoconf libtool make
[root@bogon php-5.6.29]# yum -y install gcc gcc-c++ glibc
[root@bogon php-5.6.29]# yum -y install libmcrypt-devel mhash-devel libxslt-devel
[root@bogon php-5.6.29]# yum -y install bzip2 bzip2-devel curl-devel openssl openssl-deve readline-devel
安裝中報錯configure: error: mcrypt.h not found. Please reinstall libmcrypt.
下載個源碼包安裝。下載地址:
http://www.aminglinux.com/bbs/data/p_w_upload/forum/libmcrypt.tar.bz2
[root@bogon php-5.6.29]# ./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline --without-sqlite3 --without-pdo-sqlite --with-pear
[root@bogon php-5.6.29]# make
[root@bogon php-5.6.29]# nake install
vim /etc/profile
在末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH
要使改動立即生效執行
source /etc/profile
配置php-fpm
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
啓動php-fpm
/usr/local/php/sbin/php-fpm
nginx安裝步驟在此不贅述,直接配置nginx. conf 文件
location / {
root /data/123;
index index.html index.htm index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/123 $fastcgi_script_name;
include fastcgi_params;
}