如何在 CentOS/RHEL 8/7 上使用 PHP 和 MariaDB 安装 Lighttpd

如何在 CentOS/RHEL 8/7 上使用 PHP 和 MariaDB 安装 Lighttpd

Lighttpd是一种开源、安全、快速、灵活且更优化的 Web 服务器,专为与其他 Web 服务器相比,内存利用率较低的速度关键型环境而设计。

它可以处理多达10,000个连接并行在一台服务器与有效的CPU负载管理,并配备了一个先进的功能集,如快速CGI,SCGI,身份验证,输出压缩,URL重写和更多。

Lighttpd是每个 Linux 服务器的优秀解决方案,因为它的高速 io 基础设施使我们能够使用相同的硬件扩展性能,优于其他替代 Web 服务器。

在本教程中,我们将介绍如何在CentOS/RHEL 8/7发行版上安装使用PHP、PHP-FPM和 MariaDB 的Lighttpd,该发行版包含主机名 tecmint.com IP 地址192.168.0.103。

第 1 步:安装 Lighttpd Web 服务器

1.要安装 Lighttpd,首先,您需要使用以下 yum 命令更新系统软件包和可用存储库。

# yum -y update

2.接下来,您需要在您的系统上启用 EPEL 存储库,并使用以下命令更新软件包。

# yum -y install epel-release

# yum -y update

3.启用 EPEL 存储库后,现在可以通过运行以下命令安装Lighttpd。

# yum install lighttpd

4. 安装 Lighttpd包后,您可以启动并启用服务在启动时自动启动,并确保使用以下命令验证状态。

# systemctl start lighttpd

# systemctl enable lighttpd

# systemctl status lighttpd

5.现在使用以下命令验证安装在您的系统上的Lighttpd版本。

# lighttpd -v

lighttpd/1.4.55 (ssl) - a light and fast webserver

6.现在您需要在防火墙上允许 HTTP 和HTTPS流量。

# firewall-cmd --permanent --zone=public --add-service=http

# firewall-cmd --permanent --zone=public --add-service=https

# firewall-cmd --reload

7.现在打开浏览器并指向以下 URL,以查看您的Lighttpd网络服务器正常工作。

http://Your-Domain.com

OR

http://Your-IP-addr

选中 Lighttpd 页面

Lighttpd 的默认文档根目录为 /var/www/lighttpd/主配置文件位于/etc/lighttpd/lighttpd.conf 下。

第 2 步:在 CentOS 7 中将 Mariadb 安装为 MySQL

8.接下来,使用以下命令安装Lighttpd 的 MySQL支持。

# yum -y install mariadb mariadb-server

9.安装完成后,使用以下命令启动、启用和验证 MariaDB 的状态。

# systemctl start mariadb.service

# systemctl enable mariadb.service

# systemctl status mariadb.service

10.最后,您需要通过发出以下命令来保护 MariaDB 安装。

# mysql_secure_installation

系统会提示您一些不同的问题,包括您的 MariaDB 安装以及如何保护它。您可以更改数据库根用户密码、禁用测试数据库、禁用匿名用户以及远程禁用根登录。

  输出

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): Enter OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorization. Set root password? [Y/n] y 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] y ... 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] y ... 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] y - 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] y ... 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!

11.尝试连接到 MySQL 服务器,并在终端上使用以下命令查看数据库服务器上的现有数据库。

# mysql -u root -p

输出

Enter password: 

Welcome to the MariaDB monitor. Commands end with ; or \g.

Your MariaDB connection id is 10

Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

+--------------------+

3 rows in set (0.00 sec)

MariaDB [(none)]>

第 3 步:在 CentOS 7 上使用 FastCGI 安装 PHP 和 PHP-FPM

12.要启用具有 FastCGI 支持的 PHP-FPM,首先,您需要使用以下命令安装 PHP 以及必要的扩展。

# yum -y install php php-mysqlnd php-pdo php-gd php-mbstring

13. 一旦PHP安装,现在启用PHP-FPM和S fastCGI支持的Lighttpd,要做到这一点,你需要安装这些包了。

# yum -y install php-fpm lighttpd-fastcgi

14.现在打开一个名为/etc/php-fpm.d/www.conf 的文件。

# vi /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默认情况下使用/var/run/php/php7.0-fpm.sock 插槽,您需要使用 PHP-FPM才能使用 TCP 连接。使线条外观如下:listen

;listen = /var/run/php/php7.0-fpm.sock

listen = 127.0.0.1:9000

15.现在启动 PHP-FPM服务,并确保使用以下命令使其在启动时自动启动。

# systemctl start php-fpm.service

# systemctl enable php-fpm.service

第 4 步:使用 Lighttpd 中的 FastCGI 启用 PHP 和 PHP-FPM

16.在这里,我们需要修改三个文件/etc/php.ini,/etc/lighttpd/模块.conf和/etc/lighttpd/conf.d/fastcgi.conf,以启用PHP对Lighttpd的支持。

打开第一个文件 /etc/php.ini.

# vi /etc/php.ini

取消注释以下行,说行cgi.fix_pathinfo=1。

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's

; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok

; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting

; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting

; of zero causes PHP to behave as before. Default is 1. You should fix your scripts

; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.

; http://php.net/cgi.fix-pathinfo

cgi.fix_pathinfo=1

然后打开第二个文件,称为/etc/lighttpd/模块.conf.

# vi /etc/lighttpd/modules.conf

取消注释以下行,说包括"conf.d/fastcgi.conf"。

##

## FastCGI (mod_fastcgi)

##

include "conf.d/fastcgi.conf"

接下来,打开第三个文件,称为 /etc/lighttpd/conf.d/fastcgi.conf。

# vi /etc/lighttpd/conf.d/fastcgi.conf

现在,在文件底部添加以下容器并保存它。

fastcgi.server += ( ".php" =>

((

"host" => "127.0.0.1",

"port" => "9000",

"broken-scriptfilename" => "enable"

))

)

重新启动Lighttpd 服务以反映更改并启用PHP支持。

# systemctl restart lighttpd

第 5 步:使用 Lighttpd 中的 FastCGI 支持测试 PHP 和 PHP-FPM

17.正如我们上面所述,Lighttpd的默认文档根目录为/var/www/lighttpd/。因此,在这里我们将创建一个phpinfo.php文件到这个目录。

# vi /var/www/lighttpd/info.php

向其添加以下行。此小代码段将显示有关 PHP安装及其版本的信息。

<?php

phpinfo();

?>

18.打开浏览器并导航到以下链接。

http://Your-Domain.com/info.php

OR

http://Your-IP-addr/info.php

在 CentOS 中检查 PHP 信息

你会看到PHP、PHP-FPM和MySQL的工作信息,以及许多其他已经启用的模块。

以上是 如何在 CentOS/RHEL 8/7 上使用 PHP 和 MariaDB 安装 Lighttpd 的全部内容, 来源链接: utcz.com/wiki/669653.html

回到顶部