安装thttpd服务器并配置php详情

最近项目用到轻量级服务器,首选thttpd。不仅网上的安装教程鱼龙混杂,连官网的安装手册都很含糊,安装了几次都没成功。最后终于安装了thttpd,却发现不支持php...... :( ,因为仅仅thttpd2.21版本支持php,最终还是需要thttpd2.21版本。
报一下自己的配置:Ubuntu 14.04.5/thttpd2.21/php5.3.3

下载源码:

wget http://museum.php.net/php5/php-5.3.3.tar.bz2
wget http://www.acme.com/software/thttpd/thttpd-2.21b.tar.gz

安装php 的thttpd补丁

tar jxvf php-5.3.3.tar.bz2
tar zxvf thttpd-2.21b.tar.gz
cd php-5.3.3
./configure --prefix=/usr/local/php --with-thttpd=../thttpd-2.21b

在configure后,又出现错误提示:error: xml2-config not found. Please check your libxml2 installation.
解决:sudo apt-get install libxml2
安装libxml2-dev软件包,操作如下:sudo apt-get install libxml2-dev
安装完成后,重新配置PHP

make 报错:

node.c:1953: error: dereferencing pointer to incomplete type
node.c:1955: error: dereferencing pointer to incomplete type
make: *** [ext/dom/node.lo] Error 1
在国外的一个网站上找到了这个,其他版本的php也同样适用。

# curl -o php-5.x.x.patch https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt
# cd php-5.x.x
# patch -p0 -b < ./php-5.x.x.patch 
   patching file ext/dom/node.c
   patching file 
   ext/dom/documenttype.c
   patching file ext/simplexml/simplexml.c
再次编译即可。

make 不报error错误即可进行make install。
php是否安装,不能仅仅靠php-V一定要进安装目录查看

安装 thttpd
thttpd $> cd thttpd-2.21b
thttpd $> ./configure --prefix=/usr/local/thttpd
thttpd $> sed -i 's#getline#get_line#g' extras/htpasswd.c
不然会报错,因为getline函数已经无效。
thttpd $> make
thttpd $> mkdir -p /usr/local/thttpd
thttpd $> mkdir -p /usr/local/thttpd/{man,sbin,www,etc,logs}
thttpd $> mkdir -p /usr/local/thttpd/man/{man1,man8}
thttpd $> mkdir -p /usr/local/thttpd/www/cgi-bin
thttpd-2.21b 版本的安装脚本写的更软弱·所有要手动创建这些目录
make
make install

遇到报错解决:
chgrp: invalid group: www' make[1]: *** [install] Error 1 make[1]: Leaving directory/home/linux/linux_c/thttpd/thttpd-2.25b/extras'
make: *** [installsubdirs] Error 2
增加组:
cat /etc/group
addgroup www
which addgroup
sudo addgroup www
cat /etc/group

linux@ubuntu:~/linux_c/thttpd/thttpd-2.25b$ cd /usr/local/thttpd/man/

linux@ubuntu:/usr/local/thttpd/man$

linux@ubuntu:/usr/local/thttpd/man$ ls -l

total 4

drwxr-xr-x 2 root root 4096 Sep 10 17:31 man8

linux@ubuntu:/usr/local/thttpd/man$ sudo mkdir -p man1

linux@ubuntu:/usr/local/thttpd/man$ ls -l

total 8

drwxr-xr-x 2 root root 4096 Sep 10 17:32 man1

drwxr-xr-x 2 root root 4096 Sep 10 17:31 man8

linux@ubuntu:/usr/local/thttpd/man$ cd -

/home/linux/linux_c/thttpd/thttpd-2.25b

linux@ubuntu:~/linux_c/thttpd/thttpd-2.25b$ sudo make install

OK 终于没有报错了
拷贝thttpd配置文件,本人为自己写配置文件。
contrib/redhat-rpm/thttpd.conf/
若提示[thttpd服务后出现/usr/sbin/thttpd: unknown user - 'httpd'错误提示]
可以更改用户为root
参考BUG比对

创建配置文件
thttpd $> cd /usr/local/thttpd/etc
thttpd $> vim thttpd.conf
port=80
user=www
nochroot
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
charset=utf-8
cgipat=/usr/local/thttpd/www/cgi-bin/*


安装thttpd服务器并配置php详情_第1张图片

dir定义的目录即为项目目录,可以自己定。绝对路径,我这里目录是/usr/local/thttpd/html
保留的一些指令如下:

root@Guard:/home/cyx/thttpd-2.21b# cd /usr/local/thttpd/etc/
root@Guard:/usr/local/thttpd/etc# ls
root@Guard:/usr/local/thttpd/etc# vim thttpd.conf
root@Guard:/usr/local/thttpd/etc# netstat -tunlp |grep 8080
root@Guard:/usr/local/thttpd/etc# netstat -tunlp |grep 80
tcp        0      0 0.0.0.0:60580           0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::80                   :::*                    LISTEN      1271/apache2    
root@Guard:/usr/local/thttpd/etc# netstat -ntlp
Active Internet connections (only servers)

tcp6       0      0 :::111                  :::*                    LISTEN      811/rpcbind     
tcp6       0      0 :::80                   :::*                    LISTEN      1271/apache2    
root@Guard:/usr/local/thttpd/etc# vim thttpd.conf
root@Guard:/usr/local/thttpd/etc# cd -
/home/cyx/thttpd-2.21b
root@Guard:/home/cyx/thttpd-2.21b# make install
/usr/bin/install -c -m 555 -o bin -g bin thttpd /usr/local/thttpd/sbin
/usr/bin/install -c -m 444 -o bin -g bin thttpd.8 /usr/local/thttpd/man/man8
for i in cgi-src extras ; do ( \
        cd $i ; \
        pwd ; \
        make  \
        WEBDIR=/usr/local/thttpd/www \
        CGIBINDIR=/usr/local/thttpd/www/cgi-bin \
        MANDIR=/usr/local/thttpd/man \
        WEBGROUP=www \
        install \
    ) ; done
/home/cyx/thttpd-2.21b/cgi-src
make[1]: Entering directory `/home/cyx/thttpd-2.21b/cgi-src'
mkdir /usr/local/thttpd/www/cgi-bin
mkdir: cannot create directory '/usr/local/thttpd/www/cgi-bin': File exists
make[1]: [install] Error 1 (ignored)
rm -f /usr/local/thttpd/www/cgi-bin/redirect
cp redirect /usr/local/thttpd/www/cgi-bin/redirect
rm -f /usr/local/thttpd/man/man8/redirect.8
cp redirect.8 /usr/local/thttpd/man/man8/redirect.8
rm -f /usr/local/thttpd/www/cgi-bin/ssi
cp ssi /usr/local/thttpd/www/cgi-bin/ssi
rm -f /usr/local/thttpd/man/man8/ssi.8
cp ssi.8 /usr/local/thttpd/man/man8/ssi.8
rm -f /usr/local/thttpd/www/cgi-bin/phf
cp phf /usr/local/thttpd/www/cgi-bin/phf
make[1]: Leaving directory `/home/cyx/thttpd-2.21b/cgi-src'
/home/cyx/thttpd-2.21b/extras
make[1]: Entering directory `/home/cyx/thttpd-2.21b/extras'
rm -f /usr/local/thttpd/sbin/makeweb /usr/local/thttpd/sbin/htpasswd /usr/local/thttpd/sbin/syslogtocern
cp makeweb /usr/local/thttpd/sbin/makeweb
chgrp www /usr/local/thttpd/sbin/makeweb
chgrp: invalid group: 'www'
make[1]: *** [install] Error 1
make[1]: Leaving directory `/home/cyx/thttpd-2.21b/extras'
make: *** [installsubdirs] Error 2
root@Guard:/home/cyx/thttpd-2.21b# cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:syslog,guard
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:
fax:x:21:
voice:x:22:
cdrom:x:24:guard
floppy:x:25:
tape:x:26:
sudo:x:27:guard
audio:x:29:
dip:x:30:guard
www-data:x:33:
backup:x:34:
operator:x:37:
list:x:38:
irc:x:39:
src:x:40:
gnats:x:41:
shadow:x:42:
utmp:x:43:telnetd
video:x:44:
sasl:x:45:
plugdev:x:46:guard
staff:x:50:
games:x:60:
users:x:100:
nogroup:x:65534:
libuuid:x:101:
netdev:x:102:
crontab:x:103:
syslog:x:104:
fuse:x:105:
messagebus:x:106:
mlocate:x:107:
ssh:x:108:
guard:x:1000:
lpadmin:x:110:guard
sambashare:x:111:guard
other:x:1001:lyj
lyj:x:1002:
mysql:x:112:
ssl-cert:x:113:
telnetd:x:114:
testssh:x:1003:
cyx:x:1004:
root@Guard:/home/cyx/thttpd-2.21b# addgroup www
Adding group `www' (GID 1005) ...
Done.
root@Guard:/home/cyx/thttpd-2.21b# cat /etc/group
root:x:0:
daemon:x:1:
bin:x:2:
sys:x:3:
adm:x:4:syslog,guard
tty:x:5:
disk:x:6:
lp:x:7:
mail:x:8:
news:x:9:
uucp:x:10:
man:x:12:
proxy:x:13:
kmem:x:15:
dialout:x:20:
fax:x:21:
voice:x:22:
cdrom:x:24:guard
floppy:x:25:
tape:x:26:
sudo:x:27:guard
audio:x:29:
dip:x:30:guard
www-data:x:33:
backup:x:34:
operator:x:37:
list:x:38:
irc:x:39:
src:x:40:
gnats:x:41:
shadow:x:42:
utmp:x:43:telnetd
video:x:44:
sasl:x:45:
plugdev:x:46:guard
staff:x:50:
games:x:60:
users:x:100:
nogroup:x:65534:
libuuid:x:101:
netdev:x:102:
crontab:x:103:
syslog:x:104:
fuse:x:105:
messagebus:x:106:
mlocate:x:107:
ssh:x:108:
guard:x:1000:
lpadmin:x:110:guard
sambashare:x:111:guard
other:x:1001:lyj
lyj:x:1002:
mysql:x:112:
ssl-cert:x:113:
telnetd:x:114:
testssh:x:1003:
cyx:x:1004:
www:x:1005:
root@Guard:/home/cyx/thttpd-2.21b# make install
/usr/bin/install -c -m 555 -o bin -g bin thttpd /usr/local/thttpd/sbin
/usr/bin/install -c -m 444 -o bin -g bin thttpd.8 /usr/local/thttpd/man/man8
for i in cgi-src extras ; do ( \
        cd $i ; \
        pwd ; \
        make  \
        WEBDIR=/usr/local/thttpd/www \
        CGIBINDIR=/usr/local/thttpd/www/cgi-bin \
        MANDIR=/usr/local/thttpd/man \
        WEBGROUP=www \
        install \
    ) ; done
/home/cyx/thttpd-2.21b/cgi-src
make[1]: Entering directory `/home/cyx/thttpd-2.21b/cgi-src'
mkdir /usr/local/thttpd/www/cgi-bin
mkdir: cannot create directory '/usr/local/thttpd/www/cgi-bin': File exists
make[1]: [install] Error 1 (ignored)
rm -f /usr/local/thttpd/www/cgi-bin/redirect
cp redirect /usr/local/thttpd/www/cgi-bin/redirect
rm -f /usr/local/thttpd/man/man8/redirect.8
cp redirect.8 /usr/local/thttpd/man/man8/redirect.8
rm -f /usr/local/thttpd/www/cgi-bin/ssi
cp ssi /usr/local/thttpd/www/cgi-bin/ssi
rm -f /usr/local/thttpd/man/man8/ssi.8
cp ssi.8 /usr/local/thttpd/man/man8/ssi.8
rm -f /usr/local/thttpd/www/cgi-bin/phf
cp phf /usr/local/thttpd/www/cgi-bin/phf
make[1]: Leaving directory `/home/cyx/thttpd-2.21b/cgi-src'
/home/cyx/thttpd-2.21b/extras
make[1]: Entering directory `/home/cyx/thttpd-2.21b/extras'
rm -f /usr/local/thttpd/sbin/makeweb /usr/local/thttpd/sbin/htpasswd /usr/local/thttpd/sbin/syslogtocern
cp makeweb /usr/local/thttpd/sbin/makeweb
chgrp www /usr/local/thttpd/sbin/makeweb
chmod 2755 /usr/local/thttpd/sbin/makeweb
cp htpasswd /usr/local/thttpd/sbin/htpasswd
cp syslogtocern /usr/local/thttpd/sbin/syslogtocern
rm -f /usr/local/thttpd/man/man1/makeweb.1
cp makeweb.1 /usr/local/thttpd/man/man1/makeweb.1
rm -f /usr/local/thttpd/man/man1/htpasswd.1
cp htpasswd.1 /usr/local/thttpd/man/man1/htpasswd.1
rm -f /usr/local/thttpd/man/man8/syslogtocern.8
cp syslogtocern.8 /usr/local/thttpd/man/man8/syslogtocern.8
make[1]: Leaving directory `/home/cyx/thttpd-2.21b/extras'
root@Guard:/home/cyx/thttpd-2.21b# cd /usr/local/thttpd/etc/
root@Guard:/usr/local/thttpd/etc# vi thttpd.conf 
root@Guard:/usr/local/thttpd/etc# cd ../
root@Guard:/usr/local/thttpd# ls
etc  logs  man  sbin  www
root@Guard:/usr/local/thttpd# mkdir /usr/local/thttpd/html
root@Guard:/usr/local/thttpd# ls
etc  html  logs  man  sbin  www
root@Guard:/usr/local/thttpd# cd html
root@Guard:/usr/local/thttpd/html# vi index.html
root@Guard:/usr/local/thttpd/html# vim /etc/init.d/thttpd
root@Guard:/usr/local/thttpd/html# cat /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: /etc/init.d/thttpd {start|stop}"
fi
root@Guard:/usr/local/thttpd/html# cd /etc/init.d/ 
root@Guard:/etc/init.d# chmod 777 thttpd 
root@Guard:/etc/init.d# ls
root@Guard:/etc/init.d# /etc/init.d/thttpd start
cat: /usr/local/thttpd/logs/thttpd.pid: No such file or directory
Starting THTTPD....
root@Guard:/etc/init.d# /usr/local/thttpd/sbin/thttpd: unknown config option
root@Guard:/etc/init.d# vim /etc/init.d/thttpd
root@Guard:/etc/init.d# /etc/init.d/thttpd start
cat: /usr/local/thttpd/logs/thttpd.pid: No such file or directory
Starting THTTPD....
root@Guard:/etc/init.d# /usr/local/thttpd/sbin/thttpd: unknown user - 'www'
root@Guard:/etc/init.d# cd /usr/local/thttpd/etc/
root@Guard:/usr/local/thttpd/etc# ls
thttpd.conf
root@Guard:/usr/local/thttpd/etc# vi thttpd.conf 
root@Guard:/usr/local/thttpd/etc# /usr/local/thttpd/sbin/thttpd -C /usr/local/thttpd/etc/thttpd.conf
/usr/local/thttpd/etc/throttle.conf: No such file or directory
root@Guard:/usr/local/thttpd/etc# vi thttpd.conf 
root@Guard:/usr/local/thttpd/etc# /usr/local/thttpd/sbin/thttpd -C /usr/local/thttpd/etc/thttpd.conf
/usr/local/thttpd/sbin/thttpd: unknown user - 'httpd'
root@Guard:/usr/local/thttpd/etc# vi thttpd.conf 
root@Guard:/usr/local/thttpd/etc# /usr/local/thttpd/sbin/thttpd -C /usr/local/thttpd/etc/thttpd.conf
root@Guard:/usr/local/thttpd/etc# ps -aux | grep thttpd
guard    21949  0.0  0.1  12772  3276 ?        Ss   17:09   0:00 /usr/local/thttpd/sbin/thttpd -C /usr/local/thttpd/etc/thttpd.conf
root     22029  0.0  0.0   5412   860 pts/3    S+   17:28   0:00 grep --color=auto thttpd
root@Guard:/usr/local/thttpd/etc# /usr/local/thttpd/sbin/thttpd -C /usr/local/thttpd/etc/thttpd.conf
root@Guard:/usr/local/thttpd/etc# curl 127.0.0.1:8081

hello
root@Guard:/usr/local/thttpd/etc# curl 127.0.0.1:8081/index.html

hello
root@Guard:/usr/local/thttpd/etc# vi /usr/local/thttpd/html/index.php
root@Guard:/usr/local/thttpd/etc# curl 127.0.0.1:8081/index.php
hello world

创建启动脚本

#!/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: /etc/init.d/thttpd {start|stop}"
fi

启动:

guard@Guard:~$ /usr/local/thttpd/sbin/thttpd -C /usr/local/thttpd/etc/thttpd.conf
查看是否开启thttpd:
guard@Guard:~$ ps -ef | grep thttpd
配置:
guard@Guard:~$ cat /usr/local/thttpd/etc/thttpd.conf

你可能感兴趣的:(安装thttpd服务器并配置php详情)