第一步,安装PHP
安装前先差一下依赖关系:
rpm -ivh php- 5.1.6 -27.el5.x86_64.rpm
warning: php- 5.1.6 -27.el5.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
error: Failed dependencies:
httpd-mmn = 20051115 is needed by php- 5.1.6 -27.el5.x86_64
php-cli = 5.1.6 -27.el5 is needed by php-5.1.6-27.el5.x86_64
php-common = 5.1.6 -27.el5 is needed by php-5.1.6-27.el5.x86_64
需要以上包!
1.先安装httpd- 2.2.3 -43.el5.x86_64.rpm
2.安装php-common- 5.1.6 -27.el5.x86_64.rpm
3.安装php-cli- 5.1.6 -27.el5.x86_64.rpm
以上依赖关系包安装完后,安装PHP
php- 5.1.6 -27.el5.x86_64.rpm
第二步,安装pcre
pcre-8.00.tar.gz 解压执行安装命令 ./configure make makeinstall
第三步,安装Nginx
先安装依赖关系
zlib-devel- 1.2.3 -3.x86_64.rpm
openssl- 0.9.8 e-12.el5_4.6.x86_64.rpm
e2fsprogs-devel-1.39-23.el5.x86_64.rpm
keyutils-libs-devel-1.2-1.el5.x86_64.rpm
libsepol-devel- 1.15.2 -3.el5.x86_64.rpm
libselinux-devel- 1.33.4 -5.5.el5.x86_64.rpm
krb5-devel- 1.6.1 -36.el5_4.1.x86_64.rpm
openssl-devel- 0.9.8 e-12.el5_4.6.x86_64.rpm
openssl 097a - 0. 9.7a -9.el5_2.1.x86_64.rpm
xmlsec1- 1.2.9 -8.1.1.x86_64.rpm
xmlsec1-openssl- 1.2.9 -8.1.1.x86_64.rpm
libgpg-error-devel-1.4-2.x86_64.rpm
libgcrypt-devel- 1.4.4 -5.el5.x86_64.rpm
libxml2-devel- 2.6.26 -2.1.2.8.x86_64.rpm
libxslt-devel- 1.1.17 -2.el5_2.2.x86_64.rpm
openssl-devel- 0.9.8 e-12.el5_4.6.x86_64.rpm
xmlsec1-devel- 1.2.9 -8.1.1.x86_64.rpm
xmlsec1-openssl-devel- 1.2.9 -8.1.1.x86_64.rpm
直接去http://nginx.org/ 下载最新版本的,然后就 ./configure, make, make install 普通安装就行了
第四步,安装spawn-fcgi
去 http://redmine.lighttpd.net/news/2 下载 spawn-fcgi-1.6.0.tar.gz
解压 执行 ./configure 和 make
然后在 src 目录下有个 spawn-fcgi ,
用 cp -r spawn-fcgi /usr/local/nginx/sbin/spawn-fcgi 拷贝到 nginx 的执行目录
然后启动 spawn-fcgi 方法: ./spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/bin/php-cgi
在nginx的执行目录下执行
第五步,配置Nginx
1. 在下面添加红色的代码
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.php;
}
2. 找到下面的代码,把注释去了
红色部分是关键,要看 /usr/local/nginx/conf 目录下面的 fastcgi 文件名字是什么
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
第六步,启动 Nginx
直接在 /usr/local/nginx/sbin 目录下 ./nginx 就搞定了
第七部,修改nginx配置文件
在配置文件中找到以下字段:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
将蓝色部分改为 /$document_root$fastcgi_script_name
重启nginx(nginx –s reload)
第八步,测试nginx+php环境
创建index.php文件,内容为:<?php phpinfo();?>
第九步,添加启动项
编辑/etc/rc.local文件,添加如下内容
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/bin/php-cgi
本文出自 “姜浩天的博客” 博客,转载请与作者联系!