Linux Lighttpd安裝環(huán)境變量初始化
特別值得一提的是Linux Lighttpd有很多值得學(xué)習(xí)的地方,這里我們主要介紹Linux Lighttpd,包括介紹Linux Lighttpd等方面。Linux 上完全手動編譯安裝 Linux Lighttpd 需要軟件Lighttpd http://www.lighttpd.net/download/PHP4 http://www.php.net/downloads.phpEAccelerator http://sourceforge.net/project/showfiles.php?group_id=122249
我目前的安裝測試環(huán)境如下Fedora core 3MySQL 4.0.15aCPU 賽陽 1.2G , RAM 384MB由于是手動編譯安裝因此請下載 tar.gz 格式的 source package下載完之后 請放到 /usr/local/src
***步 : 先安裝Linux Lighttpd安裝前的準(zhǔn)備動作首先要建立一個使用者來執(zhí)行Linux Lighttpd可以下指令 useradd lighttpd記得要把 /etc/passwd 的 lighttpd 這個 user 的shell從 /bin/bash 改成 /bin/nologin
開始安裝Linux Lighttpd首先下指令 tar -xzf lighttpd-1.3.12.tar.gz , 把檔案解開之后下指令 cd lighttpd-1.3.12然后要決定好Linux Lighttpd的安裝位置./configure --prefix=/usr/local/lighttpd接著下 make , 如果 make 沒問題 , 那就下達(dá) make install 開始安裝安裝成功之后 , 會發(fā)現(xiàn)LightHttpd 已經(jīng)安裝在 /usr/local/lighttpd
接著編寫設(shè)定檔 , 由于Linux Lighttpd不會幫你自動設(shè)定設(shè)定檔 , 所以要自己寫或者把 /usr/local/src/lighttpd-1.3.12/doc 內(nèi)的 lighttpd.conf 看看自己修改這里提供一個設(shè)定范例 , 請各位下載本頁的附件 , 有些許我加上的中文(big5)說明然后請看每個批注 , 改成您需要的PS : 附件中的設(shè)定文件范例有 Virtual Hosts , PHP , 網(wǎng)頁壓縮與 user_dir 的設(shè)定,對一般人來說應(yīng)該足夠。
若要使用我提供的設(shè)定檔請在 /usr/local/lighttpd 下建立 conf 活頁夾與 logs 活頁夾然后把 lighttpd.conf 放到 conf 活頁夾下接著再把附件中的 spawn-php.sh 放到 /usr/local/lighttpd/bin 活頁夾下接著請下指令 chown lighttpd.lighttpd /usr/local/lighttpd -RfPS:
附件中的 spawn-php.sh 是把 PHP with FastCGI 的環(huán)境變量初始化 , 內(nèi)容各位也可以改到這步驟應(yīng)該是都可以了 , 但是請先別急由于 PHP 還沒安裝 , 因此現(xiàn)在若啟動 Linux Lighttpd 要測試會發(fā)生錯誤所以接下來要安裝 PHP with FastCGI
第二步 : 安裝 PHP with FAST CGI把工作目錄切換到 /usr/local/src然后下指令解開 PHPtar -xzf php-4.3.10.tar.gz接著進(jìn)入 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 功能請自行加上參數(shù)唯一與以前不同點是 , 編譯成 fastcgi 模塊 , 比需使用 --enable-fastcgi以前與 apache2 一起編譯是使用 --with-apxs2 , 此時不能再下這道指令
若沒有問題 , 就執(zhí)行 make 與 make install這時候 PHP 會安裝在 /usr/local/php-fcgi 這個活頁夾了然后在 /usr/local/php-fcgi 建立一個 conf 的活頁夾把 /usr/local/src/php-4.3.10 下的 php.ini-dist 復(fù)制到 /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然后下指令解開 EAcceleratortar -xzf eaccelerator-0.9.2a.tar.gz接著進(jìn)入 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-configmakemake installEAccelerator 會安裝在 /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 這個設(shè)定是否如下extension_dir = "/usr/local/php-fcgi/lib/php/extensions/no-debug-non-zts-XXXXXX/"***存檔
***步驟 : 測試 Linux Lighttpd lighttpd 我們是安裝在 /usr/local/lighttpd因此執(zhí)行 /usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/conf/lighttpd.conf
可以下 ps -aux 看看有沒有許多 php 的行程若有,那代表你成功了你一定會煩..怎么那么多 php 程序啊 ?? 其實不要緊張那些都是多執(zhí)行緒 , 占用內(nèi)存很小
如何關(guān)閉 Linux Lighttpd , 可以下指令 killall lighttpd , 這樣就可以關(guān)閉如何一開機啟動Linux 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 來測試?yán)?ab -c 10 -n 100 http://localhost/test.php 來測試 port 80然后可以下 ab -c 10 -n 100 http://localhost:81/test.php 來測試 port 81你會發(fā)現(xiàn) lighttpd 跑的速度比 apache 快 50%~200% 以上喔 !!!!
講解一下 , 為何用Linux Lighttpd1. 省內(nèi)存 , 速度快
2. 使用 FastCGI 來與 PHP 做溝通 , 可以達(dá)到 chroot 的功能 , 不過范例中我沒寫上去 , 意思是每個用戶有獨立的讀寫權(quán)限 , 無法侵犯他人
3. Linux Lighttpd的設(shè)定檔雖然"目前"要自己寫 , 可是其語法很容易理解
以下是我的測試效能
Linux 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
【編輯推薦】