在CentOS 8上安装和配置Drupal 9 CMS

时间:2020-02-23 14:31:09  来源:igfitidea点击:

在今天的指南中,我们将介绍如何在CentOS 8 Linux系统上安装Drupal 9 CMS。 Drupal是一个开放源代码内容管理系统,使内容创建者可以构建出色的数字体验。使用Drupal,可以轻松地在Web浏览器上创建新以及添加,编辑,发布或者删除内容。 Drupal软件是用PHP编写的,并根据GNU通用公共许可证发行。

Drupal 9的大多数功能来自Drupal 8的改进和新的添加功能。

Drupal CMS的某些功能包括:

  • Layout Builder:允许内容编辑者设计页面而无需工程帮助
  • API优先架构:支持构建健壮的去耦和无头应用程序
  • 媒体库:使图像,视频和其他资产的管理比以往更加轻松。
  • 自动更新- 新的管理界面和默认主题

如何在CentOS 8上安装Drupal 9 CMS

在CentOS 8上开始安装Drupal 9 CMS之前,请注意以下新要求。

  • PHP> = 7.3
  • MySQL或者Percona,版本> = 5.7.8
  • MariaDB> = 10.3.7
  • PostgreSQL> = 10

如果我们认真执行以下步骤,则应该在CentOS 8服务器上安装可运行的Drupal 9 CMS。

更新系统

确保系统已更新到最新版本:

sudo dnf -y update && sudo systemctl reboot

服务器启动后,再次登录并确认更新已应用。

$ssh theitroad@localhost

在CentOS 8上安装MariaDB数据库

Drupal可以使用许多数据库。我选择的数据库是MariaDB。

运行这些命令以在CentOS 8 Linux上安装MariaDB数据库服务器。

sudo dnf -y install @mariadb

安装后启动并启用服务。

sudo systemctl enable --now mariadb

确认服务处于运行状态:

$systemctl status mariadb
● mariadb.service - MariaDB 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-06-27 00:59:27 CEST; 33s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 3945 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 3811 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service (code=exited, status=0/SUCCESS)
  Process: 3786 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 3913 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 24403)
   Memory: 85.3M
   CGroup: /system.slice/mariadb.service
           └─3913 /usr/libexec/mysqld --basedir=/usr
......

通过设置root密码,禁用root远程登录并删除我们不需要的测试数据库来保护数据库服务器的安全。

$sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

测试我们是否可以以设置密码的root用户身份登录数据库

$mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.17-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)]>

创建Drupal数据库

Drupal CMS需要数据库和用户才能正常运行。打开MariaDB shell。

$mysql -u root -p

为Drupal创建数据库和用户。

CREATE DATABASE drupal;
GRANT ALL ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY 'theitroad@localhost';
FLUSH PRIVILEGES;
\q

安装PHP 7.3和Apache Web Server

在CentOS 8 Linux上安装PHP:

sudo dnf module disable php:7.2
sudo dnf module enable php:7.3
sudo dnf -y install php php-{cli,fpm,gd,mysqlnd,mbstring,json,common,dba,dbg,devel,embedded,enchant,bcmath,gmp,intl,ldap,odbc,pdo,opcache,pear,pgsql,process,recode,snmp,soap,xml,xmlrpc}

确认PHP版本:

$php -v
PHP 7.3.5 (cli) (built: Apr 30 2019 08:37:17) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.3.5, Copyright (c) 1999-2016, by Zend Technologies

安装Apache Web服务器。

sudo dnf -y install httpd

设置PHP时区和内存限制。

$sudo vim /etc/php.ini
memory_limit = 256M
date.timezone = Africa/Nairobi

启动httpd和php-fpm服务。

sudo systemctl enable --now httpd php-fpm

检查服务是否正在运行:

$systemctl status httpd php-fpm
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/httpd.service.d
           └─php-fpm.conf
   Active: active (running) since Sat 2017-06-27 01:08:32 CEST; 1min 38s ago
     Docs: man:httpd.service(8)
 Main PID: 5317 (httpd)
   Status: "Running, listening on: port 80"
    Tasks: 213 (limit: 24403)
   Memory: 25.5M
   CGroup: /system.slice/httpd.service
           ├─5317 /usr/sbin/httpd -DFOREGROUND
           ├─5319 /usr/sbin/httpd -DFOREGROUND
           ├─5320 /usr/sbin/httpd -DFOREGROUND
           ├─5321 /usr/sbin/httpd -DFOREGROUND
           └─5322 /usr/sbin/httpd -DFOREGROUND

Jun 27 01:08:32 centos.theitroad.local systemd[1]: Starting The Apache HTTP Server...
Jun 27 01:08:32 centos.theitroad.local systemd[1]: Started The Apache HTTP Server.
Jun 27 01:08:32 centos.theitroad.local httpd[5317]: Server configured, listening on: port 80

● 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 Sat 2017-06-27 01:08:32 CEST; 1min 38s ago
 Main PID: 5318 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 6 (limit: 24403)
   Memory: 36.2M
   CGroup: /system.slice/php-fpm.service
           ├─5318 php-fpm: master process (/etc/php-fpm.conf)
           ├─5534 php-fpm: pool www
           ├─5535 php-fpm: pool www
           ├─5536 php-fpm: pool www
           ├─5537 php-fpm: pool www
           └─5538 php-fpm: pool www

Jun 27 01:08:32 centos.theitroad.local systemd[1]: Starting The PHP FastCGI Process Manager...
Jun 27 01:08:32 centos.theitroad.local systemd[1]: Started The PHP FastCGI Process Manager.

如果防火墙服务正在运行针对SSL的开放端口80和443:

sudo firewall-cmd --add-service={http,https} --permanent
sudo firewall-cmd --reload

在CentOS 8上下载Drupal 9

将Drupal 9 tar包下载到将运行该服务的主机。

sudo dnf install -y wget
wget https://www.drupal.org/download-latest/tar.gz -O drupal.tar.gz

解压缩下载的文件。

tar xvf drupal.tar.gz

将结果文件夹移动到/var/www/html目录。

rm -f drupal*.tar.gz
sudo mv drupal-*/ /var/www/html/drupal

确认文件内容:

$ls /var/www/html/drupal
autoload.php   core               INSTALL.txt  profiles    sites       vendor
composer.json  example.gitignore  LICENSE.txt  README.txt  themes      web.config
composer.lock  index.php          modules      robots.txt  update.php

将drupal目录的所有权设置为Apache用户和组。

sudo chown -R apache:apache /var/www/html/
sudo chmod -R 755 /var/www/html/

创建Drupal安装程序所需的其他目录和文件。

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

为Drupal配置Apache

为Drupal创建一个新的Apache配置。

sudo vi /etc/httpd/conf.d/drupal.conf

修改以下内容,并添加到文件集域,管理员用户和正确的Drupal数据路径。

<VirtualHost *:80>
     ServerName mysite.com
     ServerAlias www.mysite.com
     ServerAdmin theitroad@localhost
     DocumentRoot /var/www/html/drupal/

     CustomLog /var/log/httpd/access_log combined
     ErrorLog /var/log/httpd/error_log

     <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= [L,QSA]
     </Directory>
</VirtualHost>

确认配置语法:

$sudo apachectl -t
Syntax OK

重新启动Web服务器。

systemctl restart httpd

在CentOS 8上安装Drupal 9

在Web浏览器中,打开服务器DNS名称以完成在CentOS 8上Drupal 9的安装。

选择语言:

选择一个安装配置文件:

为Drupal配置数据库:

Drupal安装开始。等待它完成:

配置站点:

我们已经在CentOS 8服务器上成功安装了Drupal 9. 有关更多调整和高级配置,请参考官方文档。