笔记——》wordpress(三):发布wordpress站点到linux服务器

摘要

前两篇笔记已经知道了什么是wordpress和做wordpress的内容采集。那么剩下的事情就是 把wordpress发布到服务器上线了。

步骤

wordpress 运行需要php、nginx环境。所以我们的服务器上需要有php环境,nginx环境。 这个基础环境配置,网上有很多教程,本篇不赘述了。由于不借助宝塔面板,我们需要做的有以下几点:

1、上传wordpres文件

  1. 首先,在服务器上新建一个目录,随便哪个位置都行,比如我的目录名叫 kuaJing
  2. 通过xftp工具把本地文件(phpEnv\www\localhost 路径下的)上传到服务器上,就是wordpress主目录及子目录所有文件

2、修改config配置文件

修改数据库连接配置,使之能连接到远程数据库。

config 复制代码
/** Database username */
define( 'DB_USER', 'root' );

/** Database password */
define( 'DB_PASSWORD', '123456' );

/** Database hostname */
define( 'DB_HOST', 'xxxx.mysql.rds.aliyuncs.com' );

/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

3,修改nginx配置

  1. 执行命令查看nginx安装路径where is nginx
  2. 通过上一步可以查到nginx的安装目录,cd 到安装目录的conf目录下,vim nginx.conf 文件
  3. 把下面的 配置添加到 nginx.conf文件中,一个conf文件是运行多个server的,别添加到另一个server区块里面了

其中:

  • server_name 是服务器的外网ip
  • root 是wordpress的目录
  • 其他的配置就直接复制,不用修改
config 复制代码
upstream php {
        server unix:/tmp/php-cgi.socket;
        server 127.0.0.1:9000;
	}

server {
        ## Your website name goes here.
        server_name 105.xxx.xxx.193;
        ## Your only path reference.
        root /root/build/kuaJing;
        ## This should be in your http block and if it is, it's not needed here.
        index index.php;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ .php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi_params;
                fastcgi_intercept_errors on;
                fastcgi_pass php;
                #The following parameter can be also included in fastcgi_params file
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
}

修改完之后执行命令,service nginx restart,nginx就会重启,此时我们在浏览器输入服务器ip,也就是上面配置的 server_name中的ip,就可以看到wordpress页面啦。

小问题解决

1、网址域名映射

我们正式上线后,如果要给站点做推广,直接丢过去一个ip地址,说访问这个ip就能看到网站,这肯定不合理的。我们需要用域名映射到这个ip,比如我是阿里云服务器,就可以

在阿里云控制台=》云解析DNS=》xxx.com(域名实例)=》解析设置=》添加记录

给ip套一个域名,就正规多了,以后就可以用域名访问wordpress了,此时可以说网站已上线。

2、域名跳转到localhost或host

当我们用域名跳转到wordpress首页时,此时在页面上 不论点哪个菜单还是按钮,都会跳到localhost上,这种情况下就要修改数据库配置了

mysql 复制代码
select * from wp_options where option_name in ('siteurl','home');

把通过上面的sql查询到的数据的option_value从 localhost或者ip 更新成 域名 即可。

3、文件权限

当我们在已经上线的网站上 上传媒体库文件或安装插件的时候,可能会提示 上传失败 或是安装失败。大概率是因为权限问题导致的 ,我们按照下面的配置操作,应该能解决问题

举个例子,假如我们到媒体库上传图片提示失败,那我们点到uploads目录,右键

点击其他、勾选写入、点击确定

相关推荐
d***9359 小时前
springboot3.X 无法解析parameter参数问题
android·前端·后端
q***710110 小时前
Spring Boot(快速上手)
java·spring boot·后端
n***840710 小时前
十七:Spring Boot依赖 (2)-- spring-boot-starter-web 依赖详解
前端·spring boot·后端
q***965813 小时前
Spring Cloud Data Flow 简介
后端·spring·spring cloud
凌波粒14 小时前
Springboot基础教程(3)--自动装配原理/静态资源处理/欢迎页
java·spring boot·后端
likuolei14 小时前
XSL-FO 软件
java·开发语言·前端·数据库
凌波粒14 小时前
SpringBoot基础教程(2)--yaml/配置文件注入/数据校验/多环境配置
java·spring boot·后端·spring
正一品程序员14 小时前
vue项目引入GoogleMap API进行网格区域圈选
前端·javascript·vue.js
S***267514 小时前
Spring Boot环境配置
java·spring boot·后端
6***830514 小时前
什么是Spring Boot 应用开发?
java·spring boot·后端