CentOS使用yum命令安装Lighttpd Web服务器
如何使用yum命令在CentOS Linux上安装nginx。如何使用yum命令在CentOS Linux或RHEL服务器上安装Lighttpd Web服务器?如何使用Lighttpd Web服务器在CentOS上安装和配置php和mysql? Lighttpd是一种快速安全的Web服务器,已针对高性能环境进行了优化。与其他Web服务器相比,该服务器的内存占用量非常低,并且可以处理cpu-load。它包括以下高级功能:
- 快速CGI
- CGI
- 验证码
- 输出压缩
- URL重写等
CentOS开启EPEL仓库
lighttpd服务器不是基于默认CentOS或RHEL的系统的一部分。
要使用yum命令安装lighttpd,首先获取最新的epel发布文件,输入:
# wget http://epel.mirror.com/epel/6/i386/epel-release-6-8.noarch.rpm
输出示例:
--2014-02-23 12:24:52-- http://epel.mirror.com/epel/6/i386/epel-release-6-8.noarch.rpm Resolving epel.mirror.com... 120.88.47.14, 2401:4800:2121:c0:ff:ee:ee:2 Connecting to epel.mirror.com|120.88.47.14|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 14540 (14K) [application/x-redhat-package-manager] Saving to: “epel-release-6-8.noarch.rpm” 100%[==========================================================================================>] 14,540 54.6K/s in 0.3s 2014-02-23 12:24:53 (54.6 KB/s) - “epel-release-6-8.noarch.rpm” saved [14540/14540]
使用rpm命令安装下载的epel-release-6-8.noarch.rpm文件,键入:
# rpm -ivh epel-release-6-8.noarch.rpm
输出示例:
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Preparing... ########################################### [100%] 1:epel-release ########################################### [100%]
CentOS Linux安装Lighttpd Web服务器
键入以下yum命令:
# yum install lighttpd lighttpd-fastcgi lighttpd-mod_geoip
输出示例:
Loaded plugins: downloadonly, fastestmirror, security Loading mirror speeds from cached hostfile * base: mirror.thelinuxfix.com * epel: mirror.steadfast.net * extras: holmes.umflint.edu * updates: bay.uchicago.edu Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package lighttpd.x86_64 0:1.4.34-1.el6 will be installed ---> Package lighttpd-fastcgi.x86_64 0:1.4.34-1.el6 will be installed --> Processing Dependency: spawn-fcgi for package: lighttpd-fastcgi-1.4.34-1.el6.x86_64 ---> Package lighttpd-mod_geoip.x86_64 0:1.4.34-1.el6 will be installed --> Processing Dependency: libGeoIP.so.1()(64bit) for package: lighttpd-mod_geoip-1.4.34-1.el6.x86_64 --> Running transaction check ---> Package GeoIP.x86_64 0:1.4.8-1.el6 will be installed ---> Package spawn-fcgi.x86_64 0:1.6.3-1.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ====================================================================== Package Arch Version Repository Size ====================================================================== Installing: lighttpd x86_64 1.4.34-1.el6 epel 294 k lighttpd-fastcgi x86_64 1.4.34-1.el6 epel 44 k lighttpd-mod_geoip x86_64 1.4.34-1.el6 epel 21 k Installing for dependencies: GeoIP x86_64 1.4.8-1.el6 epel 620 k spawn-fcgi x86_64 1.6.3-1.el6 epel 16 k Transaction Summary ====================================================================== Install 5 Package(s) Total download size: 995 k Installed size: 2.4 M Is this ok [y/N]: y Downloading Packages: (1/5): GeoIP-1.4.8-1.el6.x86_64.rpm | 620 kB 00:00 (2/5): lighttpd-1.4.34-1.el6.x86_64.rpm | 294 kB 00:00 (3/5): lighttpd-fastcgi-1.4.34-1.el6.x86_64.rp | 44 kB 00:00 (4/5): lighttpd-mod_geoip-1.4.34-1.el6.x86_64. | 21 kB 00:00 (5/5): spawn-fcgi-1.6.3-1.el6.x86_64.rpm | 16 kB 00:00 --------------------------------------------------------------------- Total 1.7 MB/s | 995 kB 00:00 warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 Importing GPG key 0x0608B895: Userid : EPEL (6) <[email protected]> Package: epel-release-6-8.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 Is this ok [y/N]: y Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Warning: RPMDB altered outside of yum. Installing : lighttpd-1.4.34-1.el6.x86_64 1/5 Installing : GeoIP-1.4.8-1.el6.x86_64 2/5 Installing : spawn-fcgi-1.6.3-1.el6.x86_64 3/5 Installing : lighttpd-fastcgi-1.4.34-1.el6.x86_64 4/5 Installing : lighttpd-mod_geoip-1.4.34-1.el6.x86_64 5/5 Verifying : lighttpd-1.4.34-1.el6.x86_64 1/5 Verifying : lighttpd-mod_geoip-1.4.34-1.el6.x86_64 2/5 Verifying : spawn-fcgi-1.6.3-1.el6.x86_64 3/5 Verifying : GeoIP-1.4.8-1.el6.x86_64 4/5 Verifying : lighttpd-fastcgi-1.4.34-1.el6.x86_64 5/5 Installed: lighttpd.x86_64 0:1.4.34-1.el6 lighttpd-fastcgi.x86_64 0:1.4.34-1.el6 lighttpd-mod_geoip.x86_64 0:1.4.34-1.el6 Dependency Installed: GeoIP.x86_64 0:1.4.8-1.el6 spawn-fcgi.x86_64 0:1.6.3-1.el6 Complete!
首次打开CentOS Linux上的lighttpd服务器,输入:
# service lighttpd start # chkconfig lighttpd on
CentOS Linux安装PHP
输入以下yum命令以在CentOS Linux上安装php5.x和相关模块:
# yum install php-cli php-mbstring php-pecl-apc php-pdo php php-gd \ php-mysql php-xml php-bcmath php-xmlrpc php-pear php-common \ php-devel php-imap php-suhosin php-pecl-memcache
php已与MySQL数据库服务器,图形(gd)库和其他最常见的模块一起安装。
CentOS Linux安装MySQL数据库服务器
键入以下命令,使用yum命令在基于CentOS Linux的系统上安装mysql数据库服务器:
# yum install mysql-server mysql
打开mysql服务器:
# chkconfig mysqld on # service mysqld start
设置mysql服务器管理员帐户的root用户密码,输入:
# mysqladmin -u root password NEWPASSWORDHERE
CentOS Linux Lighttpd Web服务器配置
- 配置目录:
/etc/lighttpd /
- 主要配置文件:/etc/lighttpd/lighttpd.conf
- 模块配置文件:
/etc/lighttpd/modules.conf
- 模块和其他配置文件目录:/etc/lighttpd/conf.d/
- 默认DocumentRoot /服务器根目录,用于存储php/html/css/js文件:/var/www/lighttpd /默认日志目录:/var/log/lighttpd /
配置lighttpd
编辑/etc/lighttpd/lighttpd.conf,输入:
# vi /etc/lighttpd/lighttpd.conf
设置服务器根目录
进行如下设置以保护服务器根:
var.server_root = "/var/www"
加载模块
取消注释以下行:
include "modules.conf"
将服务器端口设置为80
server.port = 80
绑定到名为1.2.3.4的特定IP
将以下内容设置为您的Web服务器公共ip,例如1.2.3.4:
server.bind = "1.2.3.4"
设置文件根
您将将html/images/js/php文件存储在server_root +"/lighttpd"中,即/var/www/lighttpd /目录中:
server.document-root = server_root + "/lighttpd"
隐藏/设置服务器标签
设置服务器名称或隐藏它:
server.tag = "theitroad-Web-Server"
保存并关闭文件。
配置lighttpd模块
编辑/etc/lighttpd/modules.conf,输入:
# vi /etc/lighttpd/modules.conf
将php配置为fastcgi
取消注释以下用于PHP的FastCGI(mod_fastcgi)行:
include "conf.d/fastcgi.conf"
还要确保按照要求取消以下内容:
server.modules = ( "mod_access", "mod_alias", "mod_auth", # "mod_evasive", "mod_redirect", "mod_rewrite", # "mod_setenv", # "mod_usertrack", )
配置php5
编辑/etc/lighttpd/conf.d/fastcgi.conf文件,输入:
# cp -v /etc/lighttpd/conf.d/fastcgi.{conf,bakup} # vi /etc/lighttpd/conf.d/fastcgi.conf
如下更新以使用FastCGI配置PHP和lighttpd:
## small server config ## ## For a large server set max-procs, PHP_FCGI_CHILDREN, and PHP_FCGI_MAX_REQUESTS as per your setup ## server.modules += ( "mod_fastcgi" ) fastcgi.server = ( ".php" => (( "bin-path" => "/usr/bin/php-cgi", "socket" => "/tmp/php-cgi.socket." + var.PID, "max-procs" => 1, "idle-timeout" => 30, "bin-environment" => ( "PHP_FCGI_CHILDREN" => "1", "PHP_FCGI_MAX_REQUESTS" => "50" ), "bin-copy-environment" => ( "PATH", "SHELL", "USER" ), "broken-scriptfilename" => "enable" )) )
保存并关闭文件。
重新启动lighttpd
输入以下命令以在CentOS Linux上重新启动lighttpd服务器:
# service lighttpd restart
验证一切正常
确保端口80已打开并由lighttpd拥有:
# netstat -tulpn | grep :80
输出示例:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 29085/lighttpd
确保在日志文件中未报告任何错误:
# tailf /var/log/lighttpd/error.log
输出示例:
2014-03-09 04:48:11: (server.c.1241) logfiles cycled UID = 0 PID = 30314 2014-03-09 10:54:27: (server.c.1557) server stopped by UID = 0 PID = 4680 2014-03-09 10:54:28: (log.c.166) server started
测试一下
在/var/www/lighttpd /目录中创建hello.php:
# vi /var/www/lighttpd/hello.php
附加以下代码:
<html> <head> <title>Hello - Lighttpd - PHP - theitroad - Test</title> </head> <body> <h1>Hosshin - Zen monk</h1> Zen monk poem: <?php $zen_poem = '<blockquote><em>'; $zen_poem .= "Coming, all is clear,<br>"; $zen_poem .= "no doubt about it.<br>"; $zen_poem .= "Going, all is clear,<br>"; $zen_poem .= "without a doubt.<br>"; $zen_poem .= "What, then, is it all?"; $zen_poem .= "</em></blockquote>"; echo $zen_poem; ?> <hr> <h1>PHPINFO</h1> <?php phpinfo(); ?> <hr> <center><small>© theitroad</small></center> </body> </html>
触发网络浏览器并输入url:
http://your-server-ip/hello.php http://server1.theitroad.local/hello.php
在基于CentOS Lighttpd的服务器上运行PHP