Lighttpd是一款安全,快速,符合标准的Web服务器,专为速度至关重要的环境而设计。 本教程将介绍如何在具有PHP支持(通过PHP-FPM)和MySQL支持的CentOS 7服务器上安装Lighttpd。 PHP-FPM(FastCGI Process Manager)是一种替代的PHP FastCGI实现,具有对任何大小的网站(特别是繁忙的站点)有用的一些附加功能。 我在本教程中使用PHP-FPM,而不是Lighttpd的spawn-fcgi。
1初步说明
在本教程中,我使用IP地址为192.168.1.100的hostname 。 这些设置可能会有所不同,因此您必须在适当的情况下更换它们。
2安装MariaDB作为MySQL代替
首先我们像这样安装MySQL:
yum -y install mariadbmariadb-server
然后,我们为MySQL创建系统启动链接(以便每当系统启动时,MySQL自动启动)并启动MySQL服务器:
systemctl enable mariadb.service
systemctl start mariadb.service
为MarisDB根帐户设置密码:
mysql_secure_installation
[root@server1 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n]
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n]
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
3安装Lighttpd
由于Lighttpd和PHP-FPM不能从官方CentOS存储库获得,因此我们需要启用EPEL存储库:
yum -y install epel-release
导入EPEL GPG密钥:
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
然后运行:
yum update
之后,我们可以像这样安装Lighttpd:
yum -y install lighttpd
然后我们创建Lighttpd的系统启动链接(以便Lighttpd在系统引导时自动启动)并启动它:
systemctl enable lighttpd.service
systemctl start lighttpd.service
如果Lighttpd无法从以下错误消息开始...
(network.c.203) socket failed: Address family not supported by protocol
...打开/etc/lighttpd/lighttpd.conf ...
nano /etc/lighttpd/lighttpd.conf
...并将server.use-ipv6从enable设置为disable :[...]
##
## Use IPv6?
##
server.use-ipv6 = "disable"
[...]
然后尝试再次启动Lighttpd - 它现在应该没有任何问题:
systemctl startlighttpd.service
Lighttpd的文件根目录在/ var / www / htdocs(基本目录/ var / www plus htdocs作为根据lighttpd.conf文件的子目录),但它将默认文件安装到/ var / www / lighttpd。 这是不一致的,所以我们必须重命名这样的目录。
mv /var/www/lighttpd /var/www/htdocs
现在将您的浏览器指向http://192.168.1.100 ,您应该看到以下页面:
Lighttpd的默认文档根目录是/ var / www / htdocs / on CentOS 7,配置文件为/etc/lighttpd/lighttpd.conf 。
4安装PHP
我们可以通过PHP-FPM在Lighttpd中进行PHP工作,我们安装如下:
yum -y install php-fpm lighttpd-fastcgi
PHP-FPM是一个守护进程,在端口9000上运行FastCGI服务器。
打开/etc/php-fpm.d/www.conf ...
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.
; RPM: apache Choosed to be able to access some dir as httpd
user = lighttpd
; RPM: Keep a group allowed to write in log dir.
group = lighttpd
[...]
创建PHP-FPM的系统启动链接并启动它:
systemctl enable php-fpm.service
systemctl start php-fpm.service
如果觉得《lighttpd php7 源码安装 如何在CentOS 7上安装Lighttpd与PHP-FPM和MariaDB》对你有帮助,请点赞、收藏,并留下你的观点哦!