Lighttpd + PHP-FastCGI + MySQL + eAccelerator 环境配置

一、软件准备
============
Lighttpd: http://www.lighttpd.net
PHP: http://www.php.net
MySQL: http://www.mysql.com
eAccelerator: http://sourceforge.net/project/showfiles.php?group_id=122249
将这些软件都放到/usr/local/src

Lighttpd依赖于pcre-devel包,如果没有安装请下载或者从光盘中安装。


二、安装MySQL
=============
# cd /usr/local/src
# rpm -Uvh MySQL-client-4.0.26-0.i386.rpm
# rpm -Uvh MySQL-server-4.0.26-0.i386.rpm
# mysqladmin -u root password "new_password_for_root"
# service mysql start


三、安装Lighttpd
================
# useradd lighttpd
# vi /etc/passwd (将lighttpd用户的登录shell改为/bin/nologin)
# cd /usr/local/src
# tar xzvf lighttpd-lighttpd-1.4.10.tar.gz
# cd lighttpd-lighttpd-1.4.10
# ./configure --prefix=/usr/local/lighttpd --with-bzip2 --disable-ipv6
# make
# make install
# mkdir /usr/local/lighttpd/conf
# mkdir /usr/local/lighttpd/log
# cp ./doc/lighttpd.conf /usr/local/lighttpd/conf/
# cp ./doc/rc.lighttpd.redhat /etc/rc.d/init.d/lighttpd
# chown root:root /etc/rc.d/init.d/lighttpd
# chmod 755 /etc/rc.d/init.d/lighttpd
# chkconfig --add lighttpd
# cp ./doc/spawn-php.sh /usr/local/lighttpd/bin/
# vi /usr/local/lighttpd/bin/spawn-php.sh

以下是spawn-php.sh需要修改的部分:
SPAWNFCGI="/usr/local/lighttpd/bin/spawn-fcgi"
FCGIPROGRAM="/usr/local/php-fcgi/bin/php"
USERID=lighttpd
GROUPID=lighttpd

# chown -R lighttpd:lighttpd /usr/local/lighttpd
# vi /usr/local/lighttpd/conf/lighttpd.conf

以下是lighttpd.conf中需要修改的部分:
server.document-root = "/usr/local/lighttpd/html"
server.errorlog = "/usr/local/lighttpd/log/lighttpd.error.log"
accesslog.filename = "/usr/local/lighttpd/log/access.log"
server.pid-file = "/var/run/lighttpd.pid"

server.username = "lighttpd"
server.groupname = "lighttpd"

compress.cache-dir = "/tmp"
compress.filetype = ("text/plain", "text/html")

fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/tmp/php-fastcgi.socket",
"bin-path" => "/usr/local/php-fcgi/bin/php"
)
)
)


四、安装PHP
===========
# cd /usr/local/src
# tar xzvf php-4.2.2.tar.gz
# cd php-4.4.2
# ./configure --prefix=/usr/local/php-fcgi --enable-fastcgi --with-mysql --enable-zend-multibyte --with-config-file-path=/usr/local/php-fcgi/etc --enable-discard-path --enable-force-cgi-redirect --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --enable-xml --enable-mbstring
# make
# make install
# cp php.ini-dist /etc/php.ini


五、安装eAccelerator
====================
# /usr/local/src
# bunzip2 -d eaccelerator-0.9.4.tar.bz2
# tar -xvf eaccelerator-0.9.4.tar
# cd eaccelerator-0.9.4
# export PHP_PREFIX="/usr/local/php-fcgi"
# $PHP_PREFIX/bin/phpize
# ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config
# make
# make install
(eAccelerator安装在/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-XXXXXXXX)
# cat eaccelerator.ini >> /usr/local/php-fcgi/etc/php.ini
# vi /usr/local/php-fcgi/etc/php.ini
//全局部分
cgi.fix_pathinfo = 1
extension_dir = "/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-XXXXXXXX"
zlib.output_compression = On

//eAccelerator部分
zend_extension = "/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-XXXXXXXX/eaccelerator.so"
eaccelerator.shm_size = "0"
eaccelerator.cache_dir = "/tmp"
eaccelerator.enable = "1"
eaccelerator.optimizer = "1"
eaccelerator.debug = 0
eaccelerator.log_file = "/var/log/eaccelerator_log"
eaccelerator.name_space = ""
eaccelerator.check_mtime = "1"
eaccelerator.filter = ""
eaccelerator.shm_max = "0"
eaccelerator.shm_ttl = "0"
eaccelerator.shm_prune_period = "0"
eaccelerator.shm_only = "0"
eaccelerator.compress = "1"
eaccelerator.compress_level = "9"
eaccelerator.keys = "shm_and_disk"
eaccelerator.sessions = "shm_and_disk"
eaccelerator.content = "shm_and_disk"
eaccelerator.admin.name = "SET_USERNAME"
eaccelerator.admin.password = "SET_PASSWORD"


六、启动PHP-FastCGI
===================
# /usr/local/lighttpd/bin/spawn-php.sh


七、启动Lighttpd
================
# vi /etc/rc.d/init.d/lighttpd (检查脚本将文件中的路径设置为本机环境路径,例如Lighttpd配置文件位置)
# service lighttpd start


八、测试
========
# ps aux | grep php