如何在 Ubuntu 24.04 上安装 LOMP Stack(OpenLiteSpeed、MySQL 和 PHP)如何在 Ubuntu 24.04 上安装 LOMP Stack(OpenLiteSpeed、MySQL 和 PHP)如何在 Ubuntu 24.04 上安装 LOMP Stack(OpenLiteSpeed、MySQL 和 PHP)如何在 Ubuntu 24.04 上安装 LOMP Stack(OpenLiteSpeed、MySQL 和 PHP)
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Ubuntu 24.04 上安装 LOMP Stack(OpenLiteSpeed、MySQL 和 PHP)

本教程适用于这些操作系统版本

  • Ubuntu 24.04(高贵食蚁兽)
  • Ubuntu 22.04(果酱水母)
  • Ubuntu 20.04(焦窝)
  • Ubuntu 18.04(仿生海狸)

在此页面上

  1. 先决条件
  2. 第 1 步 - 配置防火墙
  3. 第 2 步 - 安装 OpenLiteSpeed

    1. 创建管理员密码
  4. 第 3 步 - 安装 MySQL
  5. 第 4 步 - 安装 PHP
  6. 第 5 步 - 配置 MySQL
  7. 第 6 步 - 配置 OpenLiteSpeed

    1. 将 HTTP 端口切换回 80
  8. 第 7 步 - 配置 PHP

    1. 重新启动 PHP
  9. 第 8 步 - 创建虚拟主机
  10. 第 9 步 - 安装 SSL
  11. 第 10 步 - 测试站点
  12. 结论

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

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

本教程将向您展示如何在 Ubuntu 24.04 上安装 OpenLiteSpeed 服务器。

先决条件

    运行 Ubuntu 24.04 的服务器。

    具有 sudo 权限的非 root 用户。

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

    确保一切都已更新。

    $ sudo apt update
    $ sudo apt upgrade
    

    您的系统需要的软件包很少。

    $ sudo apt install wget curl nano ufw software-properties-common dirmngr apt-transport-https gnupg2 ca-certificates lsb-release ubuntu-keyring unzip -y
    

    其中一些软件包可能已经安装在您的系统上。

第 1 步 - 配置防火墙

第一步是配置防火墙。 Debian 默认带有 ufw(简单防火墙)。

检查防火墙是否正在运行。

$ sudo ufw status

您将得到以下输出。

Status: inactive

允许 SSH 端口,以便防火墙在启用它时不会中断当前连接。

$ sudo ufw allow OpenSSH

还允许 HTTP 和 HTTPS 端口。

$ sudo ufw allow http
$ sudo ufw allow https

打开与 Openlitespeed 相关的端口。

$ sudo ufw allow 7080/tcp

启用防火墙

$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
Firewall is active and enabled on system startup

再次检查防火墙的状态。

$ sudo ufw status

您应该看到类似的输出。

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
80/tcp                     ALLOW       Anywhere
443                        ALLOW       Anywhere
7080/tcp                   ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)
7080/tcp (v6)              ALLOW       Anywhere (v6)

第 2 步 - 安装 OpenLiteSpeed

我们将通过从源代码编译来安装 OpenLiteSpeed。下载 OpenLiteSpeed 源代码文件。您可以从 OpenLiteSpeed 官方下载页面获取最新源代码文件的链接。 1.7.19 版本是当前可用的稳定版本。

$ wget https://openlitespeed.org/packages/openlitespeed-1.7.19.src.tgz

提取文件。

$ tar -zxf openlitespeed-*.tgz

切换到解压后的目录。

$ cd openlitespeed-1.7.19

构建服务器包。

$ sudo ./build.sh

您可能需要等待 5-10 分钟才能完成该过程。忽略在此过程中收到的任何警告。完成后您将收到以下输出。

...............
[100%] Linking CXX shared library modpagespeed.so
/usr/bin/ld: warning: 140.x25519-asm-x86_64.o.o: missing .note.GNU-stack section implies executable stack
/usr/bin/ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker
[100%] Built target modpagespeed
Start to pack files.
-e Building finished, please run ./install.sh for installation.
-e You may want to update the ols.conf to change the settings before installation.
-e Enjoy.

该过程完成后,打开文件 ols.conf 进行编辑。

$ sudo nano ols.conf

编辑文件,如下所示。

#If you want to change the default values, please update this file.
#

SERVERROOT=/usr/local/lsws
OPENLSWS_USER=nobody
OPENLSWS_GROUP=nobody
OPENLSWS_ADMIN=navjot
[email 
OPENLSWS_ADMINSSL=yes
OPENLSWS_ADMINPORT=7080
USE_LSPHP7=yes
DEFAULT_TMP_DIR=/tmp/lshttpd
PID_FILE=/tmp/lshttpd/lshttpd.pid
OPENLSWS_EXAMPLEPORT=8088

#You can set password here
#OPENLSWS_PASSWORD=

不要在此处添加您的密码。稍后我们将使用命令行设置密码。完成后,按 Ctrl + X 并在出现提示时输入 Y 来保存文件。

现在 OpenLiteSpeed 已构建完成,让我们安装它。

$ sudo ./install.sh

安装程序脚本为服务器安装并启用 lsws 服务。完成后您将收到以下输出。

Updating webcache manager, please waiting ...
Downloading latest shared code tar file...
Checking tar file md5...
Removing existing shared code directory...
Extracting downloaded shared code...
Removing local shared code tar file...
Updating lscmctl script...
Done!

-e Installation finished, Enjoy!

-e Your webAdmin password is kXjWTl5j, written to file /usr/local/lsws/adminpasswd.

启动 OpenLiteSpeed 服务器。

$ sudo systemctl start lsws

检查服务的状态。

$ sudo systemctl status lsws
? lshttpd.service - OpenLiteSpeed HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/lshttpd.service; enabled; preset: enabled)
     Active: active (running) since Sun 2024-06-02 12:58:44 UTC; 3s ago
    Process: 52583 ExecStart=/usr/local/lsws/bin/lswsctrl start (code=exited, status=0/SUCCESS)
   Main PID: 52604 (litespeed)
     CGroup: /system.slice/lshttpd.service
             ??52604 "openlitespeed (lshttpd - main)"
             ??52610 "openlitespeed (lscgid)"
             ??52623 "openlitespeed (lshttpd - #01)"
             ??52624 lsphp

Jun 02 12:58:42 lompserver systemd[1]: Starting lshttpd.service - OpenLiteSpeed HTTP Server...
Jun 02 12:58:42 lompserver lswsctrl[52583]: [OK] litespeed: pid=52604.
Jun 02 12:58:44 lompserver systemd[1]: Started lshttpd.service - OpenLiteSpeed HTTP Server.

检查安装的服务器版本。

$ /usr/local/lsws/bin/lshttpd -v
LiteSpeed/1.7.19 Open (BUILD built: Tue Apr 16 15:14:26 UTC 2024) 
        module versions:
        lsquic 3.3.2
        modgzip 1.1
        cache 1.66
        mod_security 1.4 (with libmodsecurity v3.0.12)

创建管理员密码

您可以使用安装过程中提供的管理员密码。但是,您应该通过重置来创建您自己的。运行密码重置脚本。

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

您将得到以下输出。选择您的用户名并设置一个强密码。

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

User name [admin]: navjot

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 的管理面板。首次登录时,您的浏览器会警告您的连接不是私密的。单击“高级”,然后单击“接受风险并继续”(对于 Firefox)或“继续(不安全)”(对于基于 Chromium 的浏览器)。您将不会再看到该警告。

您应该看到登录页面。

输入您之前设置的凭据,然后按登录按钮继续。

您将看到以下屏幕。

第 3 步 - 安装 MySQL

在继续安装 MySQL 之前,我们需要更新 LiteSpeed 存储库。通过安装程序添加的 Litespeed 存储库无法正常工作。

打开文件 /etc/apt/sources.list.d/lst_debian_repo.list 进行编辑。

$ sudo nano /etc/apt/sources.list.d/lst_debian_repo.list

通过将 Ubuntu 24.04 版本名称 (noble) 添加到存储库 URL 来更改文件内容。

deb http://rpms.litespeedtech.com/debian/ noble main

完成后,按 Ctrl + X 并在出现提示时输入 Y 来保存文件。

安装 MySQL 服务器。

$ sudo apt install mysql-server

MySQL 服务在安装后自动启动并运行。

检查服务的状态。

$ sudo systemctl status mysql

您将得到以下输出。

? mysql.service - MySQL Community Server
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled)
     Active: active (running) since Sun 2024-06-02 13:42:12 UTC; 8min ago
    Process: 57889 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 57898 (mysqld)
     Status: "Server is operational"
      Tasks: 37 (limit: 2263)
     Memory: 370.6M (peak: 386.9M)
        CPU: 6.762s
     CGroup: /system.slice/mysql.service
             ??57898 /usr/sbin/mysqld

Jun 02 13:42:11 lompserver systemd[1]: Starting mysql.service - MySQL Community Server...

运行 MySQL 安全脚本。

$ sudo mysql_secure_installation

系统会要求您安装验证密码组件。按 Y 继续。

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

接下来,系统会要求您选择密码的强度。选择“强”2 并继续。

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

MySQL 安装不会要求您设置 root 密码,因为默认身份验证类型是 auth_socket,这取决于您的 Linux 系统身份验证。不过您可以稍后更改它。

Skipping password set for root as authentication with auth_socket is used by default.
If you would like to use password authentication instead, this can be done with the "ALTER_USER" command.
See https://dev.mysql.com/doc/refman/8.0/en/alter-user.html#alter-user-password-management for more information.

接下来,您将被问到某些问题以提高 MySQL 的安全性。键入Y 以删除匿名用户、禁止远程 root 登录、删除测试数据库并重新加载权限表。

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!

您可以通过在命令行中输入 sudo mysql 来进入 MySQL shell。

第 4 步 - 安装 PHP

由于我们从源代码构建了包,因此它编译并构建了旧版本的 PHP,不建议使用。您可以通过以下命令检查它。

$ /usr/local/lsws/fcgi-bin/lsphp -v
PHP 5.6.40 (litespeed) (built: May 10 2023 23:03:31)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

因此,我们需要构建并安装最新版本的 PHP。但是,在继续之前,我们需要安装构建工具。

$ sudo apt install build-essential autoconf libtool bison re2c pkg-config

下一步是安装 PHP 构建过程所需的包。

$ sudo apt install libssl-dev libsqlite3-dev zlib1g-dev libcurl4-openssl-dev libonig-dev libzip-dev libmemcached-dev libreadline-dev libgmp-dev libpng-dev libjpeg-dev libwebp-dev libxpm-dev libicu-dev libfreetype6-dev libxslt-dev libldb-dev libtidy-dev libvips-dev libsodium-dev libavif-dev libldap2-dev libxml2-dev libkrb5-dev libc-client2007e-dev libpq-dev libargon2-1 libargon2-dev libbz2-dev libffi-dev libc-client-dev libpspell-dev flex libgmp3-dev libmcrypt-dev libmhash-dev freetds-dev libmysqlclient-dev libncurses5-dev libpcre3-dev libaspell-dev librecode-dev libsnmp-dev

接下来,下载 PHP 源代码。我们将下载 PHP 8.3.7 版本,这是撰写本文时可用的最新版本。

$ cd ~
$ wget https://www.php.net/distributions/php-8.3.7.tar.gz

提取文件。

$ tar -xzf php-8.3.7.tar.gz

切换到下载的目录。

$ cd php-8.3.7

接下来,使用以下选项运行配置脚本。 --enable-litespeed 选项至关重要。

$ sudo ./configure --prefix=/usr/local/lsws/lsphp83 --enable-bcmath --enable-calendar --enable-exif --enable-ftp --enable-gd --enable-intl --enable-mbregex --enable-mbstring --enable-mysqlnd --enable-opcache --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --with-avif --with-curl --with-ffi --with-freetype --with-gettext --with-gmp --with-imap --with-imap-ssl --with-jpeg --with-kerberos --with-libxml --with-ldap  --with-mysqli --with-mysql-sock=/run/mysqld/mysqld.sock --with-openssl --with-password-argon2 --with-pdo-mysql=mysqlnd --with-pdo-pgsql=/usr/bin/pg_config --with-pear --with-pspell --with-readline --with-sodium --with-tidy --with-webp --with-xpm --with-xsl --with-zip --with-zlib --enable-litespeed

脚本完成后,您应该得到以下输出。

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

编译源码。

$ sudo make -j $(nproc)

完成后您将收到类似的输出。

Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorytreeiterator.inc
phar.inc
invertedregexiterator.inc
directorygraphiterator.inc
pharcommand.inc
clicommand.inc

Build complete.
Don't forget to run 'make test'.

完成后,运行以下命令来尝试检查版本。

$ ./sapi/litespeed/php -v
PHP 8.3.7 (litespeed) (built: Jun  3 2024 05:28:43)
Copyright (c) The PHP Group
Zend Engine v4.3.7, Copyright (c) Zend Technologies

安装 PHP。

$ sudo make install

您将得到以下输出。

Installing shared extensions:     /usr/local/lsws/lsphp83/lib/php/extensions/no-debug-non-zts-20230831/
Installing PHP CLI binary:        /usr/local/lsws/lsphp83/bin/
Installing PHP CLI man page:      /usr/local/lsws/lsphp83/php/man/man1/
Installing PHP LiteSpeed binary:  /usr/local/lsws/lsphp83/bin/
Installing phpdbg binary:         /usr/local/lsws/lsphp83/bin/
Installing phpdbg man page:       /usr/local/lsws/lsphp83/php/man/man1/
Installing PHP CGI binary:        /usr/local/lsws/lsphp83/bin/
Installing PHP CGI man page:      /usr/local/lsws/lsphp83/php/man/man1/
Installing build environment:     /usr/local/lsws/lsphp83/lib/php/build/
Installing header files:          /usr/local/lsws/lsphp83/include/php/
Installing helper programs:       /usr/local/lsws/lsphp83/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/lsws/lsphp83/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/lsws/lsphp83/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.14
[PEAR] Console_Getopt - installed: 1.4.3
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.5
warning: pear/PEAR dependency package "pear/Archive_Tar" installed version 1.4.14 is not the recommended version 1.4.4
[PEAR] PEAR           - installed: 1.10.15
Wrote PEAR system config file at: /usr/local/lsws/lsphp83/etc/pear.conf
You may want to add: /usr/local/lsws/lsphp83/lib/php to your php.ini include_path
Installing PDO headers:           /usr/local/lsws/lsphp83/include/php/ext/pdo/

验证 PHP 安装。 /usr/local/lsws/lsphp83/bin 目录中有两个 PHP 二进制文件。一种是普通的php,即命令行版本,另一种是Litespeed 版本lsphp。第二个是我们将要使用的。

$ /usr/local/lsws/lsphp83/bin/lsphp -v
PHP 8.3.7 (litespeed) (built: Jun  3 2024 05:28:43)
Copyright (c) The PHP Group
Zend Engine v4.3.7, Copyright (c) Zend Technologies

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

$ /usr/local/lsws/lsphp83/bin/php --modules
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
imap
intl
json
ldap
libxml
mbstring
mysqli
mysqlnd
openssl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
Phar
posix
pspell
random
readline
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
sqlite3
standard
sysvsem
sysvshm
tidy
tokenizer
xml
xmlreader
xmlwriter
xsl
zip
zlib

[Zend Modules]

将 php.ini-product 从安装文件夹复制到 /usr/local/lsws/lsphp83/lib 文件夹。

$ sudo cp php.ini-production /usr/local/lsws/lsphp83/lib/php.ini

稍后我们将配置 OpenLiteSpeed 以与 PHP 配合使用。

打开php.ini进行编辑。

$ sudo nano /usr/local/lsws/lsphp83/lib/php.ini

找到变量 include_path 并更改其值,如下所示。

$ ;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
include_path = "/usr/local/lsws/lsphp83/lib/php"

完成后,按 Ctrl + X 并在出现提示时输入 Y 来保存文件。

第 5 步 - 配置 MySQL

登录 MySQL shell。

$ sudo mysql

创建测试数据库。将 testdb 替换为您选择的适当的数据库名称。

mysql> CREATE DATABASE testdb;

创建一个测试用户。将 testuser 替换为适当的用户名。将 Your_Password123 替换为强密码。

mysql> CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'Your_Password123';

向用户授予数据库的所有权限。

mysql> GRANT ALL PRIVILEGES ON testdb.* TO 'testuser'@'localhost';

刷新用户权限。

mysql> FLUSH PRIVILEGES;

退出 MySQL shell。

mysql> exit

第 6 步 - 配置 OpenLiteSpeed

将 HTTP 端口切换回 80

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

访问左侧的监听器部分。您将看到端口 8080 的默认侦听器。

单击查看按钮查看详细配置。在下一页的监听器默认>常规页面下,单击编辑图标并将端口从8080更改为80.

单击“保存”并通过单击“正常重启”按钮重新启动服务器。

在浏览器中打开 URL http://,您应该会看到以下页面。

第 7 步 - 配置 PHP

在此步骤中,我们需要将 PHP 8.3 的副本与服务器关联。

单击左侧的服务器配置部分,然后单击外部应用程序选项卡。您将看到一个现有的 PHP LiteSpeed 应用程序。我们将对它进行一些编辑。

单击编辑按钮编辑 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: lsphp83/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

完成后单击“保存”。

现在我们已经创建了自己的 PHP 8.3 应用程序,我们必须告诉服务器开始使用它。由于我们编辑了默认列表,因此它已经配置完毕。单击正常重启按钮重新启动服务器。

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

重新启动 PHP

在 OpenLiteSpeed 上,如果您编辑 php.ini 或安装新的 PHP 模块,重新启动服务器将不会显示更改。您需要为此重新启动 PHP 进程。首先,您需要找到 lsphp 进程的进程 ID。

$ ps aux | grep lsphp
nobody    120093  0.0  0.8 123772 32920 ?        S    06:35   0:00 lsphp
nobody    120111  0.0  0.4 123772 18980 ?        Ss   06:38   0:00 lsphp
navjot    120139  0.0  0.0   6544  2304 pts/0    S+   06:44   0:00 grep --color=auto lsphp

手动终止 lsphp 进程。

$ sudo kill -9 120093
$ sudo kill -9 120111

重新启动服务器。

$ sudo systemctl restart lsws

第 8 步 - 创建虚拟主机

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

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

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

接下来,打开管理控制台,访问左侧的虚拟主机部分,然后点击“添加”按钮。

填写指定的值

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

完成后点击保存按钮。您将收到以下错误,因为配置文件目前不存在。单击链接以创建配置文件。

再次单击保存按钮完成虚拟主机的创建。

创建虚拟主机后,转到虚拟主机 -> 选择虚拟主机(example.com) -> 常规并根据给定修改配置。

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

完成后点击保存按钮。接下来,我们需要设置索引文件。单击常规部分下方索引文件的编辑按钮。设置以下选项。

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

完成后单击“保存”。接下来,我们需要选择日志文件。转到日志部分,单击虚拟主机日志的编辑,然后填写以下值。保持其他设置不变。

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

如果您使用的是开发计算机,则可以将日志级别选择为DEBUG。

单击“保存”,然后单击访问日志部分中的加号以添加新条目。填写以下值。

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
Compress Archive: Not Set
Bytes log: Not Set

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

Allowed List: *
Denied List: Not set

完成后点击保存。接下来,我们需要设置脚本处理程序定义。单击加号 (+) 添加新定义。设置以下值。

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

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

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

完成后点击保存。最后,我们需要设置监听器。转到侦听器部分,然后单击默认侦听器旁边的查看按钮。然后,单击虚拟主机映射旁边的“添加”按钮添加新映射并设置以下值。

Virtual Host: example.com
Domains: example.com

完成后点击保存。现在,单击正常重启按钮以应用上述所有更改并重新启动服务器。

第 9 步 - 安装 SSL

在 OpenLiteSpeed 中设置 SSL 需要我们设置两个证书。整个服务器和 Let's Encrypt 站点特定服务器的自签名证书。

管理面板已预装自签名证书,可在 /usr/local/lsws/admin/conf 目录中找到。

让我们首先为整个服务器创建自签名证书。

$ cd ~
$ 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) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:example.com
Email Address []:[email 

您可以按 Enter 键浏览所有字段并将其留空。填写您的通用名域名和您的电子邮件地址。

创建自签名证书的目录。

$ sudo mkdir /usr/local/lsws/certs

将证书复制到 /usr/local/lsws/certs 目录。

$ sudo mv *.pem /usr/local/lsws/certs

我们需要安装 Certbot 来生成 Let's Encrypt 提供的免费 SSL 证书。

您可以使用 Debian 的存储库安装 Certbot,也可以使用 Snapd 工具获取最新版本。我们将使用 Snapd 版本。 Ubuntu 24.04 预装了 Snapd。

运行以下命令以确保您的 Snapd 版本是最新的。

$ sudo snap install core
$ sudo snap refresh core

发出以下命令来安装 Certbot。

$ sudo snap install --classic certbot

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

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

验证安装。

$ certbot --version
certbot 2.10.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  -d example.com

生成 Diffie-Hellman 组证书。

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

检查 Certbot 续订调度程序服务。

$ sudo systemctl list-timers

您会发现 snap.certbot.renew.service 是计划运行的服务之一。

NEXT                           LEFT LAST                              PASSED UNIT                      ACTIVATES                       
Mon 2024-06-03 07:20:00 UTC    5min Mon 2024-06-03 07:10:02 UTC 4min 11s ago sysstat-collect.timer     sysstat-collect.service
Mon 2024-06-03 08:29:00 UTC    1h 14min -                                  - snap.certbot.renew.timer  snap.certbot.renew.service
Mon 2024-06-03 08:50:32 UTC    1h 36min Mon 2024-06-03 07:04:04 UTC    10min ago fwupd-refresh.timer   fwupd-refresh.service

要检查 SSL 续订是否正常工作,请试运行该过程。

$ sudo certbot renew --dry-run

如果没有看到任何错误,则一切都已准备就绪。您的证书将自动更新。

现在打开管理控制台,转到侦听器 >> 添加新侦听器,然后添加以下值。

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

完成后点击保存。接下来,通过单击 SSL,单击添加按钮,然后填写以下值,转到 SSL 侦听器下的虚拟主机映射部分。

Virtual Host: example.com
Domains: example.com

完成后点击保存。接下来,转到侦听器>> SSL侦听器>> SSL选项卡>> SSL私钥和证书(编辑按钮)并为我们之前创建的自签名证书填写以下值。

Private Key File: $SERVER_ROOT/certs/key.pem
Certificate File: $SERVER_ROOT/certs/cert.pem
Chained Certificate: Yes

完成后点击保存。接下来,转到侦听器 >> SSL 侦听器 >> SSL 选项卡 >> SSL 协议(编辑按钮),然后填写 SSL 协议和密码详细信息的以下值。

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

完成后点击保存。接下来,转到虚拟主机 >> example.com >> SSL 选项卡 >> 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

完成后点击保存。接下来,转到虚拟主机 >> example.com >> SSL 选项卡 >> OCSP Stapling(编辑按钮)并填写以下值以启用 OCSP Stapling。

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

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

ALPN: Enable HTTP/2 and HTTP/3
Enable HTTP3/QUIC: Yes

我们不需要启用其他选项,因为它们默认处于打开状态。

完成后点击保存。

单击“Graceful restart”按钮重新启动服务器。

第 10 步 - 测试站点

在 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 = "Your_Password123";

    // 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>

按 Ctrl + X 并在出现提示时输入 Y 来保存文件。在浏览器中打开 URL https://example.com,您应该会看到以下页面。

测试站点功能齐全。您可以开始使用服务器来为动态 PHP 网站和应用程序提供服务。

结论

关于在 Ubuntu 24.04 服务器上安装 LOMP Stack(OpenLiteSpeed、MySQL 和 PHP)的教程到此结束。如果您有任何疑问,请在下面的评论中发表。

©2015-2025 艾丽卡 support@alaica.com