jialiguo 发表于 2015-8-21 13:00:15

CentOS 6.x配置WordPress(LNMP)

  一、实验环境:
  主机名               IP(Static)                   系统                                                    配置                              用途
wordpress         192.168.20.50      CentOS-6.4-x86_64-minimal          1CPU,1G RAM,20G DISK,1网卡         test

  **************************************************************************************
  二、配置步骤:
  1.关闭selinux和iptables:

  # vi /etc/selinux/config
  将SELINUX=enforcing修改为SELINUX=disabled
  # chkconfig iptables off
  # chkconfig ip6tables off
  # reboot
  2.下载wordpress,上传到root目录下:
  Wordpress下载地址:http://cn.wordpress.org/
  # ls
  anaconda-ks.cfginstall.loginstall.log.syslogwordpress-3.8-zh_CN.tar.gz
  3.安装Nginx源:
  # rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
  4.安装软件包支持:
  4.1.安装nginx:
  # yum -y install nginx
  4.2.安装mysql数据库:
  # yum -y install mysql-devel mysql-server
  4.3.安装PHP并支持mysql:
  # yum -y install php-fpm php-mysql php-gd
  5.配置相关服务:
  5.1.配置mysql:
  (1).设置mysql数据库密码:
  # service mysqld start
  # mysqladmin -u root -p password 'rootpasswd'
  (2).创建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:

  # vi /etc/php-fpm.d/www.conf
  将:

  user = apache
  group = apache
  修改为:
  user = nginx
  group = nginx
  保存退出;
  5.3.配置nginx:
  # vi /etc/nginx/conf.d/default.conf
  
  server {
      listen       80;
      server_namelocalhost;
  

      #charset koi8-r;
      #access_log/var/log/nginx/log/host.access.logmain;
  

      location / {
        #更改网站根目录下
        root   /var/www/html/wordpress;
        #添加php默认页面
        indexindex.php index.html index.htm;
  

        #启用伪静态规则,可以支持自定义链接和日志别名
        if (!-e $request_filename)
        {
        rewrite ^/(.+)$ /index.php last;
        }
  

      }
  

      #error_page404            /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_indexindex.php;
           fastcgi_paramSCRIPT_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 {
      #    denyall;
      #}
  }
  注意:红色标记部分为修改部分,请仔细核对;

  5.4.配置WordPress:
  (1).将tar.gz解压:
  # ls
  anaconda-ks.cfginstall.loginstall.log.syslogwordpress-3.8-zh_CN.tar.gz
  # tar -zxvf wordpress-3.8-zh_CN.tar.gz
  # ls
  anaconda-ks.cfginstall.loginstall.log.syslogwordpress wordpress-3.8-zh_CN.tar.gz
  (2).将wordpress放置/var/www/html目录下:
  # mkdir -p /var/www/html
  # cd /var/www/html
  # mv ~/wordpress ./
  (3).设置wordpress的所有者和权限:
  # chown -R nginx:nginx /var/www/html/wordpress
  # chmod -R 755 /var/www/html/wordpress
  (4).修改wordpress配置文件:
  # cd wordpress/
  # mv wp-config-sample.php wp-config.php
  # 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.启动服务并设置为自启动:
# service mysqld restart
  # service php-fpm start
  # service nginx start
  # chkconfig mysqld on
  # chkconfig php-fpm on
  # chkconfig nginx on
  7.初始化WordPress:
  浏览器中输入http://192.168.20.50,回车:
  
http://c.hiphotos.bdimg.com/album/pic/item/dc54564e9258d10929ab95cfd358ccbf6c814d06.jpg
  配置完毕;

  

  

  

  
页: [1]
查看完整版本: CentOS 6.x配置WordPress(LNMP)