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 --enable-mbstring --with-mcrypt --with-mhash --enable-fpm
make && make install
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的高并发数,进而应用到实际项目当中。