首页 > 代码库 > nginx+php
nginx+php
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/attachment/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
添加 PHP 命令到环境变量
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;
}
nginx+php