本教程以 Linux 系統(tǒng) CentOS 6.1 為例屿脐,搭建一個 WordPress 個人站點,整體流程如下:
需要用到的工具和服務有:
主機:使用云服務器或vps。
域名:如果域名指向中國境內(nèi)服務器的網(wǎng)站丧荐,須進行工信部備案, 然后解析映射到所購買的主機ip。
WinSCP和Xshell:用于遠程主機的登錄喧枷、編輯虹统、上傳文件。
步驟 一:搭建 LNMP 環(huán)境
LNMP 是 Linux割去、Nginx窟却、MySQL 和 PHP 的縮寫,這個組合是最常見的 Web 服務器的運行環(huán)境之一呻逆。在創(chuàng)建好云服務器實例之后夸赫,您可以開始進行 LNMP 環(huán)境搭建。
Linux:Linux 系統(tǒng)(本文為 CentOS 6.1)咖城;
Nginx:Web 服務器程序茬腿,用來解析 Web 程序呼奢;
MySQL:一個數(shù)據(jù)庫管理系統(tǒng);
PHP:Web 服務器生成網(wǎng)頁的程序切平。
1. 在主機上使用 Yum 安裝Nginx握础、MySQL、PHP
yum install nginx php php-fpm php-mysql mysql-server -y
2. 將各軟件設置為開機啟動:
chkconfig nginx on
chkconfig mysqld on
chkconfig php-fpm on
3. 配置 Nginx
(1) 修改nginx的配置文件 /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name www.xxxxx.com;
root /usr/local/www/wordpress; #該目錄配置為wordpress解壓后的目錄
index index.php index.html index.htm;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php index.php;
}
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;
}
}
(2) 配置完后, 啟動nginx
service nginx start
4. 配置MSQL
(1) 啟動 MySQL 服務器
service mysqld start
(2) 創(chuàng)建wordpress所需的數(shù)據(jù)庫
CREATE DATABASE <數(shù)據(jù)庫名>;
(3) 創(chuàng)建新用戶賬號
GRANT ALL PRIVILEGES ON <數(shù)據(jù)庫名>.* TO "用戶名"@"localhost"IDENTIFIED BY "密碼";
(4) 使配置立刻生效
FLUSH PRIVILEGES;
(5) 退出MySQL
EXIT
5. 啟動 PHP-FPM 服務
service php-fpm start
步驟 二:下載WordPress, 并添加配置文件
在主機上選取一個目錄, 作為wordpress的存放目錄, 該教程選擇的目錄為: /usr/local/www/
1. 下載 WordPress中文版本
cd /usr/local/www
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
2. 解壓, 解壓后的文件名稱為 wordpress
tar zxvf latest-zh_CN.tar.gz
3. 創(chuàng)建新配置文件
(1) 將wp-config-sample.php文件復制一份,命名為wp-config.php的文件悴品。
cd wordpress/
cp wp-config-sample.php wp-config.php
(2) 打開并編輯新創(chuàng)建的配置文件禀综。
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', '數(shù)據(jù)庫名' );
/** MySQL database username */
define( 'DB_USER', '用戶名' );
/** MySQL database password */
define( 'DB_PASSWORD', '密碼' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
步驟 三:啟動WordPress安裝程序
在瀏覽器訪問以下網(wǎng)址,進入 WordPress的 安裝頁面:
http://www.xxxxx.com/wp-admin/install.php # 改成自己的映射到主機的域名
填寫所需信息后, 點擊”安裝WordPress”后, 既可進入后臺控制面板苔严。
現(xiàn)在已經(jīng)完成WordPress 博客站點的創(chuàng)建定枷,并可以發(fā)布博客文章了。
備注:
(1) 在使用過程中上傳附件時, 提示“wp-contents/uploads//沒有上級目錄的寫權限
解決方案: 修改wordpress的目錄權限為777
chmod 777 -R /usr/local/www/wordpress # 改成你的wordpress的目錄
(2) 上傳主題或插件出現(xiàn)輸入ftp賬號的問題
解決方案: 在 wp-config.php 文件底部加入以下代碼
define("FS_METHOD", "direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);
(3) Nginx 設置wordpress 偽靜態(tài)
server {
listen 80;
server_name www.XXXXXX.com;
root /usr/local/www/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
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;
}
}