iT邦幫忙

第 11 屆 iThome 鐵人賽

DAY 15
0
自我挑戰組

30天學 LAMP 安裝系列 第 15

Day15 繼續調整 LAMP,為安裝 WordPress 做準備

  • 分享至 

  • xImage
  •  
  1. 安裝小工具

    $ sudo yum install vim wget -y
    
  2. 安裝 SELinux 相關工具

    $ sudo yum install policycoreutils-python -y
    
  3. 安裝 PHP 相關模組

    $ sudo yum install php-mysqlnd -y
    
  4. 建立 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
    
  5. 下載 WordPress 安裝套件

    $ cd /tmp && wget https://tw.wordpress.org/wordpress-5.2.3-zh_TW.tar.gz
    
  6. 解壓縮 WordPress 套件,產生 WordPress 資料夾,將會被擺放到 /var/www/html/ 目錄底下

    $ sudo tar -zxvf wordpress-5.2.3-zh_TW.tar.gz -C /var/www/html/
    
  7. 調整目錄擁有者

    $ sudo chown -R apache:apache /var/www/html/wordpress/
    
  8. 調整 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/
    
  9. 為 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>
    
  10. 重啟 Apache

$ sudo systemctl restart httpd
  1. 開啟瀏覽器,網址列輸入 (http://lab.example.com )

    https://ithelp.ithome.com.tw/upload/images/20190914/20119707BpPR3kOWeJ.png

  2. 開啟瀏覽器,網址列輸入 (http://wordpress.lab.example.com )

    https://ithelp.ithome.com.tw/upload/images/20190914/20119707xA48DIZ9oM.png

明日待續……

參考資料

  1. Install WordPress 5 with Apache, MariaDB 10 and PHP 7 on CentOS 7 (https://www.tecmint.com/install-wordpress-with-apache-on-centos-rhel-fedora/ )
  2. [CentOS 7] 整合 Apache、MySQL、PHP 7 組成 LAMP Server (http://blog.itist.tw/2016/01/installing-lamp-stack-with-centos-7-apache-mysql-php-7.html )
  3. [CentOS 7] 自己的部落格自己架,讓 Wordpress 幫你架好架滿 (http://blog.itist.tw/2016/01/install-wordpress-on-centos-7-with-lemp-stack.html )

上一篇
Day14 前面內容做個整理
下一篇
Day16 WordPress 簡單設定
系列文
30天學 LAMP 安裝33
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言