本教程适用于以下操作系统版本
- Ubuntu 22.04 (Jammy Jellyfish)
- Ubuntu 20.04 (Focal Fossa)
- Ubuntu 14.04 LTS (Trusty Tahr)
本页内容
- 先决条件
- 安装 LAMP 服务器
- 为 Joomla 创建 MySQL 数据库
- 下载 Joomla
- 为 Joomla 创建 Apache 虚拟主机
- 访问 Joomla Web 安装界面
- 使用 Let's Encrypt SSL 保护 Joomla
- 结论
Joomla 是一款免费、开源且屡获殊荣的内容管理系统,可用于构建网站和在线 Web 应用程序。它使用 PHP 编写,并采用 MySQL 作为数据库后端。Joomla 提供了诸多优秀特性,可帮助用户高效地组织和管理内容。它具备可扩展性、易于使用、对搜索引擎友好,并提供用户友好的 Web 界面,让你从一个统一位置管理网站。
在本文中,我们将向你展示如何在 Ubuntu 22.04 上使用 Apache 和 Let's Encrypt SSL 安装 Joomla CMS。
先决条件
- 一台运行 Ubuntu 22.04 的服务器。
- 一个指向你的服务器 IP 的有效域名。
- 服务器上已配置 root 密码。
安装 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
[email protected]
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 安装界面。你将被重定向到以下页面:

选择语言,设置站点名称,然后点击 Setup Login Data。你将看到以下页面:

填写你的真实姓名、用户名、密码和电子邮件地址,然后点击 Setup Database Connection。你将看到以下页面:

填写数据库名称、数据库用户名、主机和密码,然后点击 Install Joomla 按钮。Joomla 安装完成后,你将看到以下页面:

点击 Open Administrator。你将看到 Joomla 登录页面:

输入管理员用户名和密码,然后点击 Log in 按钮。你将在以下页面看到 Joomla 仪表板:

使用 Let's Encrypt SSL 保护 Joomla
使用 Let's Encrypt SSL 保护你的网站总是一个好做法。你需要安装 Certbot 客户端来安装和管理 SSL。可使用以下命令安装:
apt-get install python3-certbot-apache -y
Certbot 安装完成后,运行以下命令,使用 Let's 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): [email protected] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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,为你的网站安装 Let's 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 和 Let's Encrypt SSL 安装了 Joomla。现在,你可以借助 Joomla 平台轻松创建并托管网站。