一、实验环境:
主机名 IP(Static) 系统 配置 用途
wordpress 192.168.20.50 CentOS-6.4-x86_64-minimal 1CPU,1G RAM,20G DISK,1网卡 test
**************************************************************************************
二、配置步骤:
1.关闭selinux和iptables:
[root@wordpress ~]# vi /etc/selinux/config
将SELINUX=enforcing修改为SELINUX=disabled
[root@wordpress ~]# chkconfig iptables off
[root@wordpress ~]# chkconfig ip6tables off
[root@wordpress ~]# reboot
2.下载wordpress,上传到root目录下:
Wordpress下载地址:http://cn.wordpress.org/
[root@wordpress ~]# ls
anaconda-ks.cfg install.log install.log.syslog wordpress-3.8-zh_CN.tar.gz
3.安装Nginx源:
[root@wordpress ~]# rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
4.安装软件包支持:
4.1.安装nginx:
[root@wordpress ~]# yum -y install nginx
4.2.安装mysql数据库:
[root@wordpress ~]# yum -y install mysql-devel mysql-server
4.3.安装PHP并支持mysql:
[root@wordpress ~]# yum -y install php-fpm php-mysql php-gd
5.配置相关服务:
5.1.配置mysql:
(1).设置mysql数据库密码:
[root@wordpress ~]# service mysqld start
[root@wordpress ~]# mysqladmin -u root -p password 'rootpasswd'
(2).创建wordpress数据库:
[root@wordpress ~]# mysql -uroot -prootpasswd
mysql> CREATE DATABASE wordpress; /*创建名为wordpress的数据库;*/
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'wppasswd'; /*创建一个用户名为wpuser密码为wppasswd的用户;*/
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser' IDENTIFIED BY 'wppasswd'; /*给wpuser用于授予wordpress数据库权限;*/
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; /*刷新数据库;*/
Query OK, 0 rows affected (0.00 sec)
mysql> quit; /*退出数据库;*/
5.2.配置php-fpm:
[root@wordpress ~]# vi /etc/php-fpm.d/www.conf
将:
user = apache
group = apache
修改为:
user = nginx
group = nginx
保存退出;
5.3.配置nginx:
[root@wordpress ~]# vi /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
#更改网站根目录下
root /var/www/html/wordpress;
#添加php默认页面
index index.php index.html index.htm;
#启用伪静态规则,可以支持自定义链接和日志别名
if (!-e $request_filename)
{
rewrite ^/(.+)$ /index.php last;
}
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html/wordpress;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#启用php-fpm支持
location ~ .php$ {
# root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/wordpress$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /.ht {
# deny all;
#}
}
注意:红色标记部分为修改部分,请仔细核对;
5.4.配置WordPress:
(1).将tar.gz解压:
[root@wordpress ~]# ls
anaconda-ks.cfg install.log install.log.syslog wordpress-3.8-zh_CN.tar.gz
[root@wordpress ~]# tar -zxvf wordpress-3.8-zh_CN.tar.gz
[root@wordpress ~]# ls
anaconda-ks.cfg install.log install.log.syslog wordpress wordpress-3.8-zh_CN.tar.gz
(2).将wordpress放置/var/www/html目录下:
[root@wordpress ~]# mkdir -p /var/www/html
[root@wordpress ~]# cd /var/www/html
[root@wordpress html]# mv ~/wordpress ./
(3).设置wordpress的所有者和权限:
[root@wordpress html]# chown -R nginx:nginx /var/www/html/wordpress
[root@wordpress html]# chmod -R 755 /var/www/html/wordpress
(4).修改wordpress配置文件:
[root@wordpress html]# cd wordpress/
[root@wordpress wordpress]# mv wp-config-sample.php wp-config.php
[root@wordpress wordpress]# vi wp-config.php
………………省略若干行………………
/ ** 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', 'wpuser');
/** MySQL database password */
define('DB_PASSWORD', 'wppasswd');
/** MySQL hostname */
define('DB_HOST', 'localhost');
………………省略若干行………………
6.启动服务并设置为自启动:
[root@wordpress ~]# service mysqld restart
[root@wordpress ~]# service php-fpm start
[root@wordpress ~]# service nginx start
[root@wordpress ~]# chkconfig mysqld on
[root@wordpress ~]# chkconfig php-fpm on
[root@wordpress ~]# chkconfig nginx on
7.初始化WordPress:
浏览器中输入http://192.168.20.50,回车:
配置完毕;