如何使用 Apache 安装 Joomla 并在 Ubuntu 22.04 上加密 SSL
本教程适用于这些操作系统版本
- Ubuntu 22.04(Jammy Jellyfish)
- Ubuntu 14.04 LTS(Trusty Tahr)
在此页
- 先决条件
- 安装 LAMP 服务器
- 为 Joomla 创建一个 MySQL 数据库
- 下载 Joomla
- 为 Joomla 创建一个 Apache 虚拟主机
- 访问 Joomla Web 安装
- 使用 Lets Encrypt SSL 保护 Joomla
- 结论
Joomla 是一个免费、开源且屡获殊荣的内容管理系统,可让您构建网站和在线 Web 应用程序。它是用 PHP 编写的,使用 MySQL 作为数据库后端。 Joomla 提供了一些优秀的功能,可以帮助用户有效地组织和管理内容。它可扩展、易于使用、搜索引擎友好,并提供用户友好的 Web 界面以从中心位置管理您的网站。
在这篇文章中,我们将向您展示如何在 Ubuntu 22.04 上安装带有 Apache 的 Joomla CMS 和 Lets Encrypt SSL。
先决条件
- 一台运行 Ubuntu 22.04 的服务器。
- 用您的服务器 IP 指向的有效域名。
- 在服务器上配置了根密码。
安装 LAMP 服务器
首先,使用以下命令安装 Apache Web 服务器、MySQL 数据库服务器和带有其他扩展的最新版本的 PHP:
apt install apache2 mysql-server php8.1 libapache2-mod-php8.1 php8.1-dev php8.1-bcmath php8.1-intl php8.1-soap php8.1-zip php8.1-curl php8.1-mbstring php8.1-mysql php8.1-gd php8.1-xml unzip -y
安装所有包后,使用以下命令验证 PHP 版本:
php -v
您应该看到以下输出:
PHP 8.1.2 (cli) (built: Apr 7 2022 17:46:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies
完成后,您可以继续下一步。
为 Joomla 创建 MySQL 数据库
接下来,您需要为 Joomla 创建一个数据库和用户来存储 Web 内容。首先,使用以下命令连接到 MySQL:
mysql
连接后,使用以下命令创建数据库和用户:
mysql> CREATE DATABASE joomladb;
mysql> CREATE USER 'joomlauser'@'localhost' IDENTIFIED BY 'securepassword';
接下来,使用以下命令授予 Joomla 数据库的所有权限:
mysql> GRANT ALL ON joomladb.* TO 'joomlauser'@'localhost';
接下来,使用以下命令刷新权限表并退出 MySQL:
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
完成后,您可以继续下一步。
下载 Joomla
在编写本教程时,Joomla 的最新版本是 4.2.1。您可以使用以下命令从其官方网站下载它:
wget https://downloads.joomla.org/cms/joomla4/4-1-2/Joomla_4-1-2-Stable-Full_Package.zip
下载完成后,使用以下命令将下载的文件解压缩到 Apache Web 根目录:
unzip Joomla_4-1-2-Stable-Full_Package.zip -d /var/www/html/joomla
接下来,使用以下命令更改 Joomla 的所有权和权限:
chown -R www-data:www-data /var/www/html/joomla/
chmod -R 755 /var/www/html/joomla/
完成后,您可以继续下一步。
为 Joomla 创建 Apache 虚拟主机
接下来,您需要为 Joomla 创建一个 Apache 虚拟主机配置文件。您可以使用以下命令创建它:
nano /etc/apache2/sites-available/joomla.conf
添加以下行:
<VirtualHost *:80>
ServerAdmin
ServerName joomla.example.com
DocumentRoot /var/www/html/joomla
<Directory /var/www/html/joomla/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com_error.log
CustomLog ${APACHE_LOG_DIR}/example.com_access.log combined
</VirtualHost>
保存并关闭文件,然后使用以下命令激活 Joomla 虚拟主机:
a2ensite joomla.conf
接下来,重新启动 Apache 服务以应用更改:
systemctl restart apache2
您还可以使用以下命令检查 Apache 服务状态:
systemctl status apache2
您将获得以下输出:
? apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-04-29 07:59:59 UTC; 4s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 16393 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 16398 (apache2)
Tasks: 6 (limit: 4630)
Memory: 13.8M
CPU: 129ms
CGroup: /system.slice/apache2.service
??16398 /usr/sbin/apache2 -k start
??16399 /usr/sbin/apache2 -k start
??16400 /usr/sbin/apache2 -k start
??16401 /usr/sbin/apache2 -k start
??16402 /usr/sbin/apache2 -k start
??16403 /usr/sbin/apache2 -k start
Apr 29 07:59:59 ubuntu systemd[1]: Starting The Apache HTTP Server...
完成后,您可以继续下一步。
访问 Joomla Web 安装
现在,打开您的 Web 浏览器并使用 URL http://joomla.example.com 访问 Joomla Web 安装。您将被重定向到以下页面:

选择您的语言,定义您的站点名称,然后单击“设置登录数据”。您应该会看到以下页面:

提供您的真实姓名、用户名、密码、电子邮件地址,然后单击“设置数据库连接”。您应该会看到以下页面:

提供您的数据库名称、数据库用户名、主机、密码,然后单击“安装 Joomla”按钮。安装 Joomla 后,您将获得以下页面:

单击打开管理员。您应该看到 Joomla 登录页面:

提供您的管理员用户名和密码,然后单击“登录”按钮。您应该在以下页面上看到 Joomla 仪表板:

使用 Lets Encrypt SSL 保护 Joomla
使用 Lets Encrypt SSL 保护您的网站始终是个好主意。您将需要安装 Certbot 客户端来安装和管理 SSL。您可以使用以下命令安装它:
apt-get install python3-certbot-apache -y
安装 Certbot 后,运行以下命令以使用 Lets Encrypt SSL 保护您的网站:
certbot --apache -d joomla.example.com
您将被要求提供您的电子邮件并接受服务条款,如下所示:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Plugins selected: Authenticator apache, Installer apache
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for joomla.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/joomla-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/joomla-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/joomla-le-ssl.conf
接下来,选择是否将 HTTP 流量重定向到 HTTPS,如下所示:
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
键入 2 并按 Enter 键为您的网站安装 Lets Encrypt SSL:
Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/joomla.conf to ssl vhost in /etc/apache2/sites-available/joomla-le-ssl.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://joomla.example.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=joomla.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/joomla.example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/joomla.example.com/privkey.pem
Your cert will expire on 2023-01-23. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
现在,您可以使用 URL https://joomla.example.com 安全地访问您的网站。
结论
恭喜!您已经在 Ubuntu 22.04 上成功安装了带有 Apache 和 Lets Encrypt SSL 的 Joomla。您现在可以使用 Joomla 平台轻松创建和托管网站。如果您有任何问题,请随时问我。