免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4131 | 回复: 5
打印 上一主题 下一主题

搭建一个轻量级服务器环境-LIGHTTPD + MYSQL + PHP(FAST-CGI) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-11-29 17:18 |只看该作者 |倒序浏览
LIGHTTPD + MYSQL + PHP(FAST-CGI)

欢迎大家转贴这个文章,但要保留下面的版权信息:

作者:llzqq
联系:llzqq@126.com
来自:www.chinaunix.net

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" )
#$HTTP["url"] =~ "\.pdf$" {
#server.range-requests = "disable"
#}

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.安装配置MYSQL服务器

# yum install mysql-server
# yum install mysql
# service mysqld start

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

3.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

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

4.1 下载安装EAccelerator

# cd ..
# 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

4.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"
================+===============+================

4.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
================+===============+================

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

5. 测试

把/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

[ 本帖最后由 llzqq 于 2005-12-3 07:42 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2005-11-30 21:26 |只看该作者
没人使用LIGHTTPD?

论坛徽章:
0
3 [报告]
发表于 2005-11-30 23:25 |只看该作者
好文,我用过,但是没绑定 PHP,只是用来做静态的玩过

论坛徽章:
0
4 [报告]
发表于 2005-12-01 00:37 |只看该作者

  1. [root@platinum bin]# /baijin/APM/lighttpd/bin/spawn-php.sh
  2. spawn-fcgi.c.207: child exited with: 0, Success
  3. [root@platinum bin]# service lighttpd start
  4. Starting lighttpd:                                         [  OK  ]
  5. [root@platinum bin]# netstat -lnp
  6. Active Internet connections (only servers)
  7. Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
  8. tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      28765/mysqld
  9. tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      939/proftpd: (accep
  10. tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      873/sshd
  11. tcp        0      0 0.0.0.0:23                  0.0.0.0:*                   LISTEN      883/xinetd
  12. udp        0      0 0.0.0.0:69              0.0.0.0:*                           883/xinetd
  13. Active UNIX domain sockets (only servers)
  14. Proto RefCnt Flags       Type       State         I-Node PID/Program name    Path
  15. unix  2      [ ACC ]     STREAM     LISTENING     175037 28765/mysqld        /tmp/mysql.sock
  16. [root@platinum bin]#
复制代码

这是怎么回事?

论坛徽章:
0
5 [报告]
发表于 2005-12-01 06:30 |只看该作者
原帖由 platinum 于 2005-12-1 00:37 发表
[code]
[root@platinum bin]# /baijin/APM/lighttpd/bin/spawn-php.sh
spawn-fcgi.c.207: child exited with: 0, Success
[root@platinum bin]# service lighttpd start
Starting lighttpd:                  ...



用这个命令启动LIGHTTPD服务器看看那里出了问题,多半是LIGHTTPD的配置文件出了问题:


# /usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/conf/lighttpd.conf

论坛徽章:
0
6 [报告]
发表于 2006-07-14 10:31 |只看该作者
版主有lighttp+mysql+ruby+rails+fcgi的吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP