How to migrate WordPress from one host from another?

WordPress really SUCK! It doesn´t provide a viable, simple and easy solution for export/import of your whole site. Here I am sharing how I managed to migrate my WordPress site from an old host to a new one.

  • make sure Apache2, PHP, MySQL, and PHP MySQL extension work in perfect on your new host. Here is one instruction: http://www.tecmint.com/install-wordpress-on-ubuntu-16-04-with-lamp/
  • bear in mind that WordPress saves all static contents (style, theme, uploaded images, etc) in your file system. So make a copy of WordPress folder on the old host located in /var/www/html/wordpress_folder.
  • since WordPress stores all dynamic contents in mysql database (e.g., users, articles), you need to export that database to ¨.sql¨ file. Let’s suppose in /var/www/html/<wordpress_folder>/wp-config.php, we have:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define('DB_NAME', 'your_dbname');
     
    /** MySQL database username */
    define('DB_USER', 'your_usrname');
     
    /** MySQL database password */
    define('DB_PASSWORD', 'your_password');
     
    /** MySQL hostname */
    define('DB_HOST', 'your_hostname');

    Then, on the machine that hosts your wordpress website, you can do the export by:

    mysqldump -u your_usrname -p -h your_hostname your_dbname > wordpress_bakup.sql

    which will complete after receiving your_password.

  • Open the exported ¨.sql¨ file, replace all the old site urls to the new site urls, then save the ¨.sql¨ file. For example, in `vim` you can use:
     :%s/<old_ip_addr>/<new_ip_addr>/g
  • on the new host, put the old host static content under the same path relative to html root directory.
  • on the new host, import the ¨.sql¨ to a newly created database with the same name. (You may need to create a database called your_dbname first. This can be done my first logging in mysql by <span class="lang:default decode:true crayon-inline">mysql -u usr -p</span> , then create database your_dbname;  )
    mysql -u usr -p your_dbname < your_bak.sql
  • change ¨wp-config.php¨ accordingly so that DB password and username match those on the new host.
1
2
3
4
5
/** MySQL database username */
define('DB_USER', 'usr');
 
/** MySQL database password */
define('DB_PASSWORD', 'pwd');
  •  change the permission of `wp-content/uploads`, `wp-content/upgrades`, `wp-
  • content /plugins` folders to 777.
  •  add “define(‘FS_METHOD’, ‘direct’);” in the `wp-config.php`.

That´s it. Enjoy it.

—————————————————————————————————–

Updated on Aug 24th, 2015:

If you ever encounter file permission errors during updates or anything else, change permission of the whole wordpress directory as well as the files in it to 777. Do the update. And then change the permissions back as per the official document suggests:

For Directories:

find /path/to/your/wordpress/install/ -type d -exec chmod 755 {} \;

For Files:

find /path/to/your/wordpress/install/ -type f -exec chmod 644 {} \;

—————————————————————————————————–

Updated on April 8th, 2019

Another way to migrate wordpress:

Use Tools -> Export on the old site, and Use Tools->Import on the new site. Up to this point, the new site should have the identical content as in the old site. To update post contents that contain the old site’s URLs, use phpAdmin or mysqldump to export the database to an SQL file. In this file, replace the old site’s URLs with the new ones. Import the updated SQL file again using phpAdmin or mysqldump.

—————————————————————————————————-

Updated on May 6th, 2019

I just found this plugin is very useful

All-in-One WP Migration

How to make contents wider in WordPress Theme?

It again proved how silly WordPress is: I can’t find any theme with wide content area. Why do we have to waste almost a third of page area in EVERY WordPress theme? I read many articles about how to make custom CSS to widen the content column but no magic happened.

So I decided to modify `style.css` which is styling my theme, Twenty-fifteen. (Don’t have time to back up the theme or create a child theme.) Modifying `style.css` is easy but bear in mind whenever it gets updated it gets overwritten. So you need to modify `style.css` after every update.

As you can see on my site, my article has wide area so it has more contents to offer within one screen. You can download my ‘style.css’ here: https://dl.dropboxusercontent.com/u/5055823/style.css

R sapply

Background

In my memory, `sapply` is a function that takes a vector to consume and returns  another vector as result. Today I am sharing a “bizarre” behavior of it. Later I will talk about the reason to account for this weird behavior.

 

Details

 Let’s first look at the following line, from which I scratched my head:

sapply(1:30, function(x) {if(x>15) 1})  

Continue reading “R sapply”

如何删除Git历史记录里较大的文件?

背景

Git历史记录中,若不小心加入了较大的而无用的文件,很可能会让你的repository的size变得很大。Github和Bitbucket都分别对repository的大小做出了限制 (见https://help.github.com/articles/what-is-my-disk-quota/ 及https://confluence.atlassian.com/pages/viewpage.action;jsessionid=735235A3CE151FB6D4C518F3971FD524.node2?pageId=273877699)。那么如何在Git的历史记录中找出较大的文件并且删除它们呢?

  Continue reading “如何删除Git历史记录里较大的文件?”

Everything about Git

注释:本文中,中括号内参数表示可选参数,尖括号内参数表示必选参数。SHA-1值可以是commit的SHA-1值,HEAD[~|^]或者branch名字,因为HEAD和branch名字的SHA-1值都被git所记录。

一般规则

从远端代码仓库中下载项目

git clone

 

在master分支的基础上新建自己的branch,并跳到该branch上:

git checkout -b [origin/master]

  Continue reading “Everything about Git”

How is Logistic Regression designed?

背景

Logistic Regression是ML中再熟悉不过的Model了,它能基于数据X,得出生成binary label的概率:

image1

(在上式中,X仅有一个feature)

假设你出生在Logistic Regression被发明之前且在Normal Linear Regression被发明之后,现在让你设计一个Model来预测Binary的label——Y,使得这个Model能够基于观测数据X得出Y。你会怎么设计呢?

(注:接下来我们都假设X仅有一个feature)

Continue reading “How is Logistic Regression designed?”