安裝小工具
$ sudo yum install vim wget -y
安裝 SELinux 相關工具
$ sudo yum install policycoreutils-python -y
安裝 PHP 相關模組
$ sudo yum install php-mysqlnd -y
建立 WordPress 用的 MariaDB 資料庫
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
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)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> create user wordpress@localhost identified by 'password';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on wordpress.* to wordpress@localhost;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| wordpress |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> select host, user, password from user where user='wordpress';
+-----------+-----------+-------------------------------------------+
| host | user | password |
+-----------+-----------+-------------------------------------------+
| localhost | wordpress | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
+-----------+-----------+-------------------------------------------+
1 row in set (0.01 sec)
MariaDB [mysql]> show grants for wordpress@localhost;
+------------------------------------------------------------------------------------------------------------------+
| Grants for wordpress@localhost |
+------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'wordpress'@'localhost' IDENTIFIED BY PASSWORD '*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19' |
| GRANT ALL PRIVILEGES ON `wordpress`.* TO 'wordpress'@'localhost' |
+------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
MariaDB [mysql]> exit
Bye
下載 WordPress 安裝套件
$ cd /tmp && wget https://tw.wordpress.org/wordpress-5.2.3-zh_TW.tar.gz
解壓縮 WordPress 套件,產生 WordPress 資料夾,將會被擺放到 /var/www/html/ 目錄底下
$ sudo tar -zxvf wordpress-5.2.3-zh_TW.tar.gz -C /var/www/html/
調整目錄擁有者
$ sudo chown -R apache:apache /var/www/html/wordpress/
調整 wordpress 資料夾的 SELinux 設定
$ sudo semanage fcontext -a -t httpd_sys_content_t '/var/www/html/wordpress(/.*)?'
$ sudo restorecon -RFvv /var/www/html/wordpress
$ ls -aldZ /var/www/html/wordpress/
drwxr-xr-x. apache apache system_u:object_r:httpd_sys_content_t:s0 /var/www/html/wordpress/
為 WordPress 建立 Apache 的 Virtual Host
$ sudo vim /etc/httpd/conf.d/00-default-vhost.conf
#### 內容如下: ####
<Directory "/var/www/html">
Require all granted
</Directory>
<VirtualHost _default_:80>
ServerName www.lab.example.com
ServerAlias lab.example.com
DocumentRoot /var/www/html
CustomLog "logs/default-vhost.log" combined
</VirtualHost>
$ sudo vim /etc/httpd/conf.d/01-wordpress-vhost.conf
#### 內容如下: ####
<Directory "/var/www/html/wordpress">
Require all granted
</Directory>
<VirtualHost *:80>
ServerName wordpress.lab.example.com
ServerAlias wordpress
DocumentRoot /var/www/html/wordpress
CustomLog "logs/wordpress.log" combined
</VirtualHost>
重啟 Apache
$ sudo systemctl restart httpd
開啟瀏覽器,網址列輸入 (http://lab.example.com )
開啟瀏覽器,網址列輸入 (http://wordpress.lab.example.com )
明日待續……