前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >服务器搭建WordPress个人博客网站

服务器搭建WordPress个人博客网站

作者头像
小雨coding
发布2020-06-09 14:22:23
1.7K0
发布2020-06-09 14:22:23
举报
文章被收录于专栏:小雨编程

WordPress 是世界上使用最广泛的博客系统之一,是一款开源的PHP软件。有丰富的插件模板资源,使用WordPress可以快速搭建独立的博客网站。

本教程软件环境基于CentOS 6.8 64位,从配置LNMP环境开始一步步搭建属于你自己的WordPress博客网站。

一. 配置LNMP环境

LNMP是Linux、Nginx、MySQL和PHP的缩写,是WordPress博客系统依赖的基础环境,我们首先需要准备LNMP环境。

1. 安装Nginx

使用yum安装Nginx:

代码语言:javascript
复制
yum install nginx -y

2.修改Nginx默认配置

去除对IPv6的监听,因为CentOS 6不支持IPv6,需要取消对IPv6地址的监听,否则Nginx不能成功启动。

a) 创建default.conf配置文件

代码语言:javascript
复制
touch /etc/nginx/conf.d/default.conf

b) 编辑配置文件

代码语言:javascript
复制
vi /etc/nginx/conf.d/default.conf

c) 配置文件示例代码

代码语言:javascript
复制
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) 修改完成后启动Nginx

代码语言:javascript
复制
nginx

e) 这篇教程中我的IP地址为114.115.162.204,浏览器访问该IP地址,查看服务器Nginx是否安装成功,

如果显示以上界面即表示Nginx已经安装成功。 f) 将Nginx设为开机自动启动:

代码语言:javascript
复制
chkconfig nginx on

3.安装MySQL

a) 使用yum安装MySQL:

代码语言:javascript
复制
yum install mysql-server -y

b) 安装完成后,启动MySQL服务:

代码语言:javascript
复制
service  mysqld restart

c) 设置MySQL账户root的密码:

我们这里设置root账户的密码为‘abc12345678’,你可以设置其它密码,但需要把这里的密码记住,后面的步骤还需要使用。

代码语言:javascript
复制
/usr/bin/mysqladmin -u root password 'abc12345678'

d) 将MySQL设置为开机自动启动

代码语言:javascript
复制
chkconfig mysqld on

4.安装PHP

a) 使用yum安装PHP:

代码语言:javascript
复制
yum install php-fpm php-mysql -y

b)安装完成后,启动PHP-FPM进程:

代码语言:javascript
复制
service php-fpm start

c) 查看php-fpm进程监听那个端口

代码语言:javascript
复制
netstat -nlpt | grep php-fpm

php-fpm默认监听9000端口

d) 将PHP-FPM设为开机自启动:

代码语言:javascript
复制
chkconfig php-fpm on

以上我们的LNMP环境就配置好了!

二、安装配置WordPress

1.安装WordPress

配置好LNMP环境后,使用yum安装WordPress

代码语言:javascript
复制
yum install wordpress -y

安装完成后,在目录\usr\share\wordpress目录下能看到WordPress的源码

2.配置数据库

a) 进入MySQL

代码语言:javascript
复制
mysql -uroot --password='abc12345678'

此时会进去MySQL编辑界面

b)为WordPress创建一个数据库

代码语言:javascript
复制
CREATE DATABASE wordpress;

c) 创建数据库完成,退出MySQL环境

代码语言:javascript
复制
exit

d) 把数据库配置同步到WordPress配置文件中: 编辑WordPress配置文件:

代码语言:javascript
复制
vi /etc/wordpress/wp-config.php

i进入编辑模式 参考配置文件如下:

代码语言:javascript
复制
<?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已经安装好了,这时我们配置Nginx,把请求转发给PHP-FPM来处理 a) 备份Nginx默认配置文件

代码语言:javascript
复制
cd /etc/nginx/conf.d/
mv default.conf default.conf.bak

b) 在Nginx配置文件中创建WordPress配置文件wordpress.conf

代码语言:javascript
复制
touch /etc/nginx/conf.d/wordpress.conf
vi /etc/nginx/conf.d/wordpress.conf

示例代码:

代码语言:javascript
复制
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

代码语言:javascript
复制
nginx -s reload

d)浏览器打开相应IP查看是否成功

定义好站点名、管理员用户名和密码后,浏览器中再次打开该IP地址

这样,你的WordPress就搭建成功啦~

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-04-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小雨编程 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一. 配置LNMP环境
  • 1. 安装Nginx
  • 2.修改Nginx默认配置
  • 3.安装MySQL
  • 4.安装PHP
  • 二、安装配置WordPress
  • 1.安装WordPress
  • 2.配置数据库
  • 3. 配置Nginx
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档