本页内容

  • 先决条件
  • 第 1 步 - 配置防火墙
  • 第 2 步 - 安装 OpenLiteSpeed 创建管理员密码
  • 第 3 步 - 安装 PHP
  • 第 4 步 - 安装 MySQL
  • 第 5 步 - 配置 OpenLiteSpeed 将 HTTP 端口切换回 80
  • 第 6 步 - 配置 PHP
  • 第 7 步 - 创建虚拟主机
  • 第 8 步 - 安装 SSL
  • 第 9 步 - 测试站点
  • 结语
  • 创建管理员密码
  • 将 HTTP 端口切换回 80

OpenLiteSpeed 是由 LiteSpeed Technologies 开发的 LiteSpeed 服务器的一个轻量级开源版本。它支持 Apache Rewrite 规则、HTTP/2 和 HTTP/3,以及 TLS v1.3 和 QUIC 协议。它配备了基于 WebGUI 的管理面板,使其有别于其他服务器并且更易于管理。

LOMP 栈是 Linux、OpenLiteSpeed、MySQL/MariaDB 和 PHP 的缩写。Litespeed 服务器以其速度著称,尤其是通过 LiteSpeed 服务器应用程序编程接口(LSAPI)集成的 PHP。LiteSpeed PHP(LSPHP)解释器通过 LSAPI 提供动态 PHP 页面。

本教程将逐步向您展示如何在 Rocky Linux 9 机器上安装 LOMP 服务器。

先决条件

  • 运行 Rocky Linux 9 的服务器。
  • 具有 sudo 权限的非 root 用户。
  • 指向该服务器的完全限定域名(FQDN),如 example.com。
  • SELinux 无需禁用或配置即可与 OpenLiteSpeed 配合工作。
  • 确保一切已更新。$ sudo dnf update
  • 系统需要的一些软件包。$ sudo dnf install wget curl nano unzip yum-utils -y 其中部分软件包可能已在您的系统上安装。

运行 Rocky Linux 9 的服务器。

具有 sudo 权限的非 root 用户。

指向该服务器的完全限定域名(FQDN),如 example.com。

SELinux 无需禁用或配置即可与 OpenLiteSpeed 配合工作。

确保一切已更新。

$ sudo dnf update

系统需要的一些软件包。

$ sudo dnf install wget curl nano unzip yum-utils -y

其中部分软件包可能已在您的系统上安装。

第 1 步 - 配置防火墙

第一步是配置防火墙。Rocky Linux 使用 Firewalld 防火墙。检查防火墙的状态。

$ sudo firewall-cmd --state
running

防火墙使用不同的区域,公共区域(public zone)是我们将使用的默认区域。列出防火墙上所有已激活的服务和端口。

$ sudo firewall-cmd --permanent --list-services

它应显示如下输出。

cockpit dhcpv6-client ssh

OpenLiteSpeed 的 7080 端口用于其管理面板。

$ sudo firewall-cmd --permanent --add-port=7080/tcp

我们还需要 HTTP 和 HTTPS 端口才能正常工作。开放这些端口。

$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --add-service=https

重新加载防火墙以应用更改。

$ sudo firewall-cmd --reload

再次列出所有服务。

$ sudo firewall-cmd --permanent --list-services

您应得到如下输出。

cockpit dhcpv6-client http https ssh

第 2 步 - 安装 OpenLiteSpeed

下载 OpenLiteSpeed 二进制文件。您可以从 OpenLiteSpeed 官方下载页面获取最新二进制文件的链接。

$ wget https://openlitespeed.org/packages/openlitespeed-1.7.16.tgz

解压该文件。

$ tar -zxf openlitespeed-*.tgz

切换到解压后的目录。

$ cd openlitespeed

运行安装程序。

$ sudo ./install.sh

等待一段时间让安装程序完成。

在 Rocky Linux 9 机器上,OpenLiteSpeed 存在一些已知问题,您可能会看到一些关于缺少 PHP 软件包的错误。您暂时可以忽略它们,因为服务器仍可通过各种变通方法运行。

安装脚本会安装并启用 lshttpd systemd 服务。

启动 OpenLiteSpeed 服务器。

$ sudo systemctl start lshttpd

检查已安装服务器的版本。

$ /usr/local/lsws/bin/lshttpd -v
LiteSpeed/1.7.16 Open (BUILD built: Thu Nov 17 16:18:46 UTC 2022) 
        module versions:
        lsquic 3.1.1
        modgzip 1.1
        cache 1.64
        mod_security 1.4

创建管理员密码

运行密码重置脚本。

$ sudo /usr/local/lsws/admin/misc/admpass.sh

您将得到如下输出。输入 admin 作为用户名并设置一个强密码。

Please specify the user name of administrator.
This is the user name required to login the administration Web interface.

User name [admin]: admin

Please specify the administrator's password.
This is the password required to login the administration Web interface.

Password: 
Retype password: 
Administrator's username/password is updated successfully!

您现在可以使用新的管理员密码。

打开 http://:7080 以访问 OpenLiteSpeed 的管理面板。首次登录时,您的浏览器会警告连接并非私密。点击 Advanced(高级),然后点击“Accept the risk and Continue”(接受风险并继续)(Firefox 浏览器)或“Proceed to (unsafe)”(继续访问 (不安全))(基于 Chromium 的浏览器)。您之后不会再看到该警告。

您应看到登录页面。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

输入之前设置的用户名 admin 和密码,然后按 Login(登录)按钮继续。

您将看到如下界面。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

第 3 步 - 安装 PHP

OpenLiteSpeed 安装程序默认通常会安装 PHP 7.4。但在 Rocky Linux 9 上,它不会被自动安装。此外,我们将安装较新版本的 PHP。在此之前,我们需要安装 LiteSpeed 仓库。

通过运行以下命令安装 OpenLiteSpeed 仓库。

$ sudo rpm -Uvh http://rpms.litespeedtech.com/centos/litespeed-repo-1.3-1.el8.noarch.rpm

您可以从 OpenLiteSpeed 仓库页面获取 RPM 文件的最新版本。

安装 PHP 8.2。

$ sudo dnf install lsphp82 lsphp82-mysqlnd lsphp82-process lsphp82-bcmath lsphp82-pdo lsphp82-common lsphp82-xml lsphp82-opcache lsphp82-soap

lsphp-gd 和 lsphp-mbstring 软件包在仓库中仍然缺失。因此如果您需要它们,需要等待它们正式发布一段时间。

验证 PHP 安装。

$ /usr/local/lsws/lsphp82/bin/php -v
PHP 8.2.1 (cli) (built: Jan  3 2023 18:40:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.1, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.1, Copyright (c), by Zend Technologies

您可以查看已启用的 PHP 模块列表。

$ /usr/local/lsws/lsphp82/bin/php --modules
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gettext
hash
iconv
json
libxml
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
random
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

我们稍后将配置 OpenLiteSpeed 以配合 PHP 工作。

第 4 步 - 安装 MySQL

安装 MySQL 服务器。

$ sudo dnf install mysql-server

启用并启动 MySQL 服务器。

$ sudo systemctl enable mysqld --now

检查服务的状态。

$ sudo systemctl status mysqld

您将得到如下输出。

? mysqld.service - MySQL 8.0 database server
     Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
     Active: active (running) since Fri 2023-02-17 07:31:00 UTC; 2s ago
    Process: 14933 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
    Process: 14955 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
   Main PID: 15054 (mysqld)
     Status: "Server is operational"
      Tasks: 39 (limit: 5873)
     Memory: 427.1M
        CPU: 4.079s
     CGroup: /system.slice/mysqld.service
             ??15054 /usr/libexec/mysqld --basedir=/usr

Feb 17 07:30:51 nspeaks.xyz systemd[1]: Starting MySQL 8.0 database server...
Feb 17 07:30:51 nspeaks.xyz mysql-prepare-db-dir[14955]: Initializing MySQL database
Feb 17 07:31:00 nspeaks.xyz systemd[1]: Started MySQL 8.0 database server.

运行 MySQL 安全脚本。

$ sudo mysql_secure_installation

您将收到若干提示。第一个提示会询问是否要安装 Validate Password Plugin(验证密码插件)。按 Y 安装该插件。选择 2 作为其安全级别,这将要求您的密码至少 8 个字符长,并包含大写、小写、数字和特殊字符的组合。

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2

接下来,系统会要求您创建一个强 root 密码。请确保您的密码符合 Validate 插件的要求。

Please set the password for root here.

New password: 

Re-enter new password:

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y

接下来,系统会提出若干与提升数据库安全性相关的提示。在每个提示中都按 Y。

By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.

All done!

登录到 MySQL shell。

$ mysql -u root -p

在提示时输入您的 root 密码。

创建一个测试数据库和具有访问权限的用户。请将 testdb 和 testuser 替换为您环境中合适的名称。将 password 替换为一个强密码。

mysql> CREATE DATABASE testdb;
mysql> CREATE USER 'testuser' IDENTIFIED BY 'Your_Password123';
mysql> GRANT ALL PRIVILEGES ON testdb.* TO 'testuser';
mysql> FLUSH PRIVILEGES;

退出 MySQL shell。

mysql> exit

第 5 步 - 配置 OpenLiteSpeed

将 HTTP 端口切换回 80

让我们将默认 HTTP 端口更改为 80。使用您刚创建的凭据,登录位于 http://:7080 的管理面板。

从左侧访问 Listeners(监听器)部分。您将看到端口为 8080 的默认监听器。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

点击 View(查看)按钮以查看详细配置。在下一页中,进入 Listener Default > General Page(默认监听器 > 常规页面),点击 Edit(编辑)图标,将端口从 8080 更改为 80。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

点击 Save(保存),然后点击 Graceful restart(平滑重启)按钮重启服务器。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

第 6 步 - 配置 PHP

在此步骤中,我们需要将我们安装的 PHP 8.2 与服务器关联起来。

点击左侧的 Server Configuration(服务器配置)部分,然后点击 External App(外部应用)选项卡。您将看到已有的用于 PHP 的 LiteSpeed App。我们将对其进行一些编辑。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

点击 Edit(编辑)按钮以编辑 PHP 应用。

接下来,按照如下所示配置。将所有其他字段留空。

Name: lsphp
Address: uds://tmp/lshttpd/lsphp.sock
Max Connections: 35
Environment: PHP_LSAPI_MAX_REQUESTS=500
             PHP_LSAPI_CHILDREN=35
             LSAPI_AVOID_FORK=200M
Initial Request Timeout (secs): 60
Retry Timeout : 0
Persistent Connection: Yes
Response Buffering: no
Start By Server: Yes(Through CGI Daemon)
Command: lsphp82/bin/lsphp
Back Log: 100
Instances: 1
Priority: 0
Memory Soft Limit (bytes): 2047M
Memory Hard Limit (bytes): 2047M
Process Soft Limit: 1400
Process Hard Limit: 1500

完成后点击 Save(保存)。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

既然我们已经创建了自己的 PHP 8.2 应用,就必须告知服务器开始使用它。由于我们编辑了默认列表,它已经配置好了。点击 Graceful restart(平滑重启)按钮重启服务器。

要测试您的 PHP 是否已正确切换,请在浏览器中访问 http:///phpinfo.php。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

第 7 步 - 创建虚拟主机

首先,我们需要为虚拟主机创建目录。

$ sudo mkdir /usr/local/lsws/example.com/{html,logs} -p

html 目录将存放公开文件,logs 目录将包含服务器日志。

接下来,打开 Admin Console(管理控制台),从左侧访问 Virtual Hosts(虚拟主机)部分,然后点击 Add(添加)按钮。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

按指定填写各项值

Virtual Host Name: example.com
Virtual Host Root: $SERVER_ROOT/example.com/
Config File: $SERVER_ROOT/conf/vhosts/$VH_NAME/vhconf.conf
Follow Symbolic Link: Yes
Enable Scripts/ExtApps: Yes
Restrained: Yes
External App Set UID Mode: Server UID

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)按钮。您会看到如下错误,因为配置文件目前尚不存在。点击链接以创建配置文件。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

再次点击 Save(保存)按钮以完成虚拟主机的创建。

虚拟主机创建完成后,进入 Virtual Hosts -> Choose Virtual Host(选择虚拟主机,example.com)-> General(常规),并按给定内容修改配置。

Document Root: $VH_ROOT/html/
Domain Name: example.com
Enable GZIP Compression: Yes
Enable Brotli Compression: Yes

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)按钮。接下来,我们需要设置索引文件。点击 General(常规)部分下方 Index files(索引文件)对应的编辑按钮。设置以下选项。

Use Server Index Files: No
Index files: index.php, index.html, index.htm
Auto Index: No

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。接下来,我们需要选择日志文件。进入 Log(日志)部分,点击 Virtual Host Log(虚拟主机日志)对应的 Edit(编辑),并填写以下值。其他设置保持不变。

Use Server’s Log: Yes
File Name: $VH_ROOT/logs/error.log
Log Level: ERROR
Rolling Size (bytes): 10M
Keep Days: 30
Compress Archive: Not Set

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

如果您使用的是生产/开发机器,可以将 Log Level(日志级别)选择为 DEBUG。

点击 Save(保存),然后点击 Access Log(访问日志)部分的加号以添加新条目。填写以下值。

Log Control: Own Log File
File Name: $VH_ROOT/logs/access.log
Piped Logger: Not Set
Log Format: Not Set
Log Headers: Not Set
Rolling Size (bytes): 10M
Keep Days: 30
Bytes log: Not Set
Compress Archive: Not Set

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。接下来,我们需要在 Security(安全)部分下配置 Access Control(访问控制)。设置以下值。

Allowed List: *
Denied List: Not set

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。接下来,我们需要设置 Script Handler Definition(脚本处理器定义)。点击加号(+)添加新的定义。设置以下值。

Suffixes: php
Handler Type: LiteSpeed SAPI
Handler Name: [Server Level]: lsphp

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。接下来,我们需要在 Rewrite(重写)部分下设置 Rewrite Control(重写控制)。设置以下值。

Enable Rewrite: Yes
Auto Load from .htaccess: Yes
Log Level: Not Set

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。最后,我们需要设置 Listeners(监听器)。进入 Listeners(监听器)部分,点击 Default Listener(默认监听器)对应的 View(查看)按钮。然后,点击 Virtual Host Mappings(虚拟主机映射)对应的 Add(添加)按钮以添加新的映射,并设置以下值。

Virtual Host: example.com
Domains: example.com

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。现在,点击 Graceful restart(平滑重启)按钮以应用上述所有更改并重启服务器。

第 8 步 - 安装 SSL

在 OpenLiteSpeed 中设置 SSL 需要我们配置两份证书:一份用于整个服务器的自签名证书,以及一份 Let's Encrypt 站点专用证书。

让我们先创建自签名证书。

$ openssl req -x509 -days 365 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes

您将得到类似的输出。

-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:example.com
Email Address []:
[email protected]

您可以一路按回车键将各字段留空。在 Common name(通用名称)处填写您的域名,并填写您的电子邮件地址。

证书现在存储在 /home/user 目录中。我们稍后需要这些信息。

要使用 Let's Encrypt,我们需要安装 Certbot 工具。我们将使用 Snapd 软件包安装器来完成。由于 Rocky Linux 未附带它,请安装 Snapd 安装器。它需要 EPEL 仓库才能工作。

$ sudo dnf install -y epel-release

安装 Snapd。

$ sudo dnf install -y snapd

启用并启动 Snap 服务。

$ sudo systemctl enable snapd --now

安装 Snap core 软件包,并确保您的 Snapd 版本是最新的。

$ sudo snap install core && sudo snap refresh core

创建 Snapd 工作所需的必要链接。

$ sudo ln -s /var/lib/snapd/snap /snap
$ echo 'export PATH=$PATH:/var/lib/snapd/snap/bin' | sudo tee -a /etc/profile.d/snapd.sh

执行以下命令以安装 Certbot。

$ sudo snap install --classic certbot

使用以下命令,通过创建指向 /usr/bin 目录的符号链接,确保 Certbot 命令可以运行。

$ sudo ln -s /snap/bin/certbot /usr/bin/certbot

验证安装。

$ certbot --version
certbot 2.3.0

运行以下命令以生成 SSL 证书。

获取 SSL 证书。webroot(网站根)目录设置为之前配置的公开 HTML 目录。

$ sudo certbot certonly --webroot -w /usr/local/lsws/example.com/html/ --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m 
[email protected]
 -d example.com

生成 Diffie-Hellman 组证书。

$ sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096

要检查 SSL 续期是否正常工作,请对该过程进行一次试运行(dry run)。

$ sudo certbot renew --dry-run

如果没有看到错误,说明一切就绪。您的证书将自动续期。

现在打开 Admin Console(管理控制台),进入 Listeners(监听器)>> Add New Listener(添加新监听器),并添加以下值。

Listener Name: SSL
IP Address: ANY
Port: 443
Secure: Yes

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。接下来,点击 SSL,再点击 Add(添加)按钮,进入 SSL Listener(SSL 监听器)下的 Virtual Host Mappings(虚拟主机映射)部分,并填写以下值。

Virtual Host: example.com
Domains: example.com

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。接下来,进入 Listeners(监听器)>> SSL Listener(SSL 监听器)>> SSL Tab(SSL 选项卡)>> SSL Private Key & Certificate(SSL 私钥与证书,编辑按钮),并为我们之前创建的自签名证书填写以下值。

Private Key File: /home/user/key.pem
Certificate File: /home/user/cert.pem
Chained Certificate: Yes

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。接下来,进入 Listeners(监听器)>> SSL Listener(SSL 监听器)>> SSL Tab(SSL 选项卡)>> SSL Protocol(SSL 协议,编辑按钮),并为 SSL 协议和密码套件详情填写以下值。

Protocol Version: TLS v1.2 TLS v1.3
Ciphers: ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384
Enable ECDH Key Exchange: Yes
Enable DH Key Exchange: Yes
DH Parameter: /etc/ssl/certs/dhparam.pem

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。接下来,进入 Virtual Hosts(虚拟主机)>> example.com >> SSL Tab(SSL 选项卡)>> SSL Private Key & Certificate(SSL 私钥与证书,编辑按钮),并使用 Let's Encrypt 证书填写以下值。

Private Key File: /etc/letsencrypt/live/example.com/privkey.pem
Certificate File: /etc/letsencrypt/live/example.com/fullchain.pem
Chained Certificate: Yes

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。接下来,进入 Virtual Hosts(虚拟主机)>> example.com >> SSL Tab(SSL 选项卡)>> OCSP Stapling(OCSP 装订,编辑按钮),并填写以下值以启用 OCSP Stapling。

Enable OCSP Stapling: Yes
OCSP Response Max Age(Secs): 300
OCSP Responder: http://r3.o.lencr.org

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。接下来,进入 Virtual Hosts(虚拟主机)>> example.com >> SSL Tab(SSL 选项卡)>> Security(安全,编辑按钮),并填写以下值以启用 HTTP3/QUIC 协议。

Enable HTTP3/QUIC: Yes

我们不需要启用其他选项,因为它们默认已开启。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

完成后点击 Save(保存)。

点击 Graceful restart(平滑重启)按钮重启服务器。

第 9 步 - 测试站点

在您的 html 目录中创建一个测试文件。

$ sudo nano /usr/local/lsws/example.com/html/index.php

将以下代码粘贴到 Nano 编辑器中。

<html>
<head>
    <h2>OpenLiteSpeed Server Install Test</h2>
</head>
    <body>
    <?php echo '<p>Hello,</p>';

    // Define PHP variables for the MySQL connection.
    $servername = "localhost";
    $username = "testuser";
    $password = "password";

    // Create a MySQL connection.
    $conn = mysqli_connect($servername, $username, $password);

    // Report if the connection fails or is successful.
    if (!$conn) {
        exit('<p>Your connection has failed.<p>' .  mysqli_connect_error());
    }
    echo '<p>You have connected successfully.</p>';
    ?>
</body>
</html>

在浏览器中打开 URL https://example.com,您应看到如下页面。

在 Rocky Linux 9 上安装 LOMP 栈 OpenLiteSpeed MySQL PHP

测试站点已完全正常运行。您可以开始使用该服务器来提供动态的 PHP 网站和应用程序。

结语

至此,关于在 Rocky Linux 9 服务器上安装 LOMP 栈(OpenLiteSpeed、MySQL 和 PHP)的教程就结束了。如果您有任何问题,请在下方评论中留言。