如何在CentOS 8上安装Drupal 9 CMS
今天的指南涵盖在CentOS 8 Linux系统上安装Drupal 9 CMS。 Drupal是一个开放源代码内容管理系统,使内容创建者可以构建出色的数字体验。 Drupal使您可以轻松创建新网站以及在Web浏览器中添加,编辑,发布或删除所有内容。 Drupal软件是用PHP编写的,并根据GNU通用公共许可证发行。
Drupal 9的大多数功能来自Drupal 8的改进和新增功能。 Drupal CMS的一些功能包括:
- 布局制作器:允许内容编辑者无需设计即可设计页面
- 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。
步骤1:更新系统
确保您的系统已更新到最新版本。
sudo dnf -y update && sudo systemctl reboot
服务器启动后,再次登录以查看已应用的更新。
$ ssh [email protected]
步骤2:在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 2020-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, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MariaDB [(none)]>
步骤3:创建Drupal数据库
数据库和用户是Drupal CMS工作所必需的。打开MariaDB shell。
$ mysql -u root -p
创建一个Drupal数据库和用户。
CREATE DATABASE drupal;
GRANT ALL ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY '[email protected]';
FLUSH PRIVILEGES;
q
步骤4:安装PHP 7.3和Apache Web服务器
在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-2018 The PHP Group
Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.5, Copyright (c) 1999-2018, 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 2020-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.computingforgeeks.com systemd[1]: Starting The Apache HTTP Server...
Jun 27 01:08:32 centos.computingforgeeks.com systemd[1]: Started The Apache HTTP Server.
Jun 27 01:08:32 centos.computingforgeeks.com 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 2020-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.computingforgeeks.com systemd[1]: Starting The PHP FastCGI Process Manager...
Jun 27 01:08:32 centos.computingforgeeks.com systemd[1]: Started The PHP FastCGI Process Manager.
如果您的防火墙服务打开了SSL的端口80和443:
sudo firewall-cmd --add-service={http,https} --permanent
sudo firewall-cmd --reload
步骤5:在CentOS 8上下载Drupal 9
将Drupal 9 tarball下载到运行该服务的主机。
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
步骤6:为Drupal配置Apache
为Drupal网站创建一个新的Apache配置。
sudo vi /etc/httpd/conf.d/drupal.conf
修改以下内容,并将其添加到文件集中,即指向域,管理员用户和Drupal数据的正确路径。
ServerName mysite.com
ServerAlias www.mysite.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/drupal/
CustomLog /var/log/httpd/access_log combined
ErrorLog /var/log/httpd/error_log
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]
检查配置语法。
$ sudo apachectl -t
Syntax OK
重新启动您的Web服务器。
systemctl restart httpd
步骤7:在CentOS 8上安装Drupal 9
在Web浏览器中打开服务器DNS名称,并在CentOS 8上完成Drupal 9的安装。
选择一种语言:
选择一个安装配置文件。
配置Drupal的数据库。
Drupal安装将开始。等待它完成。
配置站点
您已在CentOS 8服务器上成功安装了Drupal 9。请参考官方文档进行调整和高级设置。
对于https访问,请查看Drupal SSL配置指南。
检查Ubuntu的安装:在Ubuntu上安装Drupal 9 CMS。