搭建wordpress個人博客
本教程基于Centos6.8 64系統(tǒng)
一:準備 LNMP 環(huán)境
LNMP 是 Linux、Nginx羡鸥、MySQL 和 PHP 的縮寫忠寻,是 WordPress 博客系統(tǒng)依賴的基礎(chǔ)運行環(huán)境。我們先來準備 LNMP 環(huán)境
1.安裝 Nginx
使用 yum 安裝 Nginx:
yum install nginx -y
修改 /etc/nginx/conf.d/default.conf衷旅,去除對 IPv6 地址的監(jiān)聽[?]纵朋,可參考下面的示例:
server {
listen 80 default_server;
# listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
tips:只需在第三行前加個“#”號即可
修改完成后,啟動 Nginx
nginx
此時嘁锯,可訪問實驗機器外網(wǎng) HTTP 服務(wù)(http://<您的 CVM IP 地址>)來確認是否已經(jīng)安裝成功。
將 Nginx 設(shè)置為開機自動啟動:
chkconfig nginx on
2.安裝 MySQL
使用 yum 安裝 MySQL:
yum install mysql-server -y
安裝完成后蝗羊,啟動 MySQL 服務(wù)
service mysqld restart
設(shè)置 MySQL 賬戶 root 密碼
/usr/bin/mysqladmin -u root password 'MyPas$word4Word_Press'
ps:這里的root為用戶名仁锯,MyPas$word4Word_Press為密碼,可以自己修改野芒,但一定要記得双炕,后面我們需要使用
將 MySQL 設(shè)置為開機自動啟動:
chkconfig mysqld on
3.安裝 PHP
yum install php-fpm php-mysql -y
安裝之后,啟動 PHP-FPM 進程:
service php-fpm start
把 PHP-FPM 也設(shè)置成開機自動啟動:
chkconfig php-fpm on
CentOs 6 默認已經(jīng)安裝了 PHP-FPM 及 PHP-MYSQL,下面命令執(zhí)行的可能會提示已經(jīng)安裝
二:安裝 WordPress
配置好 LNMP 環(huán)境后趟济,繼續(xù)使用 yum 來安裝 WordPress:
yum install wordpress -y
安裝完成后咽笼,就可以在 /usr/share/wordpress 看到 WordPress 的源代碼了。
配置數(shù)據(jù)庫
進入 MySQL:
mysql -uroot --password='MyPas$word4Word_Press'
為 WordPress 創(chuàng)建一個數(shù)據(jù)庫:
CREATE DATABASE wordpress;
MySQL 部分設(shè)置完了媳纬,我們退出 MySQL 環(huán)境:
exit
把上述的 DB 配置同步到 WordPress 的配置文件中施掏,可參考下面的配置:
配置文件位置 /etc/wordpress/wp-config.php
示例代碼
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', 'MyPas$word4Word_Press');
只需將相應(yīng)的內(nèi)容修改即可
配置 Nginx
WordPress 已經(jīng)安裝完畢,我們配置 Nginx 把請求轉(zhuǎn)發(fā)給 PHP-FPM 來處理
首先素挽,重命名默認的配置文件:
cd /etc/nginx/conf.d/
mv default.conf defaut.conf.bak
在 /etc/nginx/conf.d 創(chuàng)建 wordpress.conf 配置狸驳,參考下面的內(nèi)容:
server {
listen 80;
root /usr/share/wordpress;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php index.php;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
配置后耙箍,通知 Nginx 進程重新加載:
nginx -s reload
準備域名和解析(bujiesih)
三:大功告成!
恭喜辩昆,您的 WordPress 博客已經(jīng)部署完成,您可以通過瀏覽器訪問博客查看效果遮斥。
通過IP地址查看:
博客訪問地址:http://<您的域名>/wp-admin/install.php
通過域名查看:
博客訪問地址:http://www.yourdomain.com/wp-admin/install.php,其中替換 www.yourdomain.com 為之前申請的域名尉辑。