准备:

lighttpd-1.4.15.tar.gz
php-4.4.2.tar.gz
mysql-5.0.20a.tar.gz

开始:
1 编译安装lighttpd

1
2
3
4
5
tar zxvf lighttpd-1.4.15.tar.gz
cd lighttpd-1.4.15
ls
./configure —prefix=/usr/local/lighttpd
make && make install

创建网站根目录

1
mkdir /usr/local/lighttpd/htdocs

创建配置文件放置目录

1
mkdir /usr/local/lighttpd/etc

创建日志目录

1
mkdir /usr/local/lighttpd/logs

将配置文件拷贝到/usr/local/lighttpd/etc

1
cp doc/lighttpd.conf /usr/local/lighttpd/etc

启动lighttpd

1
/usr/local/lighttpd/bin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf

2 安装 MYSQL

1
2
3
4
5
6
7
8
tar zxvf mysql-5.0.20a.tar.gz
cd mysql-5.0.20a
./configure —prefix=/usr/local/mysql
make;make install
groupadd mysql
useradd -g mysql mysql
cp support-files/my-medium.cnf /etc/my.cnf
cd /usr/local/mysql/

初始化

1
bin/mysql_install_db —user=mysql

运行

1
bin/mysqld_safe —user=mysql &

设置自动启动(略)

3 安装 php (fast-cgi)

1
2
tar zxvf php-4.4.2.tar.gz
cd php-4.4.2

编译,加--enable-fastcgi--enable-force-cgi-redirect选项

1
2
3
4
5
6
7
8
./configure --prefix=/usr/local/php-fastcgi  --enable-fastcgi --enable-force-cgi-redirect --with-zlib \
--with-gd --with-ttf --with-png --with-expat-dir=/usr --with-gmp --with-xml --with-mysql=/usr/local/mysql \
--with-charset=utf-8 --disable-debug --disable-posix --disable-rpath --enable-safe-mode --enable-magic-quotes \
--disable-dmalloc --enable-bcmath --enable-dio --enable-gd-native-ttf --enable-sysvsem --enable-sysvshm \
--enable-wddx --enable-versioning --enable-pic --enable-inline-optimization --enable-memory-limit --enable-mbstring \
--enable-mbregex --enable-mbstr-enc-trans --with-config-file-path=/usr/local/lib --enable-ftp --disable-debug \
--enable-track-vars=yes --with-jpeg-dir --with-freetype-dir --enable-gd-native-ttf --enable-dl
make;make install

4 配置lighttpd

1
#vim /usr/local/lighttpd/etc/lighttpd.conf

修改一下内容

加载cgi,fastcgi模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
server.modules              = (
“mod_rewrite”,
# “mod_redirect”,
# “mod_alias”,
“mod_access”,
# “mod_cml”,
# “mod_trigger_b4_dl”,
# “mod_auth”,
# “mod_status”,
# “mod_setenv”,
“mod_fastcgi”,
# “mod_proxy”,
# “mod_simple_vhost”,
# “mod_evhost”,
# “mod_userdir”,
“mod_cgi”,
# “mod_compress”,
# “mod_ssi”,
# “mod_usertrack”,

网站根目录

1
2
3
## a static document-root, for virtual-hosting take look at the
## server.virtual-* options
server.document-root = “/usr/local/lighttpd/htdocs”

日志目录

1
2
3
4
5
6
## where to send error-messages to
server.errorlog = “/usr/local/lighttpd/logs/lighttpd.error.log”
…..
…..
#### accesslog module
accesslog.filename = “/usr/local/lighttpd/logs/access.log”

默认首页格式

1
2
3
# files to check for if …/ is requested
index-file.names = ( “index.php”, “index.html”,
“index.htm”, “default.htm” )

FastCgi模块

1
2
3
4
5
6
7
8
9
10
11
12
#### fastcgi module
## read fastcgi.txt for more info
## for PHP don’t forget to set cgi.fix_pathinfo = 1 in the php.ini
fastcgi.server= (“.php” =>
(( “socket” => “/tmp/php.socket”,
“bin-path” => “/usr/local/php-fastcgi/bin/php”,
“min-procs” => 1,
“max-procs” => 32,
“max-load-per-proc” => 4,
“idle-timeout” => 20
))
)

CGI模块

1
2
3
4
5
6
#### CGI module
cgi.assign = (
“.sh” => “/bin/bash”, #shell script
“.pl” => “/usr/bin/perl”, #Perl
“.cgi” => “”
)

5 修改php.ini

设置 cgi.fix_pathinfo = 1

6 配置完毕,重起lighttpd

查其PID

1
ps  auxww |grep lighttpd

kill掉

1
kill -9 PID

启动

1
/usr/local/lighttpd/bin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf

7.简单管理脚本
为了方便管理lighttpd,写几个简单的脚本
checkLighttpd.sh(检查lighttpd进程):

1
2
#!/bin/bash
ps auxww |grep lighttpd|grep -v grep

killLighttpd.sh(杀死lighttpd进程) :

1
2
3
#!/bin/bash
LIGHTTPD_PID=ps auxww |grep lighttpd |grep -v grep | awk '{print $2}'
kill -9 $LIGHTTPD_PID

startLighttpd.sh (启动lighttpd):

1
2
3
#!/bin/bash
/usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf
chmod +x startLighttpd.sh killLighttpd.sh checkLighttpd.sh

8 测试:
用c,shell,perl,php分别写几个小程序作测试(略)