centos
centos下搭建webserver开发环境
一、安装相关软件包
[root@web ~]# yum -y install pcre pcre-devel bzip2-devel zlib zlib-devel mysql-server php php-mysql
二、编译并安装lighttpd
[root@web ~]# tar zxf lighttpd-1.4.30.tar.gz
[root@web ~]# cd lighttpd-1.4.30
[root@web lighttpd-1.4.30]# ./configure --prefix=/usr/local/lighttpd --with-openssl --with-openssl-libs=/usr/lib
[root@web lighttpd-1.4.30]# make && make install
配置启动及配置文件目录
[root@web lighttpd-1.4.30]# cp doc/initscripts/rc.lighttpd.redhat /etc/init.d/lighttpd
[root@web lighttpd-1.4.30]# chmod +x /etc/init.d/lighttpd
[root@web lighttpd-1.4.30]# cp -p doc/initscripts/sysconfig.lighttpd /etc/sysconfig/lighttpd
[root@web lighttpd-1.4.30]# mkdir -p /etc/lighttpd
[root@web lighttpd-1.4.30]# cp -rf doc/config/* /etc/lighttpd/
[root@web lighttpd-1.4.30]# chkconfig --add lighttpd
[root@web lighttpd-1.4.30]# chkconfig lighttpd on
[root@web ~]# vim +29 /etc/init.d/lighttpd
lighttpd=/usr/sbin/lighttpd
修改成:
lighttpd=/usr/local/lighttpd/sbin/lighttpd
[root@web ~]# mkdir -p /srv/www/htdocs
[root@web ~]# mkdir /var/log/lighttpd
[root@web ~]# touch /var/log/lighttpd/access.log
[root@web ~]# touch /var/log/lighttpd/error.log
[root@web ~]# useradd -s /sbin/nologin lighttpd
[root@web ~]# chown -r lighttpd:lighttpd /var/log/lighttpd/
关闭ipv6的支持
[root@web ~]# vim +93 /etc/lighttpd/lighttpd.conf
server.use-ipv6 = enable
修改成:
server.use-ipv6 = disable
将压缩缓存目录修改到/tmp下
vim /etc/lighttpd/lighttpd.conf
var.cache_dir = /tmp/cache/lighttpd
启动服务,查看端口监听
[root@web ~]# /etc/init.d/lighttpd start
starting lighttpd: [ ok ]
[root@web ~]# netstat -tnlp | grep lighttpd
tcp 0 0 0.0.0.0:80 0.0.0.0:* listen 10601/lighttpd
三、配置fastcgi支持php
配置lighttpd modules(/etc/lighttpd/modules.conf)取消需要用到模块的注释:mod_rewrite,mod_redirect,mod_access,mod_fastcgi,mod_compress,mod_accesslog
修改后:
server.modules = (
mod_access,
mod_redirect,
mod_rewrite,
)
include conf.d/compress.conf
include conf.d/fastcgi.conf
配置/etc/lighttpd/conf.d/fastcgi.conf支持php(注意:socket和bin-path需要修改)
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”,
)
),
)
测试,在/srv/www/htdocs下建立以下测试文件:
[root@web ~]# cat /srv/www/htdocs/test.php