在 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 服務器。
# yum install httpd
2、 安裝完成後,服務開始是被禁用的,因此我們需要手動啟動它,同時讓它下次係統啟動時自動啟動,如下:
------------- 通過 SystemD - CentOS/RHEL 7 和 Fedora 22+ -------------------
# systemctl start httpd
# systemctl enable httpd
------------- 通過 SysVInit - CentOS/RHEL 6 和 Fedora ----------------------
# service httpd start
# chkconfig --level 35 httpd on
3、 接下來,為了允許通過 HTTP 和 HTTPS 訪問 Apache 服務,我們必須打開 HTTPD 守護進程正在監聽的 80和 443 端口,如下所示:
------------ 通過 Firewalld - CentOS/RHEL 7 and Fedora 22+ -------------
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload
------------ 通過 IPtables - CentOS/RHEL 6 and Fedora 22+ -------------
# iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
# iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
# service iptables save
# service iptables restart
4、 現在驗證 Apache 是否正常工作, 打開瀏覽器在地址欄中輸入 https://server_IP
, 輸入你的服務器 IP 地址, 默認 Apache2 頁麵應出現,如下麵截圖所示:
Apache 默認頁麵
步驟 2: 安裝 Apache PHP 支持
5、 接下來,安裝 PHP 和 PHP 所需模塊。
# yum install php php-mbstring php-gd php-xml php-pear php-fpm php-mysql php-pdo php-opcache
重要: 假如你想要安裝 PHP7, 你需要增加以下倉庫:EPEL 和 Webtactic 才可以使用 yum 安裝 PHP7.0:
------------- Install PHP 7 in CentOS/RHEL and Fedora -------------
# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# yum install php70w php70w-opcache php70w-mbstring php70w-gd php70w-xml php70w-pear php70w-fpm php70w-mysql php70w-pdo
6、 接下來,要從瀏覽器得到關於 PHP 安裝和配置完整信息,使用下麵命令在 Apache 文檔根目錄 (/var/www/html
) 創建一個 info.php
文件。
# echo "<?php phpinfo(); ?>" > /var/www/html/info.php
然後重啟 HTTPD 服務器 ,在瀏覽器地址欄輸入 https://server_IP/info.php
。
# systemctl restart httpd
或
# service httpd restart
驗證 PHP 信息
步驟 3: 安裝和配置 MariaDB 數據庫
7、 請知曉, Red Hat Enterprise Linux/CentOS 7.0 從支持 MySQL 轉為了 MariaDB 作為默認數據庫管理係統。
要安裝 MariaDB 數據庫, 你需要添加 官方 MariaDB 庫 到 /etc/yum.repos.d/MariaDB.repo
中,如下所示。
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
當倉庫文件準備好後,你可以像這樣安裝 MariaDB:
# yum install mariadb-server mariadb
8、 當 MariaDB 數據庫安裝完成,啟動數據庫的守護進程,同時使它能夠在下次啟動後自動啟動。
------------- 通過 SystemD - CentOS/RHEL 7 and Fedora 22+ -------------
# systemctl start mariadb
# systemctl enable mariadb
------------- 通過 SysVInit - CentOS/RHEL 6 and Fedora -------------
# service mysqld start
# chkconfig --level 35 mysqld on
9、 然後運行 mysql_secure_installation
腳本去保護數據庫(設置 root 密碼, 禁用遠程登錄,移除測試數據庫並移除匿名用戶),如下所示:
# mysql_secure_installation
MySQL 安全安裝
步驟 4: 在 CentOS 中安裝和配置 Drupal 8
10、 這裏我們使用 wget 命令 下載最新版本 Drupal(例如 8.2.6),如果你沒有安裝 wget 和 gzip 包 ,請使用下麵命令安裝它們:
# yum install wget gzip
# wget -c https://ftp.drupal.org/files/projects/drupal-8.2.6.tar.gz
11、 之後,解壓 tar 文件 並移動 Drupal 目錄到 Apache 文檔根目錄(/var/www/html
)。
# tar -zxvf drupal-8.2.6.tar.gz
# mv drupal-8.2.6 /var/www/html/drupal
12、 然後,依據 /var/www/html/drupal/sites/default
目錄下的示例設置文件 default.settings.php
,創建設置文件 settings.php
,然後給 Drupal 站點目錄設置適當權限,包括子目錄和文件,如下所示:
# cd /var/www/html/drupal/sites/default/
# cp default.settings.php settings.php
# chown -R apache:apache /var/www/html/drupal/
13、 更重要的是在 /var/www/html/drupal/sites/
目錄設置 SElinux 規則,如下:
# chcon -R -t httpd_sys_content_rw_t /var/www/html/drupal/sites/
14、 現在我們必須為 Drupal 站點去創建一個用於管理的數據庫和用戶。
# mysql -u root -p
Enter password:
MySQL Shell
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
**MySQL [(none)]> create database drupal;**
Query OK, 1 row affected (0.00 sec)
**MySQL [(none)]> create user ravi@localhost identified by 'tecmint123';**
Query OK, 0 rows affected (0.00 sec)
**MySQL [(none)]> grant all on drupal.* to ravi@localhost;**
Query OK, 0 rows affected (0.00 sec)
**MySQL [(none)]> flush privileges;**
Query OK, 0 rows affected (0.00 sec)
**MySQL [(none)]> exit**
Bye
15、 最後,打開地址: https://server_IP/drupal/
開始網站的安裝,選擇你首選的安裝語言然後點擊保存以繼續。
Drupal 安裝語言
16、 下一步,選擇安裝配置文件,選擇 Standard(標準),點擊保存繼續。
Drupal 安裝配置文件
17、 在進行下一步之前查看並通過需求審查並啟用 Clean URL
。
驗證 Drupal 需求
現在在你的 Apache 配置下啟用 Clean URL 的 Drupal。
# vi /etc/httpd/conf/httpd.conf
確保為默認根文檔目錄 /var/www/html
設置 AllowOverride All
,如下圖所示:
在 Drupal 中啟用 Clean URL
18、 當你為 Drupal 啟用 Clean URL,刷新頁麵從下麵界麵執行數據庫配置,輸入 Drupal 站點數據庫名,數據庫用戶和數據庫密碼。
當填寫完所有信息點擊保存並繼續。
Drupal 數據庫配置
若上述設置正確,Drupal 站點安裝應該完成了,如下圖界麵。
Drupal 安裝
19、 接下來配置站點為下麵的設置(使用適用你的情況的值):
- 站點名稱 – TecMint Drupal Site
- 站點郵箱地址 – admin@tecmint.com
- 用戶名 – admin
- 密碼 – ##########
- 用戶的郵箱地址 – admin@tecmint.com
- 默認國家 – India
- 默認時區 – UTC
設置適當的值後,點擊保存並繼續完成站點安裝過程。
Drupal 站點配置
20、下圖顯示的是通過 LAMP 成功安裝的 Drupal 8 站點。
Drupal 站點麵板
原文發布時間為:2017-04-22
本文來自雲棲社區合作夥伴“Linux中國”
最後更新:2017-05-22 14:32:25