搭建一個輕量級伺服器環境 LIGHTTPD + MYSQL + PHP(FAST-CGI)

來源:互聯網
上載者:User

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://www.pc51.net/server/web/apache/2007-02-25/7081.html 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.