Installation Environment
- WordPress 4.9.6
- Oracle Linux 7.5
- Apache 2.4.6
- PHP 7.2 (minimal: 5.2.4+)
- MariaDB 10.3 (minimal: 5.0+)
Let’s get started.
Linux
安裝Oracle Linux 7 (Software Selection: Minimal Install)。
Installation
安裝所需系統套件。
1 |
yum install curl wget unzip policycoreutils-python |
Apache
Installation
安裝Apache 2.4。
1 2 |
yum install httpd systemctl enable httpd |
設定https.conf,啟用mod_rewrite。
1 |
sed -i /etc/httpd/conf/httpd.conf -e 's/AllowOverride None/AllowOverride All/g' |
如果網站通過reverse proxy,啟用X-Forwarded-For後,才能取得存取來源IP記錄。
1 |
sed -i /etc/httpd/conf/httpd.conf -e 's/%h/%{X-Forwarded-For}i/g' |
啟動Apache。
1 |
systemctl start httpd |
Firewall
開放對外http連線。
1 2 |
firewall-cmd --add-service=http --permanent systemctl restart firewalld |
MariaDB
Installation
新增MariaDB 10 YUM repo。
1 |
vi /etc/yum.repos.d/MariaDB10.repo |
1 2 3 4 5 6 7 |
# MariaDB 10.3 RedHat repository list - created 2018-05-29 19:40 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name=MariaDB baseurl=http://yum.mariadb.org/10.3/rhel7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 |
安裝MariaDB 10。
1 2 |
yum --enablerepo="mariadb" install MariaDB-server MariaDB-client systemctl enable mariadb |
啟動MariaDB,設定root密碼以及資料庫安全設定。
1 2 |
systemctl start mariadb mysql_secure_installation |
登入MariaDB。
1 |
mysql -u root -p |
建立資料庫及應用程式帳號。
資料庫名稱 | wordpress |
使用者帳號 | wordpress@localhost |
使用者密碼 | password |
資料庫權限 | 對wordpress資料庫所有操作權限(除了GRANT OPTION權限) |
1 2 3 4 5 |
create user wordpress; create database wordpress; GRANT ALL PRIVILEGES ON wordpress.* To 'wordpress'@'localhost' IDENTIFIED BY 'password'; flush privileges; quit; |
Firewall
本機連線,不需設定。
PHP
Installation
安裝PHP 7。
1 2 3 4 5 6 |
cd /etc/yum.repos.d mv public-yum-ol7.repo public-yum-ol7.repo.bak wget http://yum.oracle.com/public-yum-ol7.repo yum install yum-utils yum-config-manager --enable ol7_developer_php72 yum install php php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap |
重新啟動Apache。
1 |
systemctl restart httpd |
WordPress
Installation
下載WordPress及設定網站根目錄至/var/www/html/wordpress。
1 2 3 4 |
wget https://wordpress.org/latest.zip unzip latest.zip -d /var/www/html chown apache:apache -R /var/www/html/wordpress sed -i /etc/httpd/conf/httpd.conf -e 's/DocumentRoot \"\/var\/www\/html/&\/wordpress/g' |
重新啟動Apache。
1 |
systemctl restart httpd |
設定WordPress上傳目錄及讀寫權限。
1 2 3 4 |
mkdir /var/www/html/wordpress/wp-content/uploads chown apache:apache /var/www/html/wordpress/wp-content/uploads semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/wordpress/wp-content/uploads(/.*)?" restorecon -Rv /var/www/html/wordpress/wp-content/uploads |
引以為傲的五分鐘快速安裝。
暫時開放Apache可讀寫/var/www/html/wordpress權限。
1 |
chcon -t httpd_sys_rw_content_t /var/www/html/wordpress/ |
開啟並設定WordPress網站。
1 |
http://wordpress.example.com/ |
設定完成後,wp-config.php會產生於/var/www/html/wordpress目錄。
重置Apache讀寫權限。
1 |
restorecon -v /var/www/html/wordpress/ |
Done!
Reference
- Installing WordPress
https://codex.wordpress.org/Installing_WordPress - INSTALL WORDPRESS ON CENTOS 7 WITH SELINUX
https://techblog.jeppson.org/2016/10/install-wordpress-centos-7/ - PHP 7 for Oracle Linux
http://yum.oracle.com/oracle-linux-php.html - Secret key generator for wp-config.php
https://api.wordpress.org/secret-key/1.1/salt/