<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/ DTD/wml_1.1.xml">

<wml>
<head>
<meta http-equiv="cache-control" content="max-age=180,private" />
</head>
<card title="ubuntu中nginx + fcgi + eaccelerator 配置教程">
<p>
作者:<a href="index.php?action=showuser&amp;userid=1&amp;hash=">admin</a><br />时间:2010-12-21 11:06<br />分类:<a href="index.php?action=list&amp;cid=3&amp;hash=">电脑技术</a><br />内容:
ubuntu中nginx + fcgi + eaccelerator 配置教程


 


 


 

1、安装nginx

ubuntu中已经包含了nginx，所以不用编译，不过这样安装的nginx版本很低，是6.xx版本。如果需要使用高版本的用户，建议到http://nginx.org/en/download.html下载来编译安装。

运行：


sudo apt-get install nginx



即可完成安装。

2、安装PHP

运行：


sudo apt-get install php5-cli php5-cgi



3、安装fastcgi和配置

我们需要/usr/bin/spawn-fcgi这个文件，而它是属于lighttpd这个包里面的，所以我们安装lighttpd然后把它设置为开机不启动：


sudo apt-get install lighttpd



然后设置lighttpd为开机不启动：


sudo update-rc.d -f lighttpd remove



修改nginx的配置文件：/etc/nginx/sites-available/default

修改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:


sudo /etc/init.d/nginx restart



启动fastcgi php:


spawn-fcgi -a 127.0.0.1 -p 9000 -C 50 -u www-data -f /usr/bin/php-cgi



设置让php-cgi开机自启动：


cd /etc/init.d

cp nginx php-cgi

sudo nano php-cgi



然后替换内容nginx为php-cgi

并修改相应部分为：


DAEMON=/usr/bin/spawn-fcgi

DAEMON_OPTS=&rdquo;-a 127.0.0.1 -p 9000 -C 50 -u www-data -f /usr/bin/php-cgi&rdquo;

&hellip;

stop)

echo -n &ldquo;Stopping $DESC: &rdquo;

pkill -9 php-cgi

echo &ldquo;$NAME.&rdquo;



然后运行：


sudo update-rc.d php-cgi defaults



设置php-cgi开机启动。

4、安装eAccelerator加速PHP

ubuntu server默认是没有安装编译环境的，需要运行：


sudo apt-get install build-essential



eaccelerator的安装很简单,只是在ubuntu下需要装php5-dev这个包来支持：


sudo apt-get install php5-dev



然后才可以找到/usr/bin/phpize这个命令。

获得eAccelerator源码包：


wget http://bart.eaccelerator.net/source/0.9.5.3/eaccelerator-0.9.5.3.tar.bz2



下载完毕之后，解压：


sudo tar xvf eaccelerator-0.9.5.3.tar.bz2



进入到解压之后目录：


cd eaccelerator-0.9.5.3



安装配置：


sudo /usr/bin/phpize

sudo ./configure --enable-eaccelerator=shared --with-php-config=/usr/bin/php-config

sudo make

sudo make install

mkdir /tmp/eaccelerator

chmod 777 /tmp/eaccelerator



编辑/etc/php5/cgi/php.ini，在最后添加内容：


[eaccelerator]

zend_extension=&rdquo;/usr/lib/php5/20060613+lfs/eaccelerator.so&rdquo;

eaccelerator.shm_size=&rdquo;128&Prime;

eaccelerator.cache_dir=&rdquo;/tmp/eaccelerator&rdquo;

eaccelerator.enable=&rdquo;1&Prime;

eaccelerator.optimizer=&rdquo;1&Prime;

eaccelerator.check_mtime=&rdquo;1&Prime;

eaccelerator.debug=&rdquo;0&Prime;

eaccelerator.filter=&rdquo;&rdquo;

eaccelerator.shm_max=&rdquo;0&Prime;

eaccelerator.shm_ttl=&rdquo;300&Prime;

eaccelerator.shm_prune_period=&rdquo;120&Prime;

eaccelerator.shm_only=&rdquo;0&Prime;

eaccelerator.compress=&rdquo;1&Prime;

eaccelerator.compress_level=&rdquo;9&Prime;



然后重启fast-cgi和nginx

编写查看PHP配置进行观察：


phpinfo.php:



您可以任意转载本文，但转载时请以超链接形式标明文章原始出处和作者信息及版权声明 
</p><p>
<a href="index.php?action=login&amp;hash=">立即登陆发表评论</a><br />
</p>
<p><a href="index.php?action=list&amp;hash=">返回日志列表</a><br /><a href="index.php?action=index&amp;hash=">返回主页</a></p>
</card>
</wml>
