jaffas1101 发表于 2005-11-30 09:24:23

[转帖]搭建一个轻量级服务器环境-LIGHTTPD + MYSQL + PHP(FAST-CGI)

OS: REDHAT/CENTOS<br>
<br>
Lighttp是一个新兴的安全,高效,兼容性都非常好的WEB服务器软件。相对APACHE来说lighttpd的显著特点是:非常低的内存占用,非常快的相应速度。今天我在LINUX上配置了一下感觉的确不错,在这里和大家分享一下。安装lighttpd前需要预装下列软件包:<br>
<br>
pcre<br>
zlib<br>
pcre-devel<br>
zlib-devel<br>
<br>
1.安装配置lighttpd<br>
<br>
1.1 首先创建运行lighttpd的用户和组<br>
<br>
# groupadd lighttpd<br>
# useradd -g lighttpd -s /sbin/nologin -d /dev/null lighttpd<br>
<br>
1.2 开始安装lighttpd<br>
<br>
# wget <a target=_blank href=http://www.lighttpd.net/download/lighttpd-1.4.8.tar.gz>http://www.lighttpd.net/download/lighttpd-1.4.8.tar.gz</a><br>
# tar -zxvf lighttpd-1.4.8.tar.gz<br>
# cd lighttpd-1.4.8<br>
# ./configure --prefix=/usr/local/lighttpd<br>
<br>
# make<br>
# make install<br>
<br>
# mkdir /usr/local/lighttpd/conf<br>
# mkdir /usr/local/lighttpd/log<br>
<br>
# mv ./doc/lighttpd.conf /usr/local/lighttpd/conf/<br>
# cp ./doc/rc.lighttpd.redhat /etc/init.d/lighttpd<br>
<br>
1.3 配置lighttpd<br>
<br>
# vi /usr/local/lighttpd/conf/lighttpd.conf<br>
================+===============+================<br>
server.modules = (<br>"mod_rewrite",<br>"mod_redirect",<br>"mod_access",<br>"mod_fastcgi",<br>"mod_compress",<br>"mod_accesslog" )<br>
<br>
server.document-root = "/usr/local/lighttpd/html"<br>
server.errorlog = "/usr/local/lighttpd/log/lighttpd.error.log"<br>
accesslog.filename = "/usr/local/lighttpd/log/access.log"<br>
server.pid-file = "/var/run/lighttpd.pid"<br>
<br>
server.username = "lighttpd"<br>
server.groupname = "lighttpd"<br>
<br>
compress.cache-dir = "/tmp"<br>
compress.filetype = ("text/plain", "text/html")<br>
<br>
fastcgi.server = ( ".php" =><br>( "localhost" =><br>(<br>"socket" => "/tmp/php-fastcgi.socket",<br>"bin-path" => "/usr/local/php-fcgi/bin/php"<br>)<br>)<br>)<br>
================+===============+================<br>
<br>
# cp ./doc/spawn-php.sh /usr/local/lighttpd/bin/<br>
# chown -R lighttpd:lighttpd /usr/local/lighttpd<br>
<br>
2. 安装配置PHP(FAST-CGI)<br>
<br>
2.1 下载安装PHP<br>
<br>
# cd ..<br>
# wget <a target=_blank href=http://mirrors.easynews.com/php/php-4.3.10.tar.gz>http://mirrors.easynews.com/php/php-4.3.10.tar.gz</a><br>
# tar -zxvf php-4.3.10.tar.gz<br>
# cd php-4.3.10<br>
# ./configure \<br>
--prefix=/usr/local/php-fcgi \<br>
--enable-fastcgi --with-mysql \<br>
--enable-zend-multibyte \<br>
--with-config-file-path=/etc \<br>
--enable-discard-path \<br>
--enable-force-cgi-redirect<br>
<br>
# make<br>
# make install<br>
<br>
# cp php.ini-dist /etc/php.ini<br>
<br>
3. 安装配置EAccelerator(PHP加速器)<br>
<br>
3.1 下载安装EAccelerator<br>
<br>
# wget <a target=_blank href=http://kent.dl.sourceforge.net/sourceforge/eaccelerator/>http://kent.dl.sourceforge.net/sourceforge/eaccelerator/</a> \<br>
eaccelerator-0.9.4-rc1.tar.bz2<br>
# bunzip2 -d eaccelerator-0.9.4-rc1.tar.bz2<br>
# tar -xvf eaccelerator-0.9.4-rc1.tar<br>
# cd eaccelerator-0.9.4-rc1<br>
<br>
# export PHP_PREFIX="/usr/local/php-fcgi"<br>
# $PHP_PREFIX/bin/phpize<br>
# ./configure \<br>
--enable-eaccelerator=shared \<br>
--with-php-config=$PHP_PREFIX/bin/php-config<br>
# make<br>
# make install<br>
# cat eaccelerator.ini >> /etc/php.ini<br>
<br>
3.2 配置PHP变量<br>
<br>
# vi /etc/php.ini<br>
================+===============+================<br>
cgi.fix_pathinfo = 1<br>
extension_dir = "/usr/local/php-fcgi/lib/php/extensions/\<br>
no-debug-non-zts-20020429/"<br>
zlib.output_compression = On<br>
cgi.fix_pathinfo=1<br>
eaccelerator.cache_dir="/tmp"<br>
<br>
////下面的是关于eaccelerator的配置////<br>
<br>
zend_extension="/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-20020429/eaccelerator.so"<br>
eaccelerator.shm_size = "0"<br>
eaccelerator.cache_dir = "/tmp"<br>
eaccelerator.enable = "1"<br>
eaccelerator.optimizer = "1"<br>
eaccelerator.debug = 0<br>
eaccelerator.log_file = "/var/log/eaccelerator_log"<br>
eaccelerator.name_space = ""<br>
eaccelerator.check_mtime = "1"<br>
eaccelerator.filter = ""<br>
eaccelerator.shm_max = "0"<br>
eaccelerator.shm_ttl = "0"<br>
eaccelerator.shm_prune_period = "0"<br>
eaccelerator.shm_only = "0"<br>
eaccelerator.compress = "1"<br>
eaccelerator.compress_level = "9"<br>
eaccelerator.keys = "shm_and_disk"<br>
eaccelerator.sessions = "shm_and_disk"<br>
eaccelerator.content = "shm_and_disk"<br>
eaccelerator.admin.name="yourusername" <br>
eaccelerator.admin.password="yourpassword"<br>
================+===============+================<br>
<br>
3.3 初始化PHP with FastCGI<br>
<br>
# vi /usr/local/lighttpd/bin/spawn-php.sh<br>
================+===============+================<br>
SPAWNFCGI="/usr/local/lighttpd/bin/spawn-fcgi"<br>
FCGIPROGRAM="/usr/local/php-fcgi/bin/php"<br>
USERID=lighttpd<br>
GROUPID=lighttpd<br>
================+===============+================<br>
<br>
# sh /usr/local/lighttpd/bin/spawn-php.sh<br>
<br>
4. 测试<br>
<br>
把/etc/init.d/lighttpd文件中不符的路径更改一下<br>
<br>
# chmod 755 /etc/init.d/lighttpd<br>
# chown root:root /etc/init.d/lighttpd<br>
# chkconfig --add lighttpd<br>
# chkconfig lighttpd on<br>
# service lighttpd start<br>
<br>
# ps afx | grep php<br>
<br>
12222 pts/2 S 0:00 \_ grep php<br>
12193 ? S 0:00 /usr/local/php-fcgi/bin/php<br>
12194 ? S 0:00 \_ /usr/local/php-fcgi/bin/php<br>
12195 ? S 0:00 \_ /usr/local/php-fcgi/bin/php<br>
12196 ? S 0:00 \_ /usr/local/php-fcgi/bin/php<br>
12197 ? S 0:00 \_ /usr/local/php-fcgi/bin/php<br>
12198 ? S 0:00 \_ /usr/local/php-fcgi/bin/php<br>
12199 ? S 0:00 \_ /usr/local/php-fcgi/bin/php<br>
12200 ? S 0:00 \_ /usr/local/php-fcgi/bin/php<br>
12201 ? S 0:00 \_ /usr/local/php-fcgi/bin/php<br>
12202 ? S 0:00 \_ /usr/local/php-fcgi/bin/php<br>
12203 ? S 0:00 \_ /usr/local/php-fcgi/bin/php<br>
<br>
最后在server.document-root目录中放一个test.php,用浏览器看看结果:<br>
<br>
<br>
<a target=_blank href=http://llzqq.3322.org/test.php>http://llzqq.3322.org/test.php</a><br>
页: [1]
查看完整版本: [转帖]搭建一个轻量级服务器环境-LIGHTTPD + MYSQL + PHP(FAST-CGI)