有个搬瓦工服务器,想装个不占内存的HTTP服务器放静态网页,发现有几个教程还不好用,把能用的转过来了。 我自己只用到了LIGHTTPD部分。看文章不错就整个转过来了。 下面有用到NANO编辑器,我的服务器没有,用的VIM代替。
【1.准备工作】
#升级系统
sudo yum update
#下载WGET
sudo yum install wget
【2.安装MYSQL】
#安装MYSQL
sudo yum install mysql-server
#设置开机启动
sudo chkconfig --levels 235 mysqld on
#验证是否安装成功。如果提示MySQL ERROR 2002 (HY000)。则尝试“mysql_secure_installation”命令
sudo service mysqld status
#如果服务没启动,使用下面命令
sudo service mysqld status
#创建MYSQL的ROOT用户密码,首次安装直接回车
sudo mysql_secure_installation
Enter current password for root (enter for none):_
#创建密码并简单配置MYSQL(下面示例,SQL.ROOT.PASSWORD.EXAMPLE为自己设置的密码)
Set root password? [Y/n] y
New password: SQL.ROOT.PASSWORD.EXAMPLE
Re-enter new password: SQL.ROOT.PASSWORD.EXAMPLE
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
【3.安装LIGHTTPD】
#安装RHEL EPEL Repo
sudo rpm --import https://fedoraproject.org/static/0608B895.txt
sudo wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -ivh epel-release-6-8.noarch.rpm
#安装LIGHTTPD
sudo yum install lighttpd
#开机启动
sudo chkconfig --levels 235 lighttpd on
#开启服务并查看状态
sudo service lighttpd start
sudo service lighttpd status
#现在可以用浏览器打开地址“http://IP地址”浏览网页了,不知道IP的用下面命令:
ifconfig
————-Lighttpd的故障排除———————————-
错误1:Lighttpd fails to start: “socket failed: Address family not supported by protocol” or “please use server.use-ipv6 only for hostnames, not without server.bind…” , 打开 Lighttpd.conf:
sudo nano /etc/lighttpd/lighttpd.conf
#禁止 IPv6:
##
server.use-ipv6 = "disable"
##
错误2:Warning “can’t have more connections than fds/2: 1024 1024”, 打开 Lighttpd.conf:
sudo nano /etc/lighttpd/lighttpd.conf
#取消注释 server.max-fds = 2048
##
server.max-fds = 2048
##
#重启LIGHTTPD
sudo service lighttpd restart
Stopping lighttpd [OK]
Starting lighttpd [OK]
【4.安装PHP】
#如果要安装最新PHP5.4版本,执行如下代码,默认5.3(来自评论)
sudo yum --enablerepo=remi update php php-common
#安装PHP5 (FPM):
sudo yum install php-fpm php-pdo lighttpd-fastcgi
#打开 www.conf:
sudo nano /etc/php-fpm.d/www.conf
#添加 lighttpd 到用户和用户组:
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = lighttpd
; RPM: Keep a group allowed to write in log dir.
group = lighttpd
#开机启动
sudo chkconfig --levels 235 php-fpm on
#启动服务并且检查状态
sudo service php-fpm start
sudo service php-fpm status
#安装完成,启用 Lighttpd 的 PHP5 支持 . 打开 php.ini 文件:
sudo nano /etc/php.ini
#取消这行的注释
;
cgi.fix_pathinfo=1
;
#打开 fastcgi.conf:
sudo nano /etc/lighttpd/modules.conf
#取消这行的注释
##
include "conf.d/fastcgi.conf"
##
#打开 fastcgi.conf:
sudo nano /etc/lighttpd/conf.d/fastcgi.conf
#添加如下内容
## for the php-num-procs example it means you will get 17*5 = 85 php
## processes. you always should need this high number for your very
## busy sites. And if you have a lot of RAM. :)
## ADD YOUR LINES HERE
fastcgi.server += ( ".php" =>
((
"host" => "127.0.0.1",
"port" => "9000",
"broken-scriptfilename" => "enable"
))
)
## GOOD JOB
#fastcgi.server = ( ".php" =>
#重启服务
sudo service php-fpm restart
sudo service lighttpd restart
【6.测试PHP文件能否解析】
#创建 info.php:
sudo echo '<?php phpinfo();?>' > /var/www/lighttpd/info.php
#访问 http://IP地址/info.php