发新话题
打印

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

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

OS: REDHAT/CENTOS

Lighttp是一个新兴的安全,高效,兼容性都非常好的WEB服务器软件。相对APACHE来说lighttpd的显著特点是:非常低的内存占用,非常快的相应速度。今天我在LINUX上配置了一下感觉的确不错,在这里和大家分享一下。安装lighttpd前需要预装下列软件包:

pcre
zlib
pcre-devel
zlib-devel

1.安装配置lighttpd

1.1 首先创建运行lighttpd的用户和组

# groupadd lighttpd
# useradd -g lighttpd -s /sbin/nologin -d /dev/null lighttpd

1.2 开始安装lighttpd

# wget http://www.lighttpd.net/download/lighttpd-1.4.8.tar.gz
# tar -zxvf lighttpd-1.4.8.tar.gz
# cd lighttpd-1.4.8
# ./configure --prefix=/usr/local/lighttpd

# make
# make install

# mkdir /usr/local/lighttpd/conf
# mkdir /usr/local/lighttpd/log

# mv ./doc/lighttpd.conf /usr/local/lighttpd/conf/
# cp ./doc/rc.lighttpd.redhat /etc/init.d/lighttpd

1.3 配置lighttpd

# vi /usr/local/lighttpd/conf/lighttpd.conf
================+===============+================
server.modules = (
"mod_rewrite",
"mod_redirect",
"mod_access",
"mod_fastcgi",
"mod_compress",
"mod_accesslog" )

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"
)
)
)
================+===============+================

# cp ./doc/spawn-php.sh /usr/local/lighttpd/bin/
# chown -R lighttpd:lighttpd /usr/local/lighttpd

2. 安装配置PHP(FAST-CGI)

2.1 下载安装PHP

# cd ..
# wget http://mirrors.easynews.com/php/php-4.3.10.tar.gz
# tar -zxvf php-4.3.10.tar.gz
# cd php-4.3.10
# ./configure \
--prefix=/usr/local/php-fcgi \
--enable-fastcgi --with-mysql \
--enable-zend-multibyte \
--with-config-file-path=/etc \
--enable-discard-path \
--enable-force-cgi-redirect

# make
# make install

# cp php.ini-dist /etc/php.ini

3. 安装配置EAccelerator(PHP加速器)

3.1 下载安装EAccelerator

# wget http://kent.dl.sourceforge.net/sourceforge/eaccelerator/ \
eaccelerator-0.9.4-rc1.tar.bz2
# bunzip2 -d eaccelerator-0.9.4-rc1.tar.bz2
# tar -xvf eaccelerator-0.9.4-rc1.tar
# cd eaccelerator-0.9.4-rc1

# 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
# cat eaccelerator.ini >> /etc/php.ini

3.2 配置PHP变量

# vi /etc/php.ini
================+===============+================
cgi.fix_pathinfo = 1
extension_dir = "/usr/local/php-fcgi/lib/php/extensions/\
no-debug-non-zts-20020429/"
zlib.output_compression = On
cgi.fix_pathinfo=1
eaccelerator.cache_dir="/tmp"

////下面的是关于eaccelerator的配置////

zend_extension="/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-20020429/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="yourusername"
eaccelerator.admin.password="yourpassword"
================+===============+================

3.3 初始化PHP with FastCGI

# vi /usr/local/lighttpd/bin/spawn-php.sh
================+===============+================
SPAWNFCGI="/usr/local/lighttpd/bin/spawn-fcgi"
FCGIPROGRAM="/usr/local/php-fcgi/bin/php"
USERID=lighttpd
GROUPID=lighttpd
================+===============+================

# sh /usr/local/lighttpd/bin/spawn-php.sh

4. 测试

把/etc/init.d/lighttpd文件中不符的路径更改一下

# chmod 755 /etc/init.d/lighttpd
# chown root:root /etc/init.d/lighttpd
# chkconfig --add lighttpd
# chkconfig lighttpd on
# service lighttpd start

# ps afx | grep php

12222 pts/2 S 0:00 \_ grep php
12193 ? S 0:00 /usr/local/php-fcgi/bin/php
12194 ? S 0:00 \_ /usr/local/php-fcgi/bin/php
12195 ? S 0:00 \_ /usr/local/php-fcgi/bin/php
12196 ? S 0:00 \_ /usr/local/php-fcgi/bin/php
12197 ? S 0:00 \_ /usr/local/php-fcgi/bin/php
12198 ? S 0:00 \_ /usr/local/php-fcgi/bin/php
12199 ? S 0:00 \_ /usr/local/php-fcgi/bin/php
12200 ? S 0:00 \_ /usr/local/php-fcgi/bin/php
12201 ? S 0:00 \_ /usr/local/php-fcgi/bin/php
12202 ? S 0:00 \_ /usr/local/php-fcgi/bin/php
12203 ? S 0:00 \_ /usr/local/php-fcgi/bin/php

最后在server.document-root目录中放一个test.php,用浏览器看看结果:


http://llzqq.3322.org/test.php

TOP

发新话题
  清除 Cookies - 联系我们 - 邮件技术资讯网 - Archiver - WAP - 繁體中文
当前时区 GMT+8, 现在时间是 2008-10-11 14:36

本论坛为非盈利中立机构,论坛所有言论纯属发表者个人意见,与《 邮件技术资讯网》论坛立场无关。内容所涉及的版权和法律相关事宜请参考各自所有者的条款。
如果认定侵犯了您的权利,请联系我们尽快处理。本论坛原创内容请联系本站后再行转载并务必保留我站信息。此声明修改不再另行通知,本论坛保留最终解释权。
*本论坛QQ群:1#群2233231(已满) 2#群2598254(推荐) 3#群15974064(推荐) 4#群14173252(推荐)*
* 建议使用 1024×768 模式查看本论坛 *
Powered by Discuz! 6.1.0