在本教程中,我们将向您展示如何在 AlmaLinux 8 上安装 Drupal。对于那些不知道的人,Drupal 是一个开源且流行的内容管理工具,拥有庞大的支持社区。 全球数以百万计的人和组织使用它来构建和维护他们的网站。
本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo
‘ 到命令以获取 root 权限。 我将向您展示在 AlmaLinux 8 上逐步安装 Drupal。您可以按照相同的说明进行操作 Fedora、RHEL、CentOS 和 Rocky Linux 发行版。
先决条件
- 运行以下操作系统之一的服务器:AlmaLinux 8、CentOS 和 Rocky Linux 8。
- 建议您使用全新的操作系统安装以防止任何潜在问题
- 一种
non-root sudo user
或访问root user
. 我们建议充当non-root sudo user
,但是,如果您在充当 root 时不小心,可能会损害您的系统。
在 AlmaLinux 8 上安装 Drupal
第 1 步。首先,让我们首先确保您的系统是最新的。
sudo dnf clean all sudo dnf update
步骤 2. 安装 LAMP 服务器。
在安装 WordPress 之前, Fedora 需要 LAMP 服务器。 如果您没有安装 LAMP,您可以在此处按照我们的指南进行操作。
步骤 3. 在 AlmaLinux 8 上安装 Drupal。
默认情况下,Drupal 在 AlmaLinux 8 基础存储库中不可用。 现在我们运行以下命令将最新版本的 Drupal 下载到您的系统:
wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz
接下来,解压下载的文件:
tar xvf drupal.tar.gz mv drupal-*/ /var/www/html/drupal
我们将需要更改一些文件夹权限:
chown -R apache:apache /var/www/html/drupal chmod -R 755 /var/www/html/
之后,为 Drupal 安装程序创建附加文件:
mkdir /var/www/html/drupal/sites/default/files cp /var/www/html/drupal/sites/default/default.settings.php /var/www/html/drupal/sites/default/settings.php
步骤 5. 配置 MariaDB。
默认情况下,MariaDB 未加固。 您可以使用 mysql_secure_installation
脚本。 您应该仔细阅读以下每个步骤,这些步骤将设置 root 密码、删除匿名用户、禁止远程 root 登录、删除测试数据库和访问安全 MariaDB:
mysql_secure_installation
像这样配置它:
- Set root password? [Y/n] y - Remove anonymous users? [Y/n] y - Disallow root login remotely? [Y/n] y - Remove test database and access to it? [Y/n] y - Reload privilege tables now? [Y/n] y
接下来,我们需要登录 MariaDB 控制台并为 Drupal 创建一个数据库。 运行以下命令:
mysql -u root -p
这将提示您输入密码,因此输入您的 MariaDB 根密码并点击 Enter. 登录到数据库服务器后,您需要为 Drupal 安装创建一个数据库:
MariaDB [(none)]> CREATE DATABASE drupal_db; MariaDB [(none)]> CREATE USER 'drupal'@'localhost' IDENTIFIED BY 'your-strong-password'; MariaDB [(none)]> GRANT ALL PRIVILEGES ON drupal_db.* TO 'drupal'@'localhost' IDENTIFIED BY 'your-strong-password' WITH GRANT OPTION; MariaDB [(none)]> ALTER DATABASE neos_db charset=utf8; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;
步骤 6. 配置 Apache.
我们将创建一个 Apache Drupal 网站的虚拟主机。 首先,创建’/etc/httpd/conf.d/drupal.conf
‘ 使用您喜欢的文本编辑器创建文件:
nano /etc/httpd/conf.d/drupal.conf
添加以下行:
<VirtualHost *:80> ServerName mysite.com ServerAlias www.your-domain.com ServerAdmin [email protected] DocumentRoot /var/www/html/drupal/ <Directory /var/www/html/drupal> Options Indexes FollowSymLinks AllowOverride All Require all granted RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] </Directory> </VirtualHost>
Save 和 close 文件,然后重新启动 Apache 使更改生效的服务:
sudo systemctl restart httpd sudo systemctl enable httpd
步骤 7. 安全 Apache 和 Let’s Encrypt SSL 免费证书
首先,我们使用以下命令安装 Certbot:
sudo dnf install certbot python3-certbot-apache
然后,安装 SSL 证书 Apache 如下:
sudo certbot --apache
进入交互式提示并安装证书。 如果安装了证书,您将看到以下祝贺消息:
Congratulations! You have successfully enabled HTTPS on https://your-domain.com NEXT STEPS: - The certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
步骤 8. 配置防火墙。
允许防火墙使用 HTTP 和 HTTPS 并使用以下命令重新加载它:
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
步骤 9. 访问 Drupal Web 界面。
成功安装后,打开 Web 浏览器并使用 URL 访问 Drupal CMS https://your-domain.com
. 您将被重定向到以下页面:
恭喜! 您已成功安装 Drupal。 感谢您使用本教程在您的 AlmaLinux 8 系统上安装 Drupal CMS(内容管理系统)。 如需更多帮助或有用信息,我们建议您查看 Drupal 官方网站.