本教程适用于以下操作系统版本
- Debian 12 (Bookworm)
- Debian 11 (Bullseye)
- Debian 9 (Stretch)
本页内容
- 先决条件
- 安装 LAMP 堆栈
- 创建 Drupal 数据库
- 下载 Drupal
- 为 Drupal 创建 Apache 虚拟主机
- 访问 Drupal 网站
- 在 Drupal 网站上启用 Let's Encrypt SSL 支持
- 结论
Drupal 是一个基于 LAMP 堆栈的免费开源内容管理系统。Drupal 具有强大的标准功能,使您能够创建功能强大的网站和博客。它带有许多主题、插件和小部件,可帮助您无需任何编程知识即可创建网站。它提供了许多功能,例如多站点支持、多语言支持、评论系统、RSS 订阅、用户注册等等。
在本文中,我们将向您展示如何在 Debian 11 上使用 Apache 和 Let's Encrypt SSL 安装 Drupal CMS。
先决条件
- 一台运行 Debian 11 的服务器。
- 一个指向您服务器 IP 的有效域名。
- 服务器上已配置 root 密码。
安装 LAMP 堆栈
Drupal 基于 LAMP 堆栈。因此必须在您的服务器上安装 LAMP 堆栈。如果尚未安装,您可以通过运行以下命令来安装:
apt-get install apache2 mariadb-server mariadb-client php libapache2-mod-php php-cli php-mysql php-zip php-gd php-fpm php-json php-common php-intl php-mbstring php-curl php-xml php-pear php-tidy php-soap php-bcmath php-xmlrpc -y
安装 LAMP 堆栈后,编辑 php.ini 文件并更改一些默认设置:
nano /etc/php/7.4/apache2/php.ini
更改以下几行:
memory_limit = 256M upload_max_filesize = 32M max_execution_time = 300 date.timezone = Asia/Kolkata
完成后保存并关闭文件。
创建 Drupal 数据库
Drupal 使用 MariaDB 作为数据库后端。因此您需要为 Drupal 创建一个数据库和用户。
首先,使用以下命令登录 MariaDB:
mysql
登录后,使用以下命令创建数据库和用户:
MariaDB [(none)]> CREATE DATABASE drupaldb;
MariaDB [(none)]> CREATE USER 'drupaluser'@'localhost' IDENTIFIED BY "securepassword";
接下来,使用以下命令授予 Drupal 数据库所有权限:
MariaDB [(none)]> GRANT ALL ON drupaldb.* TO 'drupaluser'@'localhost' IDENTIFIED BY "securepassword";
接下来,使用以下命令刷新权限并退出 MariaDB:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
下载 Drupal
首先,前往 Drupal 网站选择最新版本的 Drupal,并使用以下命令下载:
wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
下载 Drupal 后,使用以下命令解压下载的文件:
tar -xvf drupal.tar.gz
接下来,将解压后的目录移动到 Apache 默认根目录:
mv drupal-* /var/www/html/drupal
接下来,使用以下命令更改 Drupal 目录的所有权和权限:
chown -R www-data:www-data /var/www/html/drupal/
chmod -R 755 /var/www/html/drupal/
为 Drupal 创建 Apache 虚拟主机
接下来,您需要创建一个 Apache 虚拟主机配置文件来托管 Drupal。您可以使用以下命令创建它:
nano /etc/apache2/sites-available/drupal.conf
添加以下几行:
<VirtualHost *:80>
ServerAdmin
[email protected]
DocumentRoot /var/www/html/drupal/
ServerName drupal.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/html/drupal/>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
<Directory /var/www/html/>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>
</VirtualHost>
保存并关闭文件,然后使用以下命令启用 Drupal 虚拟主机和 Apache 重写模块:
a2ensite drupal.conf
a2enmod rewrite
接下来,重启 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 Sat 2021-09-18 14:59:40 UTC; 5s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 19698 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 19703 (apache2)
Tasks: 6 (limit: 2341)
Memory: 15.3M
CPU: 78ms
CGroup: /system.slice/apache2.service
??19703 /usr/sbin/apache2 -k start
??19704 /usr/sbin/apache2 -k start
??19705 /usr/sbin/apache2 -k start
??19706 /usr/sbin/apache2 -k start
??19707 /usr/sbin/apache2 -k start
??19708 /usr/sbin/apache2 -k start
至此,Apache Web 服务器已配置为服务 Drupal。您现在可以继续下一步。
访问 Drupal 网站
现在,打开您的 Web 浏览器并使用 URL http://drupal.example.com 访问 Drupal。您将被重定向到以下页面:

选择英语并点击“保存并继续”按钮,您应该看到以下图片:

选择一个安装配置文件并点击“保存并继续”按钮。您应该看到以下页面:

在数据库配置页面,提供所有必需的数据库详细信息,如数据库名称、数据库用户名和密码、数据库主机,然后点击“保存并继续”按钮,您应该看到以下图片:


在 Drupal 站点配置页面,提供您的站点名称、管理员用户名和密码,然后点击“保存并继续”按钮开始安装 Drupal。安装 Drupal 后,您应该在下图中看到 Drupal 仪表板:

在 Drupal 网站上启用 Let's Encrypt SSL 支持
使用 Let's Encrypt SSL 保护您的网站始终是个好主意。首先,您需要安装 Certbot 客户端来安装和管理 SSL。默认情况下,Certbot 软件包包含在 Debian 11 默认存储库中,因此您可以使用以下命令安装:
apt-get install python3-certbot-apache -y
安装 Certbot 后,运行以下命令使用 Let's Encrypt SSL 保护您的网站:
certbot --apache -d drupal.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 drupal.example.com Enabled Apache rewrite module Waiting for verification... Cleaning up challenges Created an SSL vhost at /etc/apache2/sites-available/drupal-le-ssl.conf Enabled Apache socache_shmcb module Enabled Apache ssl module Deploying Certificate to VirtualHost /etc/apache2/sites-available/drupal-le-ssl.conf Enabling available site: /etc/apache2/sites-available/drupal-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/drupal.conf to ssl vhost in /etc/apache2/sites-available/drupal-le-ssl.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://drupal.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=drupal.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/drupal.example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/drupal.example.com/privkey.pem Your cert will expire on 2021-04-20. 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 11 上使用 Let's Encrypt SSL 安装了 Drupal。您现在可以开始创建自己的博客或网站,而无需任何编程知识。如有任何问题,请随时问我。