此環(huán)境為一臺(tái)新的阿里云服務(wù)器,操作系統(tǒng)是Centos7龙屉,而且沒有替換任何yum源呐粘。
開始之前,我們需要了解一些環(huán)境,平臺(tái)環(huán)境為:
CentOS 7.5
Nginx 1.12.2
MySql 5.7
Php 7.2
Wordpress 4.9.4
/var/wordpress #為本次實(shí)驗(yàn)的“網(wǎng)站根目錄”(需手動(dòng)創(chuàng)建 mkdir -p /var/wordpress)
運(yùn)行網(wǎng)站賬戶使用“nginx”賬戶(Nginx 程序安裝后自動(dòng)生成該賬戶)
數(shù)據(jù)庫名為:“wpdb”转捕,Wordpress調(diào)用數(shù)據(jù)庫用戶為:“slevin”作岖,密碼為:“Slevin@123456”(注意這不是我們管理MySql的管理賬戶!)
我的網(wǎng)站域名為 "t1.xiaoxiangti.com"(若無域名可使用公網(wǎng) IP 地址代替)
安裝所需程序
yum install -y nginx mariadb mariadb-server php php-fpm php-mysql
安裝開發(fā)工具包
- 可先通過
yum grouplist
查看一下安裝列表,這里我們只安裝其中一個(gè)開發(fā)工具包Developmennt Tools
yum groupinstall 'Development Tools' -y
配置 Nginx 服務(wù)
- 一般nginx的默認(rèn)配置目錄是
/etc/nginx/conf.d/
五芝,這里我們新建一個(gè)配置文件
vim /etc/nginx/conf.d/web.conf
- 并在web.conf 文件中寫入以下內(nèi)容,注意
server_name t1.xiaoxiangti.com;
為你的域名痘儡。
#======================== WEB options ============================
server {
listen 80;
server_name t1.xiaoxiangti.com;
root /var/wordpress;
index index.php index.html;
charset utf-8;
#======================== Pseudo static ==========================
location / {
if (-f $request_filename/index.html){ rewrite (.*) $1/index.html break; }
if (-f $request_filename/index.php){ rewrite (.*) $1/index.php; }
if (!-f $request_filename){ rewrite (.*) /index.php; }
}
#======================== PHP options ============================
location ~ \.php {
root /var/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#======================== Error page =============================
error_page 400 403 404 /40x.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
最后啟動(dòng)nginx服務(wù),并設(shè)為開機(jī)啟動(dòng)
systemctl start nginx
systemctl enable nginx
mysql數(shù)據(jù)庫配置
這里我們安裝的是mariadb,它是mysql的一個(gè)分支枢步,但幾乎是完全兼容mysql的沉删。有一點(diǎn)不同,啟動(dòng)mysql服務(wù)的命令是systemctl start mysqld
醉途,但mariadb是systemctl start mariadb
矾瑰。
- 首先,啟動(dòng)mariadb服務(wù)
systemctl start mariadb
- 輸入
mysql
登錄數(shù)據(jù)庫后隘擎,創(chuàng)建wpdb
數(shù)據(jù)庫殴穴。
注意mysql模式下所有的命令后面都要加分號(hào)。
create database wpdb;
- 創(chuàng)建供wordpress調(diào)用數(shù)據(jù)庫的賬戶,這里賬戶名為“slevin”嵌屎,密碼為“Slevin@123456":
# mysql8以下及mariadb的版本
grant all privileges on wpdb.* to 'slevin'@'localhost' identified by 'Slevin@123456';
# mysql8及以上版本
create user 'slevin'@'localhost' identified by 'Slevin@123456';
grant all privileges on wpdb.* to 'slevin'@'localhost';
- 刷新表權(quán)限
flush privileges;
- 重啟mariadb服務(wù)推正,并且設(shè)為開機(jī)啟動(dòng)
systemctl restart mariadb
systemctl enable mariadb
配置 PHP 服務(wù)
- 使用vim編輯php的配置文件
vim /etc/php-fpm.d/www.conf
- 在 www.conf 文件中,修改user宝惰、group字段,一般默認(rèn)應(yīng)該是
apache
植榕,這里改為nginx
用戶運(yùn)行PHP服務(wù),方便之后權(quán)限規(guī)劃:
user = nginx
group = nginx
- 最后尼夺,啟動(dòng)php服務(wù),并設(shè)為開機(jī)啟動(dòng)
systemctl start php-fpm
systemctl enable php-fpm
安裝wordpess
依次執(zhí)行以下命令:
mkdir /var/wordpress && cd /var/wordpress/
wget https://cn.wordpress.org/latest-zh_CN.zip && unzip latest-zh_CN.zip
mv wordpress/* /var/wordpress/ && cd /var
chmod 755 -R wordpress
chown nginx:nginx -R wordpress
如果以上操作都沒問題的話尊残,這個(gè)時(shí)候訪問你的域名或者服務(wù)器的ip的ip地址,就會(huì)看到wordpress的安裝界面了淤堵。
安裝界面這里填入上面我們創(chuàng)建好的mysql賬戶即可寝衫。