Migrating your WordPress website

A WordPress site mainly consists of two parts. Firstly, there are files: the WordPress core, theme templates, plugin files and images. Secondly, there is a database which contains your messages, settings, categories, tags etc.

Take your site from local to production

Here we discuss the steps you have to follow to get your site from your local computer to the world wide web. Why would you bother doing this when it is perfectly possible to work with your FTP client directly on the production environment? Well the answer is twofold. Your client might not yet have taken care of his domain name or webhosting or maybe you just want to test a small feature in a local environment quickly. Apart from that it is actually a quite bad habit to work directly on the server.

So I convinced you to develop locally. Good. And now you are finished and it is time to show the whole wide world this marvellous website. Let’s deploy it to the production environment!

website to production

Moving your website from local to production environment

A recipe for going ‘live’

What follows is a simple couple of steps (except for the last trickier one) which will put your website live in a matter of minutes.

  • Go to the folder in which your local copy lives. Copy over all the files in there to a new folder. I call this folder ‘my-website-live’.
  • Create a database in the production environment. Make a note of the credentials, that is, the database name, the username and the password, you’ll quickly need those!
  • In the folder my-website-live is a wp-config.php file. This file contains your basic setup and the database credentials. Go ahead and change them to the settings you wrote down in step 2.
  • Now it is time to put the files online. Open your favourite FTP program and upload the files in the folder my-website-live to the root folder on the server (I assume you want to have your website installed in the root, right?).
  • Export your local database (in .sql format) using your local phpMyAdmin interface.
  • Import this file in the live database.
  • Since WordPress is saving a number of configurations in the database we have to change them. Find the table wp_options en change the records with option_name = site_url and option_name = home. Make sure the option_value links to the live site. Note that it is possible that the table prefix is no longer wp_. In that case, find the ***_options table.
  • Now it is time to check if it works: log in on the admin panel of the live site. If this does not work, you probably made a mistake in step 7. Go back and fix the urls. If you can log in to the admin panel, go to general settings and save. Do this also for the permalinks. This is only necessary to get some internal linkings correct.
  • Do one final query to get links in posts and pages right. This step is a bit complex so I explain it in more detail below.
phpmyadmin

PHPMyAdmin: interface for administration of the database

Links in posts and pages

When you wrote your posts and pages you probably used some internal links. These are still pointing to the local environment. You can change this using a plugin or by executing the following query. If you follow along, now it is time to make a back-up of your database! Still with me? Go ahead and open phpMyAdmin on the production environment. We need to perform a query on the wp_posts table since all posts and pages are stored in this table. This is the query:

UPDATE wp_posts SET post_content = REPLACE(post_content, 'localhost/test/', 'www.your-domain.com/')

I assume you have installed the live version in the root of the server and the local version in a folder ’test’. You are probably doing this a little different so change the paths accordingly. If you are scared to execute this query directly on the database, you might do it on one post specifically by adding

WHERE post_id=X

Here X refers to a post_id which contains an internal link.

Fancy a plugin, do you?

A little later I discovered a marvelous plugin that is developed specifically for this purpose: transferring the database from one environment to the other. Unfortunately it is a paid plugin, but it is well worth the cost. In particular when you have a more complex database. It was developed by ‘Delicious Brains’ and the plugin is called ‘WP Migrate DB Pro’. After walking through the steps outplayed here twice you probably want to do your migrations automatically. But, since it never hurts to do something by hand the first time… go ahead and try it!


Mijn Twitter profiel Mijn Facebook profiel
Pim Hooghiemstra Webdeveloper and founder of PLint-sites. Loves to build complex webapplications using Vue and Laravel! Latest post
Laravel-mix and the spread operator

Leave a Reply

Your email address will not be published. Required fields are marked *