本教程适用于以下操作系统版本

  • Debian 12 (Bookworm)
  • Debian 10 (Buster)
  • Debian 9 (Stretch)

本页目录

  • 先决条件
  • 开始之前
  • 安装 LAMP 服务器
  • 为 Joomla 创建数据库
  • 安装 Joomla
  • 配置 Apache Web 服务器
  • 访问 Joomla
  • 使用 Let's Encrypt SSL 保护 Joomla
  • 结论

Joomla 是一个免费的开源内容管理系统,用于创建、修改和管理网站内容。它简单易用,因此您无需具备任何 HTML 或 CSS 知识即可构建网站。它使用 PHP 编写,并使用 MySQL 作为数据库。它提供了广泛的功能,使其成为一个开箱即用的灵活内容管理系统。它附带数百个免费扩展,让您可以自定义和扩展功能。

在本教程中,我将向您展示如何在 Debian 10 上使用 Apache 和 Let's Encrypt 安装 Joomla CMS。

先决条件

  • 一台运行 Debian 10 的服务器。
  • 一个指向您服务器 IP 的有效域名。
  • 服务器上已配置 root 密码。

开始之前

首先,运行以下命令将系统软件包更新到最新版本:

apt-get update -y

所有软件包更新完成后,您可以继续下一步。

安装 LAMP 服务器

接下来,您需要在系统上安装 Apache Web 服务器、MariaDB 数据库、PHP 及其他 PHP 扩展。您可以使用以下命令安装所有这些组件:

apt-get install apache2 mariadb-server php openssl php-imagick php-common php-curl php-gd php-imap php-intl php-json php-ldap php-mbstring php-mysql php-pgsql php-smbclient php-ssh2 php-sqlite3 php-xml php-zip -y

所有软件包安装完成后,您可以继续下一步。

为 Joomla 创建数据库

Joomla 使用 MySQL 或 MariaDB 来存储其内容。因此您需要为 Joomla 创建一个数据库和用户。

首先,使用以下命令连接到 MariaDB:

mysql

连接成功后,使用以下命令创建数据库和用户:

MariaDB [(none)]> CREATE DATABASE joomladb;
MariaDB [(none)]> GRANT ALL ON joomladb.* TO 'joomlauser'@'localhost' IDENTIFIED BY 'password';

接下来,使用以下命令刷新权限并退出 MariaDB:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

完成后,您可以继续下一步。

安装 Joomla

接下来,使用以下命令下载最新版本的 Joomla:

wget https://downloads.joomla.org/cms/joomla3/3-9-25/Joomla_3-9-25-Stable-Full_Package.tar.bz2

下载完成后,在 Apache Web 根目录中为 Joomla 创建一个目录:

mkdir /var/www/html/joomla

接下来,运行以下命令将下载的文件解压到 Joomla 目录中:

bunzip2 Joomla_3-9-25-Stable-Full_Package.tar.bz2
tar -xvf Joomla_3-9-25-Stable-Full_Package.tar -C /var/www/html/joomla/

接下来,使用以下命令为 Joomla 目录设置适当的权限和所有权:

chown -R www-data:www-data /var/www/html/joomla
chmod -R 755 /var/www/html/joomla

完成后,您可以继续下一步。

配置 Apache Web 服务器

接下来,您需要创建一个 Apache 虚拟主机配置文件来托管 Joomla。

您可以使用以下命令创建它:

nano /etc/apache2/sites-available/joomla.conf

添加以下几行内容:

<VirtualHost *:80>
   ServerName joomla.example.com 
   ServerAdmin 
[email protected]

   DocumentRoot /var/www/html/joomla
   <Directory /var/www/html/joomla>
	    Allowoverride all
   </Directory>
</VirtualHost>

保存并关闭文件,然后使用以下命令启用 Apache 虚拟主机:

a2ensite joomla

接下来,重启 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 Mon 2021-03-22 09:26:20 UTC; 4s ago
     Docs: https://httpd.apache.org/docs/2.4/
  Process: 14495 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
 Main PID: 14499 (apache2)
    Tasks: 6 (limit: 4701)
   Memory: 18.8M
   CGroup: /system.slice/apache2.service
           ??14499 /usr/sbin/apache2 -k start
           ??14500 /usr/sbin/apache2 -k start
           ??14501 /usr/sbin/apache2 -k start
           ??14502 /usr/sbin/apache2 -k start
           ??14503 /usr/sbin/apache2 -k start
           ??14504 /usr/sbin/apache2 -k start

Mar 22 09:26:20 debian10 systemd[1]: Starting The Apache HTTP Server...

访问 Joomla

现在,打开您的 Web 浏览器,使用 URL http://joomla.example.com 访问 Joomla Web 界面。您将被重定向到以下页面:

如何在 Debian 10 上使用 Apache 和 Let's Encrypt 安装 Joomla 完整教程

现在,提供您的站点名称、电子邮件地址、管理员用户名、密码,然后点击“下一步”按钮。您应该会看到以下页面:

如何在 Debian 10 上使用 Apache 和 Let's Encrypt 安装 Joomla 完整教程

提供您的数据库名称、数据库用户名、密码,然后点击“下一步”按钮。您应该会看到以下页面:

如何在 Debian 10 上使用 Apache 和 Let's Encrypt 安装 Joomla 完整教程

如何在 Debian 10 上使用 Apache 和 Let's Encrypt 安装 Joomla 完整教程

现在,确认所有设置并点击“安装”按钮开始安装。安装完成后,您应该会看到以下页面:

如何在 Debian 10 上使用 Apache 和 Let's Encrypt 安装 Joomla 完整教程

点击“删除安装文件夹”。您应该会看到以下页面:

如何在 Debian 10 上使用 Apache 和 Let's Encrypt 安装 Joomla 完整教程

现在,点击“管理员”按钮,您应该会看到 Joomla 登录页面:

如何在 Debian 10 上使用 Apache 和 Let's Encrypt 安装 Joomla 完整教程

提供您的管理员凭据并点击“登录”按钮,您将如下图所示看到 Joomla 控制面板:

如何在 Debian 10 上使用 Apache 和 Let's Encrypt 安装 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 并按回车键,为您的网站安装 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 2020-10-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

结论

恭喜!您已在 Debian 10 服务器上成功安装 Joomla CMS。现在您可以使用 Joomla 轻松构建自己的网站。如有任何问题,欢迎随时提问。