介绍
Lighttpd 是一个开源的 Web 服务器,它具有较低的内存占用空间,许多网站(如YouTube和维基百科)运行 在 Lighttpd 服务器。MySQL 是用于 Web 应用程序(如WordPress)的流行数据库解决方案,通常与服务器端脚本语言PHP 结合使用。
第一步 – 先决条件
更新 yum:
sudo yum update
您需要安装 wget,一个用于使用 HTTP,HTTPS 和 FTP 检索文件的软件包:
sudo yum install wget
请注意,命令以“sudo”开头。这将允许您以 root 权限运行。
第二步 – 安装MySQL
安装MySQL:
sudo yum install mysql-server
为 MySQL 创建一个系统启动链接,使服务在引导时运行:
sudo chkconfig --levels 235 mysqld on
现在查看一下 Mysql 是否在运行:
sudo service mysqld status
如果没在运行就执行:
sudo service mysqld start
为 MySQL 用户 root 创建密码并执行一些初始配置:
sudo mysql_secure_installation
Enter current password for root (enter for none):_
由于 MySQL root 密码尚未配置,我们只需按 ENTER 键即可继续设置 MySQL 的过程:
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
第三步 – 安装 Lighttpd
来自官方 CentOS 存储库的 Lighttpd 和P HP-FPM 不受支持,我们继续向 CentOS 添加 Remi RPM 和 EPEL 存储库:
sudo rpm --import https://project.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
为 Lighttpd 创建一个系统启动链接,以使服务在启动时运行:
sudo chkconfig --levels 235 lighttpd on
启动服务并检查它是否正在运行:
sudo service lighttpd start
sudo service lighttpd status
打开浏览器并输入您的 IP,便可以看到 Lighttpd 的欢迎页面:
典型错误 – Lighttpd疑难解答
错误1:Lighttpd fails to start: “socket failed:Address family not supported by protocol” 或 “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
第四步 – 安装PHP
安装PHP5(FPM):
sudo yum install php-fpm 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
为PHP-FPM创建一个系统启动链接,以使服务在启动时运行:
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" =>
安装 MySQL PHP 模块:
sudo yum install php-mysql
重启 Lighttpd 和 PHP-FPM:
sudo service php-fpm restart
sudo service lighttpd restart
第六步(可选) – 使用info.php 测试 PHP
创建 info.php:
sudo nano /var/www/lighttpd/info.php
添加以下行:
<?php
phpinfo(); ?>
现在打开浏览器输入你的IP,可以看到PHP的页面了,页面显示如下:
如果你看到这个页面,恭喜你已经成功了。