轻量型thttpd+php5

thttpd是一个非常小巧的轻量级web server,它非常非常简单,仅仅提供了HTTP/1.1和简单的CGI支持,thttpd 也类似于lighttpd,对于并发请求不使用fork()来派生子进程处理,而是采用多路复用(Multiplex)技术来实现。因此效能很好。thttpd还有一个较为引人注目的特点:基于URL的文件流量限制,这对于下载的流量控制而言是非常方便的。象Apache就必须使用插件实现,效率较thttpd低。
php有 thttpd 编译选项,可以作为thttpd模块,这样就比nginx lighttpd 的 php-fpm 更节省资源,相应速度要快!但是目前 thttpd 对PHP的支持限于版本的要求,今天搜索搜索到有一达人出了php5.2.11版本的补丁。

下载php-5.2.11-thttpd-2.25b
thttpd $> wget http://download2.3tera.net/oss/files/osm/thttpd-2.25b/php-5.2.11-thttpd-2.25b.tar.bz2

下载 thttpd-2.25b
thttpd $> wget http://www.acme.com/software/thttpd/thttpd-2.25b.tar.gz

1. 创建用户
thttpd $> groupadd -g 33 www
thttpd $> useradd -g 33 www

2. 编译php-5.2.11 作为 thttpd模块
thttpd $> tar jxvf php-5.2.11-thttpd-2.25b.tar.bz2
thttpd $> cd php-5.2.11
thttpd $> ./configure –prefix=/usr/local/php5 –with-thttpd=/root/thttpd-2.25b #这里我就默认安装的,你需要什么模块自行添加
thttpd $> make
thttpd $> make install

3.安装 thttpd-2.25b
thttpd $> tar zxvf thttpd-2.25b.tar.gz
thttpd $> cd thttpd-2.25b
thttpd $> ./configure –prefix=/usr/local/thttpd
thttpd $> sed -i ‘s#getline#get_line#g’ extras/htpasswd.c #在这里必须要修改一下htpasswd.c源码,不然会出现
htpasswd.c:52: error: conflicting types for ‘getline’
/usr/include/stdio.h:655: error: previous declaration of ‘getline’ was here
htpasswd.c:52: error: conflicting types for ‘getline’
/usr/include/stdio.h:655: error: previous declaration of ‘getline’ was here
make[1]: *** [htpasswd.o] Error 1
make[1]: Leaving directory `/root/thttpd-2.25b/extras’
make: *** [subdirs] Error 2
原因是getline 已加入 POSIX 2008,可以把extras/htpasswd.c 里面的getline重命名为get_line或别的。
解决错误参考 :http://blog.lytsing.org/archives/387.html
thttpd $> mkdir -p /usr/local/thttpd/man/man1 # 安装脚本没有这步,不然会报错!
thttpd $> make
thttpd $> make install

3.添加配置
thttpd $> cd /usr/local/thttpd
thttpd $> mkdir {etc,logs}
thttpd $> cd etc
thttpd $> vim thttpd.conf
port=80
user=www
chroot
host=0.0.0.0
logfile=/usr/local/thttpd/logs/thttpd.log
pidfile=/usr/local/thttpd/logs/thttpd.pid
throttles=/usr/local/thttpd/etc/throttle.conf
urlpat=*.txt|*.mp3
charset=utf-8
dir=/var/www
cgipat=/usr/local/thttpd/www/cgi-bin/*
thttpd $> vim throttle.conf
*.jpg|*.gif 50000 # 对所有 jpg gif 限速 5万字节每秒
*.mpg 20000 # 对访问所有的 mpg 文件限速 2万字节每秒
dir/* 20000 # 对访问 dir/ 目录下所有文件限速 一秒钟 2万个字节

4. 创建启动文件
thttpd $> vim /etc/init.d/thttpd
#!/bin/bash
COMMAND=/usr/local/thttpd/sbin/thttpd
CONFIG=/usr/local/thttpd/etc/thttpd.conf
PID=`cat /usr/local/thttpd/logs/thttpd.pid`
function_start_thttpd()
{
printf “Starting THTTPD….\n”
$COMMAND -C $CONFIG 2>&1 >/dev/null&
}
function_stop_thttpd()
{
printf “Stoping THTTPD….\n”
kill $PID
}

if [ "$1" = "start" ]; then
function_start_thttpd
elif [ "$1" = "stop" ];then
function_stop_thttpd
else
printf “Usage: thttpd {start|stop}”"
fi

5.访问测试
启动服务
thttpd $> /etc/init.d/thttpd start

在另一台电脑打开浏览器输入 IP

轻量型thttpd+php5

thttpd

 


本文转自Deidara 51CTO博客,原文链接:http://blog.51cto.com/deidara/410900,如需转载请自行联系原作者