WordPress 搭建我的博客/站點

本教程以 Linux 系統 CentOS 6.1 爲例,搭建一個 WordPress 我的站點,總體流程以下:php

須要用到的工具和服務有:html

  • 主機:使用雲服務器或vps。
  • 域名:若是域名指向中國境內服務器的網站,須進行工信部備案, 而後解析映射到所購買的主機ip。
  • WinSCP和Xshell:用於遠程主機的登陸、編輯、上傳文件。

步驟 一:搭建 LNMP 環境mysql

LNMP 是 Linux、Nginx、MySQL 和 PHP 的縮寫,這個組合是最多見的 Web 服務器的運行環境之一。在建立好雲服務器實例以後,您能夠開始進行 LNMP 環境搭建。nginx

Linux:Linux 系統(本文爲 CentOS 6.1);
Nginx:Web 服務器程序,用來解析 Web 程序;
MySQL:一個數據庫管理系統;
PHP:Web 服務器生成網頁的程序。複製代碼

1. 在主機上使用 Yum 安裝Nginx、MySQL、PHPweb

yum install nginx php php-fpm php-mysql mysql-server -y複製代碼

2. 將各軟件設置爲開機啓動:sql

chkconfig nginx on
chkconfig mysqld on
chkconfig php-fpm on複製代碼

3. 配置 Nginxshell

(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. 配置MSQLbash

(1) 啓動 MySQL 服務器

service mysqld start複製代碼

(2) 建立wordpress所需的數據庫

CREATE DATABASE <數據庫名>;複製代碼

(3) 建立新用戶帳號

GRANT ALL PRIVILEGES ON <數據庫名>.* 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. 建立新配置文件

(1) 將wp-config-sample.php文件複製一份,命名爲wp-config.php的文件。

cd wordpress/
cp wp-config-sample.php wp-config.php複製代碼

(2) 打開並編輯新建立的配置文件。

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', '數據庫名' );

/** 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安裝程序

在瀏覽器訪問如下網址,進入 WordPress的 安裝頁面:

http://www.xxxxx.com/wp-admin/install.php # 改爲本身的映射到主機的域名複製代碼

填寫所需信息後, 點擊」安裝WordPress」後, 既可進入後臺控制面板。

如今已經完成WordPress 博客站點的建立,並能夠發佈博客文章了。

備註:

(1) 在使用過程當中上傳附件時, 提示「wp-contents/uploads/ "沒有上級目錄的寫權限

解決方案: 修改wordpress的目錄權限爲777

chmod 777 -R /usr/local/www/wordpress # 改爲你的wordpress的目錄複製代碼

(2) 上傳主題或插件出現輸入ftp帳號的問題

解決方案: 在 wp-config.php 文件底部加入如下代碼

define("FS_METHOD", "direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);複製代碼

(3) Nginx 設置wordpress 僞靜態

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;     } }複製代碼
相關文章
相關標籤/搜索