wordpress搭建

本教程以 Linux 系统 CentOS 6.1 为例,搭建一个 WordPress 个人站点,整体流程如下:

 

需要用到的工具和服务有:

主机:使用云服务器或vps。

域名:如果域名指向中国境内服务器的网站,须进行工信部备案, 然后解析映射到所购买的主机ip。

WinSCP和Xshell:用于远程主机的登录、编辑、上传文件。

步骤 一:搭建 LNMP 环境

LNMP 是 Linux、Nginx、MySQL 和 PHP 的缩写,这个组合是最常见的 Web 服务器的运行环境之一。在创建好云服务器实例之后,您可以开始进行 LNMP 环境搭建。

Linux:Linux 系统(本文为 CentOS 6.1);

Nginx:Web 服务器程序,用来解析 Web 程序;

MySQL:一个数据库管理系统;

PHP:Web 服务器生成网页的程序。

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) 创建wordpress所需的数据库

CREATE DATABASE <数据库名>;

(3) 创建新用户账号

GRANT ALL PRIVILEGES ON <数据库名>.* TO "用户名"@"localhost"IDENTIFIED BY "密码";

(4) 使配置立刻生效

FLUSH PRIVILEGES;

(5) 退出MySQL

EXIT

image

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 # 改成自己的映射到主机的域名

image

填写所需信息后, 点击”安装WordPress”后, 既可进入后台控制面板。

image

现在已经完成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;
}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值