Linux 上完全手动编译安装 Lighttpd

来源:互联网 发布:战网需要启动windows 编辑:程序博客网 时间:2024/05/18 02:59

Linux 上完全手动编译安装 Lighttpd

Linux 上完全手动编译安装 Lighttpd

Linux 上完全手动编译安装 Lighttpd + PHP4(FastCGI) + eAccelerator

需要软件
Lighttpd http://www.lighttpd.net/download/
PHP4 http://www.php.net/downloads.php
EAccelerator http://sourceforge.net/project/showfiles.php?group_id=122249

我目前的安装测试环境如下
Fedora core 3
MySQL 4.0.15a
CPU 赛阳 1.2G , RAM 384MB

由于是手动编译安装
因此请下载 tar.gz 格式的 source package
下载完之后 请放到 /usr/local/src

 

=================================================================================
第一步 : 先安装 Lighttpd
安装前的准备动作
首先要建立一个使用者来执行 lighttpd
可以下指令 useradd lighttpd
记得要把 /etc/passwd 的 lighttpd 这个 user 的shell从 /bin/bash 改成 /bin/nologin

开始安装 lighttpd
首先下指令 tar -xzf lighttpd-1.3.12.tar.gz , 把档案解开之后
下指令 cd lighttpd-1.3.12
然后要决定好 lighttpd 的安装位置
./configure --prefix=/usr/local/lighttpd
接着下 make , 如果 make 没问题 , 那就下达 make install 开始安装
安装成功之后 , 会发现LightHttpd 已经安装在 /usr/local/lighttpd

接着编写设定档 , 由于 lighttpd 不会帮你自动设定设定档 , 所以要自己写
或者把 /usr/local/src/lighttpd-1.3.12/doc 内的 lighttpd.conf 看看自己修改
这里提供一个设定范例 , 请各位下载本页的附件 , 有些许我加上的中文(big5)说明
然后请看每个批注 , 改成您需要的
PS : 附件中的设定文件范例有 Virtual Hosts , PHP , 网页压缩与 user_dir 的设定,对一般人来说应该足够

若要使用我提供的设定档
请在 /usr/local/lighttpd 下建立 conf 活页夹与 logs 活页夹
然后把 lighttpd.conf 放到 conf 活页夹下
接着再把附件中的 spawn-php.sh 放到 /usr/local/lighttpd/bin 活页夹下
接着请下指令 chown lighttpd.lighttpd /usr/local/lighttpd -Rf
PS: 附件中的 spawn-php.sh 是把 PHP with FastCGI 的环境变量初始化 , 内容各位也可以改

到这步骤应该是都可以了 , 但是请先别急
由于 PHP 还没安装 , 因此现在若启动 lighttpd 要测试会发生错误
所以接下来要安装 PHP with FastCGI

=================================================================================
第二步 : 安装 PHP with FAST CGI
把工作目录切换到 /usr/local/src
然后下指令解开 PHP
tar -xzf php-4.3.10.tar.gz
接着进入 php-4.3.10 (cd php-4.3.10)
开始下指令
./configure --prefix=/usr/local/php-fcgi --enable-fastcgi --with-mysql=/usr/local/mysql --enable-zend-multibyte --with-config-file-path=/usr/local/php-fcgi/conf --enable-discard-path --enable-force-cgi-redirect

这部分若要加上其它 PHP 功能请自行加上参数
唯一与以前不同点是 , 编译成 fastcgi 模块 , 比需使用 --enable-fastcgi
以前与 apache2 一起编译是使用 --with-apxs2 , 此时不能再下这道指令

若没有问题 , 就执行 make 与 make install
这时候 PHP 会安装在 /usr/local/php-fcgi 这个活页夹了
然后在 /usr/local/php-fcgi 建立一个 conf 的活页夹
把 /usr/local/src/php-4.3.10 下的 php.ini-dist 复制到 /usr/local/php-fcgi/conf/php.ini
指令是 cp /usr/local/src/php-4.3.10/php.ini-dist /usr/local/php-fcgi/conf/php.ini

=================================================================================
第三步 : 安装 EAccelerator
把工作目录切换到 /usr/local/src
然后下指令解开 EAccelerator
tar -xzf eaccelerator-0.9.2a.tar.gz
接着进入 eaccelerator-0.9.2a 这个活页夹(cd eaccelerator-0.9.2a)
开始下指令
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-XXXXXX 这个目录
上面目录后面的XXXXXX 要自己看喔(非常重要)

接着要编辑 /usr/local/php-fcgi/conf/php.ini
找到一行 cgi.fix_pathinfo
要写成 cgi.fix_pathinfo = 1
若没有这行 , 请自行加入就可

然后加入
extension="eaccelerator.so"
eaccelerator.shm_size="8"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
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"
检查一下 extension_dir 这个设定是否如下
extension_dir = "/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-XXXXXX/"
最后存档

=================================================================================
最后步骤 : 测试 lighttpd
lighttpd 我们是安装在 /usr/local/lighttpd
因此执行 /usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/conf/lighttpd.conf
可以下 ps -aux 看看有没有许多 php 的行程
若有,那代表你成功了
你一定会烦..怎么那么多 php 程序啊 ?? 其实不要紧张
那些都是多执行绪 , 占用内存很小

如何关闭 lighttpd , 可以下指令 killall lighttpd , 这样就可以关闭
如何一开机启动 lighttpd ?
在 /etc/rc.d/rc.local 新增一行
/usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/conf/lighttpd.conf
这样每次开机就会去启动了

如何测试效能 ???
若您之前有安装 apache with php
请先把 apache 用别的 port 来跑 , 例如 81
然后可以利用 apache 提供的 ab 来测试
例如 ab -c 10 -n 100 http://localhost/test.php 来测试 port 80
然后可以下 ab -c 10 -n 100 http://localhost:81/test.php 来测试 port 81
你会发现 lighttpd 跑的速度比 apache 快 50%~200% 以上喔 !!!!

==========================================================

讲解一下 , 为何用 lighttpd
1. 省内存 , 速度快
2. 使用 FastCGI 来与 PHP 做沟通 , 可以达到 chroot 的功能 , 不过范例中我没写上去 , 意思是每个用户有独立的读写权限 , 无法侵犯他人
3. lighttpd 的设定档虽然"目前"要自己写 , 可是其语法很容易理解

以下是我的测试效能
Lighttpd 的部分测试 phpMyAdmin
./ab -c 10 -n 100 http://192.168.0.254/~pigo/phpMyAdmin/index.php
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.254 (be patient).....done

Server Software: lighttpd/1.3.12
Server Hostname: 192.168.0.254
Server Port: 80

Document Path: /~pigo/phpMyAdmin/index.php
Document Length: 2463 bytes

Concurrency Level: 10
Time taken for tests: 2.250865 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Non-2xx responses: 100
Total transferred: 267100 bytes
HTML transferred: 246300 bytes
Requests per second: 44.43 [#/sec] (mean)
Time per request: 225.086 [ms] (mean)
Time per request: 22.509 [ms] (mean, across all concurrent requests)
Transfer rate: 115.51 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 2 10.6 0 55
Processing: 19 86 106.9 21 706
Waiting: 19 85 106.5 20 704
Total: 19 89 112.5 21 751

Apache 2 的部分测试 phpMyAdmin
./ab -c 10 -n 100 http://192.168.0.254:81/~pigo/phpMyAdmin/index.php
This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.0.254 (be patient).....done

Server Software: Apache/2.0.52
Server Hostname: 192.168.0.254
Server Port: 81

Document Path: /~pigo/phpMyAdmin/index.php
Document Length: 2463 bytes

Concurrency Level: 10
Time taken for tests: 13.81193 seconds
Complete requests: 100
Failed requests: 0
Write errors: 0
Non-2xx responses: 100
Total transferred: 278100 bytes
HTML transferred: 246300 bytes
Requests per second: 7.64 [#/sec] (mean)
Time per request: 1308.119 [ms] (mean)
Time per request: 130.812 [ms] (mean, across all concurrent requests)
Transfer rate: 20.72 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 39 155.1 0 918
Processing: 111 1141 1005.0 912 5239
Waiting: 10 1124 1008.6 911 5238
Total: 111 1181 1001.7 932 5239

原文地址:http://blog.sina.com.tw/archive.php?blog_id=3759&md=entry&id=9778
简体了一下,大陆人看着方便些。

原创粉丝点击