一、安装lighttpd
由于CentOS官方的源中没有Lighttpd包,因此需要手动导入RPMforge源:
如果你是64位的系统:
Shell
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
1
2
wgethttp://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
rpm-Uvhrpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
如果是32位系统:
Shell
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
rpm -Uvh rpmforge-release-0.5.2-2.el5.rf.i386.rpm
1
2
wgethttp://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm
rpm-Uvhrpmforge-release-0.5.2-2.el5.rf.i386.rpm
然后,你可以像这样安装Lighttpd:
Shell
yum install lighttpd
1
yuminstalllighttpd
接着我们设置开机启动lighttpd并立即启动它:
Shell
chkconfig --levels 235 lighttpd on
/etc/init.d/lighttpd start
1
2
chkconfig--levels235lighttpdon
/etc/init.d/lighttpdstart
问题1:
如果在启动的时候提示如下错误:
Shell
(network.c.203) socket failed: Address family not supported by protocol
1
(network.c.203)socketfailed:Addressfamilynotsupportedbyprotocol
则打开 /etc/lighttpd/lighttpd.conf 文件,找到server.use-ipv6一行配置节,将enable改为disable,基本上可以正常启动。
问题2:
如果启动时出现如下错误:couldn’t set ‘maxfiledescriptors’ Operation not permitted
解决办法:
1)关闭selinux:
Shell
# vi /etc/selinux/config
1
# vi /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled后重启。
2)创建一个selinux模块允许lighttpd有权限设置filedescriptor限制
Shell
# /usr/sbin/semodule -DB
# service auditd restart
# service lighttpd restart
1
2
3
# /usr/sbin/semodule -DB
# service auditd restart
# service lighttpd restart
问题解决!问题出现原因:因为使用root权限登录的CentOS,所以不存在权限的问题,其实是selinux限制了程序设置最大文件描述符,关闭限制后就可以重启
二、添加php支持
Shell
yum install lighttpd-fastcgi php-cli
1
yuminstalllighttpd-fastcgiphp-cli
安装好对应的fastcgi以及php模块后对lighttpd进行配置。
1 、打开 /etc/php.ini 文件
在文件的最后(END前)添加一句
Shell
cgi.fix_pathinfo = 1
1
cgi.fix_pathinfo=1
2、打开 /etc/lighttpd/modules.conf 文件
将 include “conf.d/fastcgi.conf” 一行取消注释并保存
3、打开 /etc/lighttpd/conf.d/fastcgi.conf 文件
找到 fastcgi.server这一节配置段,并将其全部反注释(使之生效),并修改为如下(注意红色为修改部分):
fastcgi.server = ( “.php” =>
( “php-local” =>
(
“socket” => “/tmp/php-fastcgi-1.socket“,
“bin-path” => “/usr/bin/php-cgi“,
“max-procs” => 1,
“broken-scriptfilename” => “enable”,
)
),
( “php-tcp” =>
(
“host” => “127.0.0.1″,
“port” => 9999,
“check-local” => “disable”,
“broken-scriptfilename” => “enable”,
)
),
( “php-num-procs” =>
(
“socket” => “/tmp/php-fastcgi-2.socket“,
“bin-path” => “/usr/bin/php-cgi“,
“bin-environment” => (
“PHP_FCGI_CHILDREN” => “16″,
“PHP_FCGI_MAX_REQUESTS” => “10000″,
),
“max-procs” => 5,
“broken-scriptfilename” => “enable”,
)
),
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fastcgi.server=(“.php”=>
(“php-local”=>
(
“socket”=>“/tmp/php-fastcgi-1.socket“,
“bin-path”=>“/usr/bin/php-cgi“,
“max-procs”=>1,
“broken-scriptfilename”=>“enable”,
)
),
(“php-tcp”=>
(
“host”=>“127.0.0.1″,
“port”=>9999,
“check-local”=>“disable”,
“broken-scriptfilename”=>“enable”,
)
),
(“php-num-procs”=>
(
“socket”=>“/tmp/php-fastcgi-2.socket“,
“bin-path”=>“/usr/bin/php-cgi“,
“bin-environment”=>(
“PHP_FCGI_CHILDREN”=>“16″,
“PHP_FCGI_MAX_REQUESTS”=>“10000″,
),
“max-procs”=>5,
“broken-scriptfilename”=>“enable”,
)
),
)
最后保存即可。
现在可以重启Lighttpd使之生效:
Shell
# /etc/init.d/lighttpd restart
1
# /etc/init.d/lighttpd restart
三、添加php对mysql的支持
Shell
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
1
yuminstallphp-mysqlphp-gdphp-imapphp-ldapphp-odbcphp-pearphp-xmlphp-xmlrpc
上述命令已经同时安装好了php的MySQL、GD图形库、IMAP、ODBC、Pear、xml等支持组件。