WordPress 是世界上使用最廣泛的博客系統(tǒng)之一,是一款開源的PHP軟件义锥。有豐富的插件模板資源,使用WordPress可以快速搭建獨(dú)立的博客網(wǎng)站。
本教程軟件環(huán)境基于CentOS 6.8 64位姆坚,從配置LNMP環(huán)境開始一步步搭建屬于你自己的WordPress博客網(wǎng)站。
一. 配置LNMP環(huán)境
LNMP是Linux实愚、Nginx兼呵、MySQL和PHP的縮寫兔辅,是WordPress博客系統(tǒng)依賴的基礎(chǔ)環(huán)境,我們首先需要準(zhǔn)備LNMP環(huán)境击喂。
1. 安裝Nginx
使用yum
安裝Nginx:
yum install nginx -y
2.修改Nginx默認(rèn)配置:
去除對(duì)IPv6的監(jiān)聽维苔,因?yàn)镃entOS 6不支持IPv6,需要取消對(duì)IPv6地址的監(jiān)聽,否則Nginx不能成功啟動(dòng)懂昂。
a) 創(chuàng)建default.conf配置文件
touch /etc/nginx/conf.d/default.conf
b) 編輯配置文件
vi /etc/nginx/conf.d/default.conf
c) 配置文件示例代碼
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 {
}
}
d) 修改完成后啟動(dòng)Nginx
nginx
e) 這篇教程中我的IP地址為114.115.162.204介时,瀏覽器訪問該IP地址,查看服務(wù)器Nginx是否安裝成功凌彬,
如果顯示以上界面即表示Nginx已經(jīng)安裝成功沸柔。
f) 將Nginx設(shè)為開機(jī)自動(dòng)啟動(dòng):
chkconfig nginx on
3.安裝MySQL
a) 使用yum
安裝MySQL:
yum install mysql-server -y
b) 安裝完成后,啟動(dòng)MySQL服務(wù):
service mysqld restart
c) 設(shè)置MySQL賬戶root的密碼:
我們這里設(shè)置root賬戶的密碼為’abc12345678‘饿序,你可以設(shè)置其它密碼勉失,但需要把這里的密碼記住,后面的步驟還需要使用原探。
/usr/bin/mysqladmin -u root password 'abc12345678'
d) 將MySQL設(shè)置為開機(jī)自動(dòng)啟動(dòng)
chkconfig mysqld on
4.安裝PHP
a) 使用yum
安裝PHP:
yum install php-fpm php-mysql -y
b)安裝完成后乱凿,啟動(dòng)PHP-FPM進(jìn)程:
service php-fpm start
c) 查看php-fpm進(jìn)程監(jiān)聽那個(gè)端口
netstat -nlpt | grep php-fpm
php-fpm默認(rèn)監(jiān)聽9000端口
d) 將PHP-FPM設(shè)為開機(jī)自啟動(dòng):
chkconfig php-fpm on
以上我們的LNMP環(huán)境就配置好了!
二咽弦、安裝配置WordPress
1.安裝WordPress
配置好LNMP環(huán)境后徒蟆,使用yum
安裝WordPress
yum install wordpress -y
安裝完成后,在目錄\usr\share\wordpress
目錄下能看到WordPress的源碼
2.配置數(shù)據(jù)庫
a) 進(jìn)入MySQL
mysql -uroot --password='abc12345678'
此時(shí)會(huì)進(jìn)去MySQL編輯界面
b)為WordPress創(chuàng)建一個(gè)數(shù)據(jù)庫
CREATE DATABASE wordpress;
c) 創(chuàng)建數(shù)據(jù)庫完成型型,退出MySQL環(huán)境
exit
d) 把數(shù)據(jù)庫配置同步到WordPress配置文件中:
編輯WordPress配置文件:
vi /etc/wordpress/wp-config.php
按i
進(jìn)入編輯模式
參考配置文件如下:
<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the
* installation. You don't have to use the web site, you can
* copy this file to "wp-config.php" and fill in the values.
*
* This file contains the following configurations:
*
* * MySQL settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://codex.wordpress.org/Editing_wp-config.php
*
* @package WordPress
*/
// ** 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', 'abc12345678');
/** 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', '');
/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
/**#@-*/
/**
* WordPress Database Table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = 'wp_';
/**
* See http://make.wordpress.org/core/2013/10/25/the-definitive-guide-to-disabling-auto-updates-in-wordpress-3-7
*/
/* Disable all file change, as RPM base installation are read-only */
define('DISALLOW_FILE_MODS', true);
/* Disable automatic updater, in case you want to allow
above FILE_MODS for plugins, themes, ... */
define('AUTOMATIC_UPDATER_DISABLED', true);
/* Core update is always disabled, WP_AUTO_UPDATE_CORE value is ignore */
/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that can be used for debugging,
* visit the Codex.
*
* @link https://codex.wordpress.org/Debugging_in_WordPress
*/
define('WP_DEBUG', false);
/* That's all, stop editing! Happy blogging. */
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', '/usr/share/wordpress');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');
3. 配置Nginx
WordPress已經(jīng)安裝好了段审,這時(shí)我們配置Nginx,把請求轉(zhuǎn)發(fā)給PHP-FPM來處理
a) 備份Nginx默認(rèn)配置文件
cd /etc/nginx/conf.d/
mv default.conf default.conf.bak
b) 在Nginx配置文件中創(chuàng)建WordPress配置文件wordpress.conf
touch /etc/nginx/conf.d/wordpress.conf
vi /etc/nginx/conf.d/wordpress.conf
示例代碼:
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;
}
}
c) 配置成功后闹蒜,重新加載nginx
nginx -s reload
d)瀏覽器打開相應(yīng)IP查看是否成功
定義好站點(diǎn)名寺枉、管理員用戶名和密碼后,瀏覽器中再次打開該IP地址
這樣绷落,你的WordPress就搭建成功啦~