安装Drupal 8必备组件-MariaDB数据库服务器
Drupal 8 需要 MariaDB 5.5.2 或者更高版本。
幸运的是,MariaDB 5.5.6 在 CentOS 7.6 服务器的标准 yum 存储库中可用。
因此,我们可以使用 yum 命令轻松安装它。
[root@drupal-8-server ~]# yum install -y mariadb-server
启用并启动 MariaDB 服务。
[root@drupal-8-server ~]# systemctl enable mariadb Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. [root@drupal-8-server ~]# systemctl start mariadb
如下配置和保护 MariaDB 数据库服务器。
[root@drupal-8-server ~]# 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!
连接 MariaDB 数据库实例。
[root@drupal-8-server ~]# mysql -u root -p123 Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 5.5.60-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)]>
为 Drupal 8 软件创建一个数据库和一个用户。
MariaDB [(none)]> CREATE DATABASE drupal CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; Query OK, 1 row affected (0.03 sec) MariaDB [(none)]> GRANT ALL ON drupal.* TO 'drupaluser'@'localhost' IDENTIFIED BY '123'; Query OK, 0 rows affected (0.01 sec)
重新加载权限表并退出。
MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> exit Bye
MariaDB 服务器已安装在 CentOS 7 上。
但是,我们也可以安装最新版本的 MariaDB。
在 CentOS 7 LEMP 服务器上安装 Drupal 8
从 Drupal 下载页面下载最新版本。
[root@drupal-8-server ~]# cd /tmp [root@drupal-8-server tmp]# wget -O drupal.tar.gz https://www.drupal.org/download-latest/tar.gz
将下载的文件解压到 /var/www/ 目录。
[root@drupal-8-server tmp]# tar xvf drupal.tar.gz -C /var/www/
重命名 Drupal 软件目录如下。
[root@drupal-8-server tmp]# cd [root@drupal-8-server ~]# mv /var/www/drupal-8.7.3/ /var/www/drupal8
根据 Drupal 8 安装程序的要求创建以下目录。
[root@drupal-8-server ~]# mkdir /var/www/drupal8/sites/default/files
将 Drupal 8 软件的所有者更改为 nginx 用户。
[root@drupal-8-server ~]# chown -R nginx:nginx /var/www/drupal8/ [root@drupal-8-server ~]# restorecon -R /var/www/drupal8/
为 Drupal 8 创建 Nginx 网站配置。
[root@drupal-8-server ~]# vi /etc/nginx/conf.d/drupal.conf
Drupal 8 网站提供了一个预定义的 Nginx+Drupal 配方。
我们在这里使用它来配置我们的 Drupal 服务器。
server {
server_name drupal-8-server.onitroad.com onitroad.com;
root /var/www/drupal8; ## 站点位置
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Very rarely should these ever be accessed outside of your lan
location ~* \.(txt|log)$ {
allow 192.168.1.0/24;
deny all;
}
location ~ \..*/.*\.php$ {
return 403;
}
location ~ ^/sites/.*/private/ {
return 403;
}
# Block access to scripts in site files directory
location ~ ^/sites/[^/]+/files/.*\.php$ {
deny all;
}
# Allow "Well-Known URIs" as per RFC 5785
location ~* ^/.well-known/ {
allow all;
}
# Block access to "hidden" files and directories whose names begin with a
# period. This includes directories used by version control systems such
# as Subversion or Git to store control files.
location ~ (^|/)\. {
return 403;
}
location / {
# try_files $uri @rewrite; # For Drupal <= 6
try_files $uri /index.php?$query_string; # For Drupal >= 7
}
location @rewrite {
rewrite ^/(.*)$ /index.php?q=;
}
# Don't allow direct access to PHP files in the vendor directory.
location ~ /vendor/.*\.php$ {
deny all;
return 404;
}
# In Drupal 8, we must also match new paths where the '.php' appears in
# the middle, such as update.php/selection. The rule we use is strict,
# and only allows this pattern with the update.php front controller.
# This allows legacy path aliases in the form of
# blog/index.php/legacy-path to continue to route to Drupal nodes. If
# you do not have any paths like that, then you might prefer to use a
# laxer rule, such as:
# location ~ \.php(/|$) {
# The laxer rule will continue to work if Drupal uses this new URL
# pattern with front controllers other than update.php in a future
# release.
location ~ '\.php$|^/update.php' {
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
# Security note: If you're running a version of PHP older than the
# latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
# See http://serverfault.com/q/627903/94922 for details.
include fastcgi_params;
# Block httpoxy attacks. See httpoxy.org/.
fastcgi_param HTTP_PROXY "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
# PHP 5 socket location.
#fastcgi_pass unix:/var/run/php5-fpm.sock;
# PHP 7 socket location.
fastcgi_pass unix:/run/php-fpm/www.sock;
}
# Fighting with Styles? This little gem is amazing.
# location ~ ^/sites/.*/files/imagecache/ { # For Drupal <= 6
location ~ ^/sites/.*/files/styles/ { # For Drupal >= 7
try_files $uri @rewrite;
}
# Handle private files through Drupal. Private file's path can come
# with a language prefix.
location ~ ^(/[a-z\-]+)?/system/files/ { # For Drupal >= 7
try_files $uri /index.php?$query_string;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
try_files $uri @rewrite;
expires max;
log_not_found off;
}
}
重启 Nginx 服务。
[root@drupal-8-server ~]# systemctl restart nginx
暂时将 SELinux 置于许可模式,以便 Drupal 8 安装程序可以在 Drupal 软件目录中创建必要的文件。
[root@drupal-8-server ~]# setenforce 0
使用客户端浏览器浏览 URL http://drupal-8-server.onitroad.com。
选择首选语言,然后单击“保存并继续”。
选择安装配置文件,然后单击“保存并继续”。
我们选择了标准配置文件。
如果有任何缺失的需求,那么它会显示验证需求页面,否则它会带你到设置数据库页面。
提供我们在上面创建的数据库和用户名。
单击“保存并继续”。
Drupal 8 安装正在进行中。
根据要求配置网站。
单击“保存并继续”。
进入 jackli 用户的仪表板。
我们还可以使用 URL http://drupal-8-server.onitroad.com 访问我们的 Drupal 8 网站。
将 SELinux 置于强制模式以提高安全性。
[root@drupal-8-server ~]# setenforce 1
我们已经在 CentOS 7 LEMP 服务器上成功安装了 Drupal 8.
Drupal 是免费的开源内容管理框架。
Drupal 是使用 Symfony 框架用 PHP 编写的。
它由 Drupal 社区开发和支持。
Drupal 在 GPLv2 许可下分发。
在本文中,我们将在 CentOS 7 LEMP 服务器上安装 Drupal 8.
首先,我们将配置一个 LEMP(Linux、Nginx、MySQL、PHP)服务器,然后在其上部署 Drupal 8.
安装 Drupal 8 必备组件 - PHP 支持:
Drupal 8 需要 PHP 7.2 或者更高版本,这在标准 yum 存储库中不可用。
因此,首先我们必须在 CentOS 7 服务器上安装第三方 yum 存储库 Remi,然后我们将从 Remi 存储库安装 PHP 7.2.
[root@drupal-8-server ~]# rpm -ivh http://rpms.remirepo.net/enterprise/remi-release-7.rpm
为 Remi yum 存储库构建缓存。
[root@drupal-8-server ~]# yum makecache fast
现在,我们可以使用 yum 命令安装最新版本的 PHP。
[root@drupal-8-server ~]# yum install php72-php php72-php-mysqlnd php72-php-fpm php72-php-gd php72-php-xml php72-php-mbstring php72-php-pdo php72-php-opcache -y
为 Nginx 服务器配置 php-fpm。
[root@drupal-8-server ~]# vi /etc/opt/remi/php72/php-fpm.d/www.conf
其中查找并设置以下参数。
user = nginx group = nginx listen = /run/php-fpm/www.sock listen.owner = nginx listen.group = nginx
为 Unix 套接字创建目录并将所有者更改为 nginx 用户。
[root@drupal-8-server ~]# mkdir /run/php-fpm [root@drupal-8-server ~]# chown nginx /run/php-fpm
启用并启动 php-fpm 服务。
[root@drupal-8-server ~]# systemctl enable php72-php-fpm Created symlink from /etc/systemd/system/multi-user.target.wants/php72-php-fpm.service to /usr/lib/systemd/system/php72-php-fpm.service. [root@drupal-8-server ~]# systemctl start php72-php-fpm
我们的 CentOS 7 服务器上已安装 PHP 7.2.
安装 Drupal 8 必备组件 - Nginx Web 服务器:
Nginx 1.12.2 Web 服务器在 EPEL(企业 Linux 的另外包)yum 存储库中可用。
因此,首先我们必须安装 EPEL yum 存储库,然后我们将从 EPEL 安装 Nginx。
[root@drupal-8-server ~]# yum install -y epel-release
为 EPEL yum 存储库构建缓存。
[root@drupal-8-server ~]# yum makecache fast
现在,我们可以使用 yum 命令安装 Nginx。
[root@drupal-8-server ~]# yum install -y nginx
启用并启动 Nginx 服务。
[root@drupal-8-server ~]# systemctl enable nginx Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service. [root@drupal-8-server ~]# systemctl start nginx
在 Linux 防火墙中允许 HTTP 服务。
[root@drupal-8-server ~]# firewall-cmd --permanent --add-service=http success [root@drupal-8-server ~]# firewall-cmd --reload success
在 CentOS 7 上安装了 Nginx Web 服务器。
Drupal 8 系统要求
- 数据库服务器 - MariaDB 5.5.2 或者更高版本(带有 PDO 扩展)
- Web 服务器 - Nginx 0.7.x 或者更高版本
- PHP 支持 - PHP 7.2 或者更高版本(带有 OPCache)
