WordPress 是使用 PHP 語言開發的部落格網站平臺,使用者可以在支援 PHP 和 MySQL 資料庫的站群伺服器上架設屬於自己的網站。也可以把 WordPress 當作一個內容管理系統(CMS)來使用。 WordPress 是一款個人部落格網站系統,並逐步演化成一款內容管理系統站群軟體,它是使用 PHP 語言和 MySQL 資料庫開發的。使用者可以在支援 PHP 和 MySQL 資料庫的站群伺服器上使用自己的部落格網站。
環境說明:
在同一臺 WordPress 主機上實現 LAMP(Linux + Apache + MariaDB + PHP)
CentOS 7.3 、 Apache 2.4.6 、 MariaDB 5.5.52 、 PHP 5.4.16
1 安裝 LAMP
採用 yum 方式進行安裝 httpd 、 MariaDB 、 php 、 php-mysql,php-mysql 用來進行 php 和 MariaDB 資料庫的連線。
[root@CentOS7 ~]# yum install httpd mariadb-server php php-mysql -y
2 建立新的虛擬 WordPress 主機
(1)新增虛擬 WordPress 主機配置檔案
[root@CentOS7 ~]# vim /etc/httpd/conf.d/vhost.conf
DocumentRoot “/var/www/wordpress”
ServerName www.mywordpress.com
AllowOverride None
Require all granted
(2)建立所需目錄
[root@CentOS7 ~]# mkdir /var/www/wordpress
3 在虛擬 WordPress 主機主目錄/var/www/wordpress 下新建 index.php 檔案
[root@CentOS7 ~]# vim /var/www/wordpress/index.php
4 檢查語法並啟動 httpd 服務
(1)檢查語法
[root@CentOS7 ~]# httpd -t
Syntax OK
(2)啟動 httpd 服務
[root@CentOS7 ~]# systemctl start httpd.service
5 測試
在瀏覽器中輸入 www.mywordpress.com
可以看到 PHP 預設頁面已經成功顯示,說明測試成功
6 下載 wordpress 壓縮包,wordpress-4.7.4-zh_CN.tar.gz
(1)解壓縮
[root@CentOS7 ~]# tar -xf wordpress-4.7.4-zh_CN.tar.gz
(2)把解壓縮後得到的檔案(wordpress)複製到 DocumentRoot(/var/www/wordpress/)下
[root@CentOS7 ~]# cp -a wordpress /var/www/wordpress/
7 啟動 MariaDB 服務
[root@CentOS7 ~]# systemctl start mariadb
8 透過瀏覽器訪問 wordpress
在瀏覽器中輸入 http://www.mywordpress.com/wordpress
注意:配置 DNS 站群伺服器解析 www.test.com 為 192.168.29.100
或者 修改 windows 下的 C:WindowsSysteme32driversetchosts 檔案
192.168.29.100 www.test.com
可以看到已經出了 wordpress 頁面,可以點選 “現在就開始” 就行配置,也可以手動修改配置檔案
9 修改 wordpress 配置檔案
(1)進入 WordPress 目錄(/var/www/wordpress/wordpress/)
[root@CentOS7 ~]# cd /var/www/wordpress/wordpress/
(2)複製 cp wp-config-sample.phpWordPress 模板檔案為 wp-config.php,然後編輯
[root@CentOS7 ~]# vim /var/www/wordpress/wordpress/wp-config.php
// ** MySQL 設定 – 具體資訊來自您正在使用的 WordPress 主機 ** //
/** WordPress 資料庫的名稱 */
define(‘DB_NAME’, ‘wordpress’);
/** MySQL 資料庫使用者名稱 */
define(‘DB_USER’, ‘test1’);
/** MySQL 資料庫密碼 */
define(‘DB_PASSWORD’, ‘123456’);
/** MySQLWordPress 主機 */
define(‘DB_HOST’, ‘localhost’);
10 在資料庫中建立資料庫和使用者
(1)建立資料庫
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
(2)建立使用者
MariaDB [(none)]> create user ‘test1’@’localhost’ identified by ‘123456’;
Query OK, 0 rows affected (0.00 sec)
(3)給使用者授權
MariaDB [(none)]> grant all on wordpress.* to ‘test1’@’localhost’;
Query OK, 0 rows affected (0.01 sec)
11 再次訪問 WordPress
http://www.mywordpress.com/wordpress
填入相關資訊,就可以正常訪問部落格網站了。