在 RHEL、CentOS 及 Fedora 上安装 Drupal 8
Drupal 是一个开源,灵活,高度可拓展和安全的内容管理系统Content Management System(CMS),使用户轻松的创建网站。
它可以使用模块拓展,使用户将内容管理转换为强大的数字解决方案。
Drupal 运行在诸如 Apache、IIS、Lighttpd、Cherokee、Nginx 的 Web 服务器上,后端数据库可以使用 MySQL、MongoDB、MariaDB、PostgreSQL、MSSQL Server。
在这篇文章中, 我们会展示在 RHEL 7/6、CentOS 7/6 和 Fedora 20-25 发行版上使用 LAMP 架构,如何手动安装和配置 Drupal 8。
Drupal 需求:
- Apache 2.x (推荐)
- PHP 5.5.9 或 更高 (推荐 PHP 5.5)
- MySQL 5.5.3 或 MariaDB 5.5.20 与 PHP 数据对象(PDO) 支持
安装过程中,我使用 drupal.tecmint.com
作为网站主机名,IP 地址为 192.168.0.104
。你的环境也许与这些设置不同,因此请适当做出更改。
步骤 1:安装 Apache Web 服务器
1、 首先我们从官方仓库开始安装 Apache Web 服务器。
<span class="com">#</span><span class="kwd">yum</span><span class="pln"> install httpd</span>
2、 安装完成后,服务开始是被禁用的,因此我们需要手动启动它,同时让它下次系统启动时自动启动,如下:
<span class="pun">-------------</span><span class="pun">通过</span><span class="typ">SystemD</span><span class="pun">-</span><span class="typ">CentOS</span><span class="pun">/</span><span class="pln">RHEL </span><span class="lit">7</span><span class="pun">和</span><span class="typ">Fedora</span><span class="lit">22</span><span class="pun">+</span><span class="pun">-------------------</span>
<span class="com">#</span><span class="kwd">systemctl</span><span class="pln"> start httpd </span>
<span class="com">#</span><span class="kwd">systemctl</span><span class="pln"> enable httpd</span>
<span class="pun">-------------</span><span class="pun">通过</span><span class="typ">SysVInit</span><span class="pun">-</span><span class="typ">CentOS</span><span class="pun">/</span><span class="pln">RHEL </span><span class="lit">6</span><span class="pun">和</span><span class="typ">Fedora</span><span class="pun">----------------------</span>
<span class="com">#</span><span class="pln"> service httpd start</span>
<span class="com">#</span><span class="pln"> chkconfig </span><span class="pun">--</span><span class="pln">level </span><span class="lit">35</span><span class="pln"> httpd on</span>
3、 接下来,为了允许通过 HTTP 和 HTTPS 访问 Apache 服务,我们必须打开 HTTPD 守护进程正在监听的 80 和 443 端口,如下所示:
<span class="pun">------------</span><span class="pun">通过</span><span class="typ">Firewalld</span><span class="pun">-</span><span class="typ">CentOS</span><span class="pun">/</span><span class="pln">RHEL </span><span class="lit">7</span><span class="kwd">and</span><span class="typ">Fedora</span><span class="lit">22</span><span class="pun">+</span><span class="pun">-------------</span>
<span class="com">#</span><span class="pln"> firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="pln">zone</span><span class="pun">=</span><span class="kwd">public</span><span class="pun">--</span><span class="pln">add</span><span class="pun">-</span><span class="pln">service</span><span class="pun">=</span><span class="pln">http</span>
<span class="com">#</span><span class="pln"> firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">permanent </span><span class="pun">--</span><span class="pln">zone</span><span class="pun">=</span><span class="kwd">public</span><span class="pun">--</span><span class="pln">add</span><span class="pun">-</span><span class="pln">service</span><span class="pun">=</span><span class="pln">https</span>
<span class="com">#</span><span class="pln"> firewall</span><span class="pun">-</span><span class="pln">cmd </span><span class="pun">--</span><span class="pln">reload</span>
<span class="pun">------------</span><span class="pun">通过</span><span class="typ">IPtables</span><span class="pun">-</span><span class="typ">CentOS</span><span class="pun">/</span><span class="pln">RHEL </span><span class="lit">6</span><span class="kwd">and</span><span class="typ">Fedora</span><span class="lit">22</span><span class="pun">+</span><span class="pun">-------------</span>
<span class="com">#</span><span class="pln"> iptables </span><span class="pun">-</span><span class="pln">A INPUT </span><span class="pun">-</span><span class="pln">p tcp </span><span class="pun">-</span><span class="pln">m tcp </span><span class="pun">--</span><span class="pln">dport </span><span class="lit">80</span><span class="pun">-</span><span class="pln">j ACCEPT</span>
<span class="com">#</span><span class="pln"> iptables </span><span class="pun">-</span><span class="pln">A INPUT </span><span class="pun">-</span><span class="pln">p tcp </span><span class="pun">-</span><span class="pln">m tcp </span><span class="pun">--</span><span class="pln">dport </span><span class="lit">443</span><span class="pun">-</span><span class="pln">j ACCEPT</span>
<span class="com">#</span><span class="pln"> service iptables save</span>
<span class="com">#</span><span class="pln"> service iptables restart</span>
4、 现在验证 Apache 是否正常工作, 打开浏览器在地址栏中输入 http://server_IP
, 输入你的服务器 IP 地址, 默认 Apache2 页面应出现,如下面截图所示:
Apache 默认页面
步骤 2: 安装 Apache PHP 支持
5、 接下来,安装 PHP 和 PHP 所需模块。
<span class="com">#</span><span class="kwd">yum</span><span class="pln"> install php php</span><span class="pun">-</span><span class="pln">mbstring php</span><span class="pun">-</span><span class="pln">gd php</span><span class="pun">-</span><span class="pln">xml php</span><span class="pun">-</span><span class="pln">pear php</span><span class="pun">-</span><span class="pln">fpm php</span><span class="pun">-</span><span class="pln">mysql php</span><span class="pun">-</span><span class="pln">pdo php</span><span class="pun">-</span><span class="pln">opcache</span>
重要: 假如你想要安装 PHP7, 你需要增加以下仓库:EPEL 和 Webtactic 才可以使用 yum 安装 PHP7.0:
<span class="pun">-------------</span><span class="typ">Install</span><span class="pln"> PHP </span><span class="lit">7</span><span class="kwd">in</span><span class="typ">CentOS</span><span class="pun">/</span><span class="pln">RHEL </span><span class="kwd">and</span><span class="typ">Fedora</span><span class="pun">-------------</span>
<span class="com">#</span><span class="pln"> rpm </span><span class="pun">-</span><span class="typ">Uvh</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm</span>
<span class="com">#</span><span class="pln"> rpm </span><span class="pun">-</span><span class="typ">Uvh</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//mirror.webtatic.com/yum/el7/webtatic-release.rpm</span>
<span class="com">#</span><span class="kwd">yum</span><span class="pln"> install php70w php70w</span><span class="pun">-</span><span class="pln">opcache php70w</span><span class="pun">-</span><span class="pln">mbstring php70w</span><span class="pun">-</span><span class="pln">gd php70w</span><span class="pun">-</span><span class="pln">xml php70w</span><span class="pun">-</span><span class="pln">pear php70w</span><span class="pun">-</span><span class="pln">fpm php70w</span><span class="pun">-</span><span class="pln">mysql php70w</span><span class="pun">-</span><span class="pln">pdo</span>
6、 接下来,要从浏览器得到关于 PHP 安装和配置完整信息,使用下面命令在 Apache 文档根目录 (/var/www/html
) 创建一个 info.php
文件。
<span class="com">#</span><span class="kwd">echo</span><span class="str">"<?php phpinfo(); ?>"</span><span class="pun">></span><span class="str">/var/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="kwd">info</span><span class="pun">.</span><span class="pln">php</span>
然后重启 HTTPD 服务器 ,在浏览器地址栏输入 http://server_IP/info.php
。
<span class="com">#</span><span class="kwd">systemctl</span><span class="pln"> restart httpd</span>
<span class="pun">或</span>
<span class="com">#</span><span class="pln"> service httpd restart</span>
验证 PHP 信息
步骤 3: 安装和配置 MariaDB 数据库
7、 请知晓, Red Hat Enterprise Linux/CentOS 7.0 从支持 MySQL 转为了 MariaDB 作为默认数据库管理系统。
要安装 MariaDB 数据库, 你需要添加 官方 MariaDB 库 到 /etc/yum.repos.d/MariaDB.repo
中,如下所示。
<span class="pun">[</span><span class="pln">mariadb</span><span class="pun">]</span>
<span class="pln">name </span><span class="pun">=</span><span class="typ">MariaDB</span>
<span class="pln">baseurl </span><span class="pun">=</span><span class="pln"> http</span><span class="pun">:</span><span class="com">//yum.mariadb.org/10.1/centos7-amd64</span>
<span class="pln">gpgkey</span><span class="pun">=</span><span class="pln">https</span><span class="pun">:</span><span class="com">//yum.mariadb.org/RPM-GPG-KEY-MariaDB</span>
<span class="pln">gpgcheck</span><span class="pun">=</span><span class="lit">1</span>
当仓库文件准备好后,你可以像这样安装 MariaDB:
<span class="com">#</span><span class="kwd">yum</span><span class="pln"> install mariadb</span><span class="pun">-</span><span class="pln">server mariadb</span>
8、 当 MariaDB 数据库安装完成,启动数据库的守护进程,同时使它能够在下次启动后自动启动。
<span class="pun">-------------</span><span class="pun">通过</span><span class="typ">SystemD</span><span class="pun">-</span><span class="typ">CentOS</span><span class="pun">/</span><span class="pln">RHEL </span><span class="lit">7</span><span class="kwd">and</span><span class="typ">Fedora</span><span class="lit">22</span><span class="pun">+</span><span class="pun">-------------</span>
<span class="com">#</span><span class="kwd">systemctl</span><span class="pln"> start mariadb</span>
<span class="com">#</span><span class="kwd">systemctl</span><span class="pln"> enable mariadb</span>
<span class="pun">-------------</span><span class="pun">通过</span><span class="typ">SysVInit</span><span class="pun">-</span><span class="typ">CentOS</span><span class="pun">/</span><span class="pln">RHEL </span><span class="lit">6</span><span class="kwd">and</span><span class="typ">Fedora</span><span class="pun">-------------</span>
<span class="com">#</span><span class="pln"> service mysqld start</span>
<span class="com">#</span><span class="pln"> chkconfig </span><span class="pun">--</span><span class="pln">level </span><span class="lit">35</span><span class="pln"> mysqld on</span>
9、 然后运行 mysql_secure_installation
脚本去保护数据库(设置 root 密码, 禁用远程登录,移除测试数据库并移除匿名用户),如下所示:
<span class="com">#</span><span class="pln"> mysql_secure_installation</span>
MySQL 安全安装
步骤 4: 在 CentOS 中安装和配置 Drupal 8
10、 这里我们使用 wget 命令 下载最新版本 Drupal(例如 8.2.6),如果你没有安装 wget 和 gzip 包 ,请使用下面命令安装它们:
<span class="com">#</span><span class="kwd">yum</span><span class="pln"> install </span><span class="kwd">wget</span><span class="pln"> gzip</span>
<span class="com">#</span><span class="kwd">wget</span><span class="pun">-</span><span class="pln">c https</span><span class="pun">:</span><span class="com">//ftp.drupal.org/files/projects/drupal-8.2.6.tar.gz</span>
11、 之后,解压 tar 文件 并移动 Drupal 目录到 Apache 文档根目录(/var/www/html
)。
<span class="com">#</span><span class="kwd">tar</span><span class="pun">-</span><span class="pln">zxvf drupal</span><span class="pun">-</span><span class="lit">8.2</span><span class="pun">.</span><span class="lit">6.tar</span><span class="pun">.</span><span class="pln">gz</span>
<span class="com">#</span><span class="kwd">mv</span><span class="pln"> drupal</span><span class="pun">-</span><span class="lit">8.2</span><span class="pun">.</span><span class="lit">6</span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">drupal</span>
12、 然后,依据 /var/www/html/drupal/sites/default
目录下的示例设置文件 default.settings.php
,创建设置文件 settings.php
,然后给 Drupal 站点目录设置适当权限,包括子目录和文件,如下所示:
<span class="com">#</span><span class="kwd">cd</span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">drupal</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">/</span><span class="kwd">default</span><span class="pun">/</span>
<span class="com">#</span><span class="kwd">cp</span><span class="kwd">default</span><span class="pun">.</span><span class="pln">settings</span><span class="pun">.</span><span class="pln">php settings</span><span class="pun">.</span><span class="pln">php</span>
<span class="com">#</span><span class="kwd">chown</span><span class="pun">-</span><span class="pln">R apache</span><span class="pun">:</span><span class="pln">apache </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">drupal</span><span class="pun">/</span>
13、 更重要的是在 /var/www/html/drupal/sites/
目录设置 SElinux 规则,如下:
<span class="com">#</span><span class="pln"> chcon </span><span class="pun">-</span><span class="pln">R </span><span class="pun">-</span><span class="pln">t </span><span class="typ">httpd_sys_content_rw_t</span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">html</span><span class="pun">/</span><span class="pln">drupal</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">/</span>
14、 现在我们必须为 Drupal 站点去创建一个用于管理的数据库和用户。
<span class="com">#</span><span class="pln"> mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
<span class="typ">Enter</span><span class="pln"> password</span><span class="pun">:</span>
<span class="typ">MySQL</span><span class="typ">Shell</span>
<span class="typ">Welcome</span><span class="pln"> to the </span><span class="typ">MariaDB</span><span class="pln"> monitor</span><span class="pun">.</span><span class="typ">Commands</span><span class="kwd">end</span><span class="kwd">with</span><span class="pun">;</span><span class="kwd">or</span><span class="pln"> \g</span><span class="pun">.</span>
<span class="typ">Your</span><span class="typ">MySQL</span><span class="pln"> connection </span><span class="kwd">id</span><span class="kwd">is</span><span class="lit">12</span>
<span class="typ">Server</span><span class="pln"> version</span><span class="pun">:</span><span class="lit">5.1</span><span class="pun">.</span><span class="lit">73</span><span class="typ">Source</span><span class="pln"> distribution</span>
<span class="typ">Copyright</span><span class="pun">(</span><span class="pln">c</span><span class="pun">)</span><span class="lit">2000</span><span class="pun">,</span><span class="lit">2016</span><span class="pun">,</span><span class="typ">Oracle</span><span class="pun">,</span><span class="typ">MariaDB</span><span class="typ">Corporation</span><span class="typ">Ab</span><span class="kwd">and</span><span class="pln"> others</span><span class="pun">.</span>
<span class="typ">Type</span><span class="str">'help;'</span><span class="kwd">or</span><span class="str">'\h'</span><span class="kwd">for</span><span class="pln"> help</span><span class="pun">.</span><span class="typ">Type</span><span class="str">'\c'</span><span class="pln"> to </span><span class="kwd">clear</span><span class="pln"> the current input statement</span><span class="pun">.</span>
<span class="pun">**</span><span class="typ">MySQL</span><span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> create database drupal</span><span class="pun">;**</span>
<span class="typ">Query</span><span class="pln"> OK</span><span class="pun">,</span><span class="lit">1</span><span class="pln"> row affected </span><span class="pun">(</span><span class="lit">0.00</span><span class="pln"> sec</span><span class="pun">)</span>
<span class="pun">**</span><span class="typ">MySQL</span><span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> create user ravi@localhost identified by </span><span class="str">'tecmint123'</span><span class="pun">;**</span>
<span class="typ">Query</span><span class="pln"> OK</span><span class="pun">,</span><span class="lit">0</span><span class="pln"> rows affected </span><span class="pun">(</span><span class="lit">0.00</span><span class="pln"> sec</span><span class="pun">)</span>
<span class="pun">**</span><span class="typ">MySQL</span><span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> grant all on drupal</span><span class="pun">.*</span><span class="pln"> to ravi@localhost</span><span class="pun">;**</span>
<span class="typ">Query</span><span class="pln"> OK</span><span class="pun">,</span><span class="lit">0</span><span class="pln"> rows affected </span><span class="pun">(</span><span class="lit">0.00</span><span class="pln"> sec</span><span class="pun">)</span>
<span class="pun">**</span><span class="typ">MySQL</span><span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> flush privileges</span><span class="pun">;**</span>
<span class="typ">Query</span><span class="pln"> OK</span><span class="pun">,</span><span class="lit">0</span><span class="pln"> rows affected </span><span class="pun">(</span><span class="lit">0.00</span><span class="pln"> sec</span><span class="pun">)</span>
<span class="pun">**</span><span class="typ">MySQL</span><span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="kwd">exit</span><span class="pun">**</span>
<span class="typ">Bye</span>
15、 最后,打开地址: http://server_IP/drupal/
开始网站的安装,选择你首选的安装语言然后点击保存以继续。
Drupal 安装语言
16、 下一步,选择安装配置文件,选择 Standard(标准),点击保存继续。
Drupal 安装配置文件
17、 在进行下一步之前查看并通过需求审查并启用 Clean URL
。
验证 Drupal 需求
现在在你的 Apache 配置下启用 Clean URL 的 Drupal。
<span class="com">#</span><span class="kwd">vi</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">httpd</span><span class="pun">/</span><span class="pln">conf</span><span class="pun">/</span><span class="pln">httpd</span><span class="pun">.</span><span class="pln">conf</span>
确保为默认根文档目录 /var/www/html
设置 AllowOverride All
,如下图所示:
在 Drupal 中启用 Clean URL
18、 当你为 Drupal 启用 Clean URL,刷新页面从下面界面执行数据库配置,输入 Drupal 站点数据库名,数据库用户和数据库密码。
当填写完所有信息点击保存并继续。
Drupal 数据库配置
若上述设置正确,Drupal 站点安装应该完成了,如下图界面。
Drupal 安装
19、 接下来配置站点为下面的设置(使用适用你的情况的值):
- 站点名称 – TecMint Drupal Site
- 站点邮箱地址 – [email protected]
- 用户名 – admin
- 密码 – ##########
- 用户的邮箱地址 – [email protected]
- 默认国家 – India
- 默认时区 – UTC
设置适当的值后,点击保存并继续完成站点安装过程。
Drupal 站点配置
20、下图显示的是通过 LAMP 成功安装的 Drupal 8 站点。
Drupal 站点面板
现在你可以点击增加内容,创建示例网页内容。
选项: 有些人使用 MySQL 命令行管理数据库不舒服,可以从浏览器界面 安装 PHPMYAdmin 管理数据库
浏览 Drupal 文档 : https://www.drupal.org/docs/8
就这样! 在这个文章, 我们展示了在 CentOS 7 上如何去下载、安装和使用基本配置来设置 LAMP 以及 Drupal 8。 欢迎就这个教程提供反馈,或提供给我们一些相关信息。
作者简介:
Aaron Kili 是 linux 和 F.O.S.S 爱好者,将成为 Linux 系统管理员,Web 开发者,目前是 TecMint 的原创作者,热爱计算机工作,并且坚信知识共享。
via: http://www.tecmint.com/install-drupal-in-centos-rhel-fedora/
作者:Aaron Kili 译者:imxieke 校对:jasminepeng