搭建wordpress 博客站点—实战篇

环境说明

服务器IP:192.168.169.50
lnmp 搭建只在一台服务器 (建议mysql 数据库单独作为一台服务器,文章后面有详细介绍)
搭建wordpress ,基于lnmp 架构搭建,并实现以下图效果
这里写图片描述php

lnmp 的具体搭建可参考个人文章,注意页面信息必定到有mysql 的信息,可在页面搜索mysql
在mysql 里面建立一个用户chen并受权容许在192.168.169 网段登陆html

mysql> create user 'chenshuo'@'192.168.169.50' identified by 'chen';   //建立一个用户chenshuo
mysql>  grant all on *.* to 'chenshuo'@'%' identified by 'chen';    //这里我设置的受权能够在任何主机登陆
Query OK, 0 rows affected, 1 warning (0.00 sec)

创建db.php ,测试mysql 远程登陆mysql

[root@localhost ~]# vim /usr/local/nginx/html/db.php 
<?php
        $servername = "192.168.169.50";        //登陆到mysql服务器的IP
        $username = "chenshuo";                     //登陆到MySQl的用户
        $password = "chen";                      //登陆到mysql的密码

        $conn= mysqli_connect($servername,$username,$password);

        if (! $conn) {
                die("connection failed: " . mysqli_connect_error());
        }
        echo "create yes";
        ?>

在浏览器查看效果
这里写图片描述linux

下载wordpress,(可在官网下载安装包)nginx

[root@localhost ~]# cd /usr/src/
[root@localhost src]# unzip wordpress-4.9.4-zh_CN.zip 
[root@localhost src]# ls
debug                                       nginx-1.12.0         php-7.2.8.tar.xz
kernels                                     nginx-1.12.0.tar.gz  wordpress
mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz  php-7.2.8            wordpress-4.9.4-zh_CN.zip

拷贝wordpress 到 /usr/local/nginx/html/ 下面web

[root@localhost src]# cp -r wordpress/ /usr/local/nginx/html/

修改nginx 的主配置文件sql

[root@localhost src]# vim /usr/local/nginx/conf/nginx.conf
   server {
        listen       80;
        server_name  localhost;
        
        access_log  logs/access.log  main;
        location / {
            root   html/wordpress;          //修改这里的Url
            index  index.php index.html index.htm;
        }   
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }   
        
       location ~ \.php$ {
       root           html/wordpress;    //修改这里的url
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
       include        fastcgi_params;  
        }
    }   
    
}

检测nginx 语法,从新加载nginx配置文件数据库

[root@localhost src]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost src]# nginx -s reload

在浏览器上登陆nginx 服务器IP,安装wordpress,以下图所示vim

这里写图片描述

在数据库里面建立一个wordpress 库api

mysql> create database wordpress;
Query OK, 1 row affected (0.01 sec)

也能够经过远程的方式来测试

[root@localhost ~]# mysql -h 192.168.169.50 -uchenshuo -pchen

安装wordpress 所填的信息
这里写图片描述

这里写图片描述

建立wp-config.php 配置文件,并复制网站上面的内容

[root@localhost ~]# vim /usr/local/nginx/html/wordpress/wp-config.php
/** 数据库整理类型。如不肯定请勿更改 */
define('DB_COLLATE', '');

/**#@+
 * 身份认证密钥与盐。
 *
 * 修改成任意独一无二的字串!
 * 或者直接访问{@link https://api.wordpress.org/secret-key/1.1/salt/
 * WordPress.org密钥生成服务}
 * 任何修改都会致使全部cookies失效,全部用户将必须从新登陆。
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         '!/GbCcQLv7?+Cxmb~I<GX3W{p 5Mmn-ntUD2Ae_g6C_.~.GM%^PYBss~ho|D#x@s');
define('SECURE_AUTH_KEY',  'Kt[hosED{ygS(JX-&non9LiKhWyZf<ZI!V(-A9(#Io`!_g2reG{{5,WfW(c$0)Dj');
......如下省略,在网页上有所有的配置

配置完以上在刷新浏览器继续安装

这里写图片描述

填写如下信息,在安装下一步
这里写图片描述
安装出现这个页面就说明成功了
这里写图片描述

这里写图片描述

修改上传照片的大小的限制,默认只容许上传2M大小的图片

[root@localhost ~]# vim  /etc/php.ini
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 100M     //大小修改成100M
[root@localhost ~]# service php-fpm restart    //重启php-fpm
Gracefully shutting down php-fpm . done
Starting php-fpm  done

上传图片时,提示权限受到限制
正上传
5279f0d77c561.jpg 没法创建目录wp-content/uploads/2018/09。有没有上级目录的写权限?

[root@localhost ~]# cd /usr/local/nginx/html/wordpress/
[root@localhost wordpress]# chmod 777 -R wp-content/

能够查看数据库里面的信息

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| wordpress          |
+--------------------+
5 rows in set (0.06 sec)
mysql> use wordpress;
mysql> show tables;
+-----------------------+
| Tables_in_wordpress   |
+-----------------------+
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_termmeta           |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
+-----------------------+
12 rows in set (0.01 sec)

环境补充说明
nginx 提早安装完成这里是源码安装就再也不介绍,详细的nginx的搭建能够参照个人文章lnmp ,主配置文件/usr/local/nginx/conf/nginx.conf 和你的可能不太同样须要注意
mysql 单独在一台服务器

服务 IP
nginx +php 192.168.169.50
mysql 192.168.169.20

安装mariadb

[root@localhost yum.repos.d]# yum install -y mariadb mariadb-server
[root@nfs-client ~]# systemctl start mariadb 
[root@localhost yum.repos.d]# rpm -ql mariadb     
.....此处省略
/usr/bin/mysql_install_db
/usr/bin/mysql_plugin
/usr/bin/mysql_secure_installation      //找到这条命令
/usr/bin/mysql_setpermission
/usr/bin/mysql_tzinfo_to_sql
/usr/bin/mysql_upgrade
/usr/bin/mysql_zap
 .....此处省略

配置MySQL的 root密码

[root@localhost yum.repos.d]#mysql_secure_installation

受权用户chenshuo 在nginx-server 上登陆,用来链接php-fpm

[root@localhost yum.repos.d]# mysql -uroot -p
Enter password: 
MariaDB [(none)]> grant all on *.* to chenshuo@'192.168.169.50' identified by 'chen';
Query OK, 0 rows affected (0.00 sec)

在nginx-server 上,安装php

[root@nginx-server ~]# yum install php php-fpm -y

安装php和所需组件使php支持mysql、FastCGI模式

[root@localhost ~]# vim /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0            //修改成0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[root@nginx-server ~]# yum install -y php lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql
[root@nginx-server ~]# systemctl start php-fpm

在nginx 主网站建立链接mysql

[root@nginx-server ~]# vim /usr/local/nginx/html/db.php 
<?php
 $servername = "192.168.169.20";        //数据库服务器的IP
 $username = "chenshuo";            //访问数据库的用户名     
 $password = "chen";                //访问数据库密码
 $conn= mysqli_connect($servername,$username,$password);
 if (! $conn) { die("connection failed: " . mysqli_connect_error());
 }
 echo "create yes";
 ?>

注意nginx 主配置文件要开启php-fastcgi模块

[root@nginx-server ~]# vim /usr/local/nginx/conf/nginx.conf
  server {
        listen       80;
        server_name  localhost;

        access_log  logs/access.log  main;
        location / {
           root   html;
            index  index.php index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

       location ~ \.php$ {
       root           html;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;         //注意修改这一个位置
       include        fastcgi_params;
        }
[root@nginx-server ~]# nginx -t 
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx-server ~]# nginx -s reload

添加 php帮助信息作为测试页面

[root@localhost ~]# vim /usr/local/nginx/html/index.php
<?php
        phpinfo();
?>

访问服务器页面必需要有mysql 的页面信息,才能链接数据库
在这里插入图片描述

后面操做参照前面 下载wordprss 开始