在CentOS 8/Rhel 8上安装和配置Drupal 8
在本博客文章中,我们将讨论如何在CentOS 8/Rhel 8 Linux发行版上安装Drupal 8.
Drupal是一个免费的开源内容管理平台,以便于创建,在线内容和用户参与社区。
Drupal是用PHP编写的,它使用数据库后端存储其数据 - MySQL,MariaDB,SQLite,PostgreSQL 等
Drupal的功能可以延长或者定制成千上万的插件。
我们可以选择我们选择的Web服务器,以便在CentOS 8上托管Drupal - 这可以是nginx,apache,lighttpd或者Windows IIS Server。
让我们入门并在CentOS 8/Rhel 8 Linux上安装Drupal。
第1步 - 更新CentOS/RHEL 8机器
更新系统包索引和已安装的软件包。
sudo dnf -y update
由于我们可以获得内核更新,请考虑重新启动系统。
sudo reboot
第2步 - 安装数据库服务器
选择要使用的数据库服务器,这可以是MySQL,MariaDB或者PostgreSQL。
下面的一个导游应该为我们工作。
在CentOS 8上安装MariaDB
在CentOS 8上安装PostgreSQL
在CentOS 8上安装MySQL
我的安装将使用MariaDB作为DRUPAL的数据库服务器。
在数据库安装后,为CentOS 8 Linux创建Drupal的数据库和用户。
$mysql -u root -p CREATE DATABASE drupal CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; CREATE USER Hyman@theitroad IDENTIFIED BY "Hyman@theitroad"; GRANT ALL ON drupal.* TO Hyman@theitroad IDENTIFIED BY "Hyman@theitroad"; FLUSH PRIVILEGES; QUIT
Drupal数据库用户应该能够访问创建的Drupal数据库。
$mysql -u drupal -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 19 Server version: 10.3.11-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | drupal | | information_schema | +--------------------+ 2 rows in set (0.000 sec) MariaDB [(none)]> QUIT Bye
第3步:安装PHP和所需的扩展
安装Drupal在CentOS 8上需要PHP。
这可以通过在终端中的下面运行命令来实现。
sudo dnf install -y @php sudo dnf install -y php php-{cli,mysqlnd,json,opcache,xml,mbstring,gd,curl}
可以使用PHP命令进行安装的版本。
$php -v PHP 7.2.11 (cli) (built: Oct 9 2016 15:09:36) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.2.11, Copyright (c) 1999-2016, by Zend Technologies
启动并启用PHP-FPM服务。
sudo systemctl enable --now php-fpm
服务应显示在SystemCtl状态命令上运行。
$systemctl status php-fpm ● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2019-10-09 22:02:47 EAT; 5s ago Main PID: 9716 (php-fpm) Status: "Ready to handle connections" Tasks: 6 (limit: 11512) Memory: 22.5M CGroup: /system.slice/php-fpm.service ├─9716 php-fpm: master process (/etc/php-fpm.conf) ├─9717 php-fpm: pool www ├─9718 php-fpm: pool www ├─9719 php-fpm: pool www ├─9720 php-fpm: pool www └─9721 php-fpm: pool www Oct 09 22:02:47 centos8.novalocal systemd[1]: Starting The PHP FastCGI Process Manager... Oct 09 22:02:47 centos8.novalocal systemd[1]: Started The PHP FastCGI Process Manager.
第4步:安装Web服务器
在本教程中,我们将使用Apache作为CentOS上的Drupal。
我们在CentOS 8上安装Apache的详细教程8.只需运行以下命令即可在CentOS中获取Apache Httpd Server。
sudo dnf -y install @httpd
启动并启用HTTPD服务。
sudo systemctl enable --now httpd
允许防火墙中的HTTP和HTTPS协议。
sudo firewall-cmd --add-service={http,https} --permanent sudo firewall-cmd --reload
第5步:在CentOS 8/Rhel 8上安装Drupal 8
从Drupal发布页面下载最新版本的Drupal发布。
sudo dnf -y install wget DRUPAL_VERSION="8.9.1" wget https://ftp.drupal.org/files/projects/drupal-${DRUPAL_VERSION}.tar.gz
提取下载的存档文件。
tar xvf drupal-${DRUPAL_VERSION}.tar.gz
移动从提取到/var/www/html目录创建的文件夹。
sudo mv drupal-${DRUPAL_VERSION} /var/www/html/drupal
创建Drupal Installer所需的其他目录和文件。
sudo mkdir /var/www/html/drupal/sites/default/files sudo cp /var/www/html/drupal/sites/default/default.settings.php /var/www/html/drupal/sites/default/settings.php
设置目录权限和selinux标签。
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/drupal(/.*)?" sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/drupal/sites/default/settings.php' sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/drupal/sites/default/files' sudo restorecon -Rv /var/www/html/drupal sudo restorecon -v /var/www/html/drupal/sites/default/settings.php sudo restorecon -Rv /var/www/html/drupal/sites/default/files sudo chown -R apache:apache /var/www/html/drupal
在CentOS 8上为Drupal创建Apache配置文件。
sudo vi /etc/httpd/conf.d/drupal.conf
基本配置类似于下面。
<VirtualHost *:80> ServerAdmin Hyman@theitroad ServerName example.com DocumentRoot /var/www/html/drupal <Directory /var/www/html/drupal Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog /var/log/httpd/drupal_error.log CustomLog /var/log/httpd/drupal_access.log combined </VirtualHost>
其中:example.com是域/var/www/html/drupal是drupal文件/var/log/apache2的位置/是Apache日志文件的位置
对于HTTPS访问,请检查Drupal SSL配置教程。
更改后重新启动httpd服务。
sudo systemctl restart httpd
如果重新启动成功,则应在状态检查中查看成功消息。
$systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Drop-In: /usr/lib/systemd/system/httpd.service.d └─php-fpm.conf Active: active (running) since Wed 2019-10-09 22:17:06 EAT; 5s ago Docs: man:httpd.service(8) Main PID: 9951 (httpd) Status: "Started, listening on: port 443, port 80" Tasks: 213 (limit: 11512) Memory: 25.1M CGroup: /system.slice/httpd.service ├─9951 /usr/sbin/httpd -DFOREGROUND ├─9953 /usr/sbin/httpd -DFOREGROUND ├─9954 /usr/sbin/httpd -DFOREGROUND ├─9955 /usr/sbin/httpd -DFOREGROUND └─9956 /usr/sbin/httpd -DFOREGROUND Oct 09 22:17:06 centos8.novalocal systemd[1]: Starting The Apache HTTP Server... Oct 09 22:17:06 centos8.novalocal httpd[9951]: Server configured, listening on: port 443, port 80 Oct 09 22:17:06 centos8.novalocal systemd[1]: Started The Apache HTTP Server.
第6步:在CentOS 8/Rhel 8上完成Drupal安装
打开浏览器并执行配置的URL"http://example.com",这应该是从DNS或者/etc/hosts文件中解析的记录。
选择安装语言,然后单击"继续"。
在下一页上,选择安装配置文件。
提供数据库连接详细信息。
对于远程数据库服务器,请在"高级选项"下提供地址。
安装应该开始。
提供域,管理员用户,电子邮件和密码。