24

在Ubuntu 8.04下配置nginx和fastcgi方式的php

最近我们(瑞豪开源Xen VPS: http://www.RasHost.com)的一个客户要求在他的Ubuntu 8.04 VPS上安装一个高性能的web服务器nginx,下面是我的安装记录。

由于Ubuntu 804已经包含了nginx,所以根本不要编译,安装超简单!

在VPS上修改/etc/apt/sources.list文件内容为:

deb http://ubuntu.cn99.com/ubuntu hardy main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu hardy-security main restricted universe multiverse
deb http://ubuntu.cn99.com/ubuntu hardy-updates main restricted universe multiverse

然后运行:

apt-get update
apt-get install nginx

即可完成安装

启动nginx:

/etc/init.d/nginx start

然后就可以访问了,http://58.30.17.160/ , 一切正常!如果不能访问,先不要继续,看看是什么原因,解决之后再继续。

下面配置php和mysql。

安装php和MySQL:

apt-get install php5-cli php5-cgi mysql-server-5.0 php5-mysql

我们需要/usr/bin/spawn-fcgi这个文件,而它是属于lighttpd这个包里面的,所以我们安装lighttpd然后把它设置为开机不启动:

apt-get install lighttpd #我们只要/usr/bin/spawn-fcgi
rcconf #去掉lighttpd开机自启动

修改nginx的配置文件:/etc/nginx/sites-available/default
修改 server_name 58.30.17.154;
修改index的一行修改为:
index index.php index.html index.htm;

去掉下面部分的注释:

location ~ \.php$ {
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

重新启动nginx:

/etc/init.d/nginx stop
/etc/init.d/nginx start

启动fastcgi php:

spawn-fcgi -a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi

为了让php-cgi开机自启动:

cd /etc/init.d
cp nginx php-cgi

vim php-cgi
替换nginx为php-cgi
并修改相应部分为:

DAEMON=/usr/bin/spawn-fcgi
DAEMON_OPTS="-a 127.0.0.1 -p 9000 -C 10 -u www-data -f /usr/bin/php-cgi"
...
 stop)
        echo -n "Stopping $DESC: "
        pkill -9 php-cgi
        echo "$NAME."

然后运行rcconf设置php-cgi为开机自启动

在/var/www/nginx-default/目录下创建一个文件:

echo '< ?phpinfo();?>'  > /var/www/nginx-default/index.php

然后浏览器访问nginx就可以看到一切正常了

欢迎转载,请注明转载自: http://vpsblog.rashost.com/20080524-ubuntu-nginx/

1 条评论了已经

Trackbacks/Pingbacks.

发表评论

名字(必须)
邮箱(不会被公布)(必须)
网址

字体为 粗体 是必填项目,邮箱地址 永远不会 公布。

允许部分 HTML 代码:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URLs(网站链接)必须完整有效 (比如: http://vpsblog.rashost.com),所有标签都必须完整的关闭。

超出部分系统将会自动分段及换行。

请保证评论内容是与日志或 Blog 内容相关的,灌水、攻击性或不恰当的评论 可能 会被编辑或删除。