Nginx+php 简单安装配置
生产环境
Linux 2.6.18
nginx-1.0.4 http://www.nginx.org/
php-5.3.6 http://www.php.net/
一,安装Nginx
wget http://nginx.org/download/nginx-1.0.4.tar.gz
tar -zxvf nginx-1.0.4.tar.gz
cd nginx-1.0.4
./configure --prefix=/data/apps/nginx-1.0.4
make && make install
二,安装php-5.3.6
wget http://www.php.net/get/php-5.3.6.tar.gz/from/a/mirror
tar -zxvf php-5.3.6.tar.gz
cd php-5.3.6
./configure --prefix=/data/apps/php5.3.6 --with-config-file-path=/data/apps/php5.3.6/etc --with-mysql=/data/apps/mysql5.1.19 --with-mysqli=/data/apps/mysql5.1.19/bin/mysql_config --with-mcrypt --enable-mbstring --with-mhash --enable-fpm
make && make install
php配置文件
cp php.ini-production /data/apps/php5.3.6/etc/php.ini
cd /data/apps/php5.3.6/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
去掉下列变量前面的注释,以避免启动php-fpm时报错
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
三,整合Nginx和php
编辑Nginx配置文件,其中`/data/nginxwebs`为站点根目录
vim /data/apps/nginx-1.0.4/conf/nginx.conf
location / {
root /data/nginxwebs;
index index.html index.htm index.php;
expires 30m;
}
location ~ /.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/nginxwebs$fastcgi_script_name;
include fastcgi_params;
}
四,启动php-fpm & Nginx
/data/apps/php5.3.6/sbin/php-fpm &
/data/apps/nginx-1.0.4/sbin/nginx &
五,小结
php5.3.3以上的版本集成了php-fpm,所以安装步骤比较简单,看来Nginx真的有传说中的魅力,现在连php都向其靠拢了。
Nginx通过php-fpm监听的默认9000端口来解析php请求。
接下来我将体验Nginx的高并发数,进而应用到实际项目当中。
libmcrypt下载
http://download.csdn.net/detail/jom_ch/4179398
主要参考文档:
http://blog.csdn.net/omohe/archive/2009/07/10/4336731.aspx