1. 程式人生 > 其它 >Centos7搭建WordPress個人站點(整理)

Centos7搭建WordPress個人站點(整理)

本教程使用伺服器騰訊云云伺服器 CVM(以下簡稱 CVM),以 Linux 系統 CentOS 7.0以上為例,來完成 WordPress 搭建工作。

步驟一:建立並運行雲伺服器

  1. 根據個人需要購買雲伺服器。 並可以參照騰訊雲的建立指引建立 Linux 雲伺服器
  2. 伺服器建立成功後,登入騰訊雲管理控制檯可以檢視或編輯雲主機狀態

後續步驟將會用到以下資訊,請注意儲存: 雲主機使用者名稱和密碼; 雲主機公網 IP。 3、在控制檯操作欄可以直接登入伺服器,進入命令列視窗後,依次輸入雲主機的使用者名稱和密碼,就可連線到雲主機,進行後續操作

步驟二:安裝Apache伺服器

1、利用yum命令安裝Apache

yum -y install httpd

2、啟動httpd並且設定為開機啟動

systemctl start httpd.service
systemctl enable httpd.service

3、安裝firewall

yum -y install firewalld firewall-config
systemctl start firewalld.service
systemctl enable firewalld.service

4、配置firewall

firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

步驟三:安裝MariaDB

1、利用yum命令進行安裝,並配置開機啟動

yum -y install mariadb-server mariadb
systemctl start mariadb.service
systemctl enable mariadb.service

2、配置root密碼

mysql_secure_installation

具體有以下幾個選項,可以根據各自情況進行配置(建議全部選Y)

Enter current password for root (enter for none):(輸入原始root密碼,若無則按enter)
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation. 
Set root password? [Y/n] (按Y設定root密碼)
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove anonymous users? [Y/n] (按Y移除匿名使用者)
 ... Success!

Disallow root login remotely? [Y/n] (按Y禁止遠端root登陸,一般root都設定為只允許本地登陸)
 ... skipping.

Remove test database and access to it? [Y/n] (按Y刪除測試資料庫)

Reload privilege tables now? [Y/n] (按Y重新載入)
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

步驟四:安裝PHP

1、首先下載PHP及常用元件,同樣運用yum命令

yum -y install php

2、檢視下載的所有元件

yum search php

3、安裝需要的元件

yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

4、新建一個php頁面檢視安裝的元件 vi /var/www/html/info.php 按字母i或insert鍵進入編輯模式,編輯為以下內容

<?php
phpinfo();
?>

編輯完成後鍵入“Esc:wq”,儲存檔案並退回到命令列模式

5、重啟httpd服務

systemctl restart httpd.service

6、在瀏覽器開啟網址http://x.x.x.x/info.php進行檢視(x.x.x.x為你的伺服器公網IP)

步驟五:配置資料庫

1、登陸MariaDB為WordPress建立資料庫及使用者

mysql -u root -p

2、新建資料庫wordpressdb,使用者為wordpressuser,密碼為123456

CREATE DATABASE wordpressdb;
CREATE USER wordpressuser@localhost IDENTIFIED BY '123456';

3、更改使用者許可權,儲存並退出

GRANT ALL PRIVILEGES ON wordpressdb.* TO wordpressuser@localhost;
FLUSH PRIVILEGES;
exit

4、重啟相關服務

systemctl restart httpd.service
systemctl restart  mariadb.service

步驟六:安裝WordPress

1、新建一個資料夾,此處取名wp

mkdir wp
cd wp
yum -y install wget unzip net-tools
wget http://wordpress.org/latest.zip

2、解壓檔案,並且將其複製到/var/www/html目錄下

unzip -q latest.zip
cp -rf wordpress/* /var/www/html/

3、修改資料夾許可權

chown -R apache:apache /var/www/html/
chmod -R 755 /var/www/html/
mkdir -p /var/www/html/wp-content/uploads
chown -R :apache /var/www/html/wp-content/uploads

4、編輯配置檔案

cd /var/www/html
cp wp-config-sample.php wp-config.php 
vi wp-config.php

開啟檔案後,按i鍵或insert鍵進入編輯模式,將其修改為以下格式(其中wordpressdb為資料庫名稱,wordpressuser為資料庫使用者名稱,123456為資料庫密碼)

// * MySQL settings - You can get this info from your web host * // 
/* The name of the database for WordPress / 
define(‘DB_NAME’, ‘wordpressdb’);

/* mysql database username / 
define(‘DB_USER’, ‘wordpressuser’);

/* MySQL database password / 
define(‘DB_PASSWORD’, ‘123456’);

鍵入“Esc:wq”,存檔並退出

5、重啟相關服務

systemctl restart httpd.service
systemctl restart  mariadb.service

步驟七:WordPress的個人設定

登入 htttp://x.x.x.x/訪問你的部落格(x.x.x.x為你的伺服器公網IP),按照自己的喜好進行相關的設定。


參考素材:http://blog.csdn.net/keneuro/article/details/48543613 http://blog.csdn.net/keneuro/article/details/48575533 https://www.qcloud.com/community/article/883465