Change domain in WordPress

Context:

I deployed a wordpress website in AliYun web hosting before doing domain resolution and site registration, so website works on temporary domain which is provided by AliYun. The problem is coming, after registered website and resolved my domain to given IP successfully, I can access webisite by using my domain, but all other pages including sub pages, css files are not working. I found temporary domain is still working, those pages will be redirected to url prefixed with temporary domain.

Best Solution:

Go to WordPress admin page, Click settings-> General to reset url, this is easiest way to figure it.

Screen Shot 2016-08-30 at 10.48.57

Screen Shot 2016-08-30 at 10.46.03

The reason why I introduce other two methods to change url is that I typed wrong domain, it caused I can not open website even admin page, I can not change it right back.

Hard Solution:

Go to WordPress root folder using FileZilla or some other FTP tools.
Open wp-config.php, add following two lines to it, save it back.

define('WP_HOME','http://kingscow.com');
define('WP_SITEURL','http://kingscow.com');

Screen Shot 2016-08-30 at 10.44.08

As official said this is not best solution as domain will not be changable, as shown below.
Screen Shot 2016-08-30 at 10.40.41

Soft Solution:

Another way to change url while not fossilizing url is adding two lines to theme’s functions.php file, which is located at wp-content/themes//. If functions.php file does not exist, create one with that two lines only.
Screen Shot 2016-08-30 at 10.43.15
Refreshing pages until new domain works
**important** Remove that two lines from functions.php file, because it is not necessary right there.

Reference: https://codex.wordpress.org/Changing_The_Site_URL

Change domain in WordPress

Docker系列 – 构建和发布 image

Docker提供了build和publish命令用于创建和发布image到指定的registry。本文假设项目基于spring boot + gradle,并使用docker hub做为registry,并且使用spring boot gralde docker插件完成docker的构建(创建)和发布(上传)。

1. 建立项目

参考此文创建spring boot项目,仅做小的修改,将HelloApplication源文件中Tap Spring Boot改为Tap docker。

2. 生成docker image

2.1 配置build.gradle
修改build.gradle文件,增加gradle-docker plugin以及配置,代码如下。

其中,classpath(‘gradle.plugin.com.palantir.gradle.docker:gradle-docker:0.13.0’)用于引入gradle-docker插件。目前该插件提供了0.17.2版本,并提供了更丰富的命令例如dockerTag,但这里无法使用该版本,能用的最高版是0.13.0。而apply plugin: ‘com.palantir.docker’用于应用该插件。最后在docker{ }内定义docker image信息,具体参考gradle-docker官网

2.2 配置Dockerfile
在项目根目录下创建Dockerfile文件,输入代码如下。

它使用openjdk:8-jdk-alpine做为基础镜像,提供了执行jar包的运行环境,包括linux和jdk8。项目jar包由外部参数JAR_FILE传入,最后通过java -jar运行项目。

2.3 生成docker image
按alt+F12,或者在Terminal中进入项目根目录,分别执行如下命令,结果如下图。
第一条命令根据build.gradle配置创建jar包,并利用jar包信息生成image。第二条用于查看是否生成响应的image。可以看到REPOSITORY为kingscow/naive-spring-boot,TAG为infant,和我们上面配置信息完全匹配,说明image成功生成。

2.4 使用docker运行工程
键入下面命令运行docker,效果如下图。其中,docker run用于运行image生成container,同时由于项目中定义的是8888端口,这里使用-p将8080映射到container内的8888,最后-t指定image名称。

2.5 查看运行结果
打开浏览器输入localhost:8080,如果返回Tap docker,说明docker成功运行。然后键入docker ps,可以看到一行IMAGE名为kingscow/naive-spring-boot:infant的container,这里就是项目部署到的container。

3. 发布docker image

3.1 注册docker账户
截止目前,我们都是在本地构建和运行image,下一步是要将它发布到registry,方便下一步的消费(如公共镜像,CI,部署等)。docker运行自建registry,这里为了演示方便使用docker hub做为registry,将我们制作好的image发布到这里。
首先,需要有docker hub的账户,如果还没有,前往docker hub完成注册,并记住登录名和名吗,如果已有直接跳到下一步3.2。
3.2 登陆docker
使用docker login命令登陆registry,默认的registry就是docker hub,输入登录名和密码,如果出现如下图的Login Successful,说明登陆成功。如果不登陆直接发布image,docker会提示permission错误。

3.2 发布image
键入如下命令发布image到hub,效果如下图。

3.3 查看发布
登陆docker hub网站,查看发布结果,类似下图所示。

简而言之,docker发布的基本流程为:develop -> package(jar) -> build image -> login -> publish image

参考:https://spring.io/guides/gs/spring-boot-docker/#scratch

Docker系列 – 构建和发布 image