前置条件:Nginx已安装好。Nginx安装很简单,只要安装好一些必要地依赖库就可以了
开始:
1. 下载php-5.6.2 wget http://cn2.php.net/distributions/php-5.6.2.tar.gz,然后解压并进入解压后的目录(因为php5.3.0以后版本默认集成了fpm包,所以直接下载即可,不需要另外下载fpm压缩包);
2. 安装php必要的一些准备库
3.
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir=/usr/local/libxml --with-gd --with-jpeg-dir=/usr/local/jpeg --with-png-dir=usr/local/png --with-freetype-di=/usr/local/fretype --with-zlib-dir=/usr/local/zlib --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --with-openssl
4.
make && make install
5.
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
8. 显示成功后,进入下一步,启动fpm:
9. 提示找不到用户php-fpm的uid,此时应修改fpm的配置文件/etc/local/php/etc/php-fpm.conf,找到user和group这一行,修改为当前用户名,再次启动即可,若要开机自动启动,执行: chkconfig php-fpm on。可以使用命令查看是否已启动: netstat -ant | grep 9000
10. 修改nginx的配置文件:
[root@cent_Node1 conf]# vim nginx.conf
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /Nginx_1711/nginx/client_body_temp;
proxy_temp_path /Nginx_1711/nginx/proxy_temp;
fastcgi_temp_path /Nginx_1711/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml;
server
{
listen 3292;
server_name localhost;
index index.html index.htm index.php;
root /Nginx_1711/nginx/html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /Nginx_1711/nginx/html$fastcgi_script_name;
}
}
}
11. 编写测试php的文件:<?php
phpinfo();
?>
12 显示如下,成功配置好nginx和php: