Move a WordPress website to a new environment

Moving a WordPress website is annoying. Main reason? The url's are hardcoded in the database. So on each move these paths have to be rewritten. And you have to be careful with manual SQL database commands because some paths might be serialized. 

There are more automated methods available but I'm old school and use this method: 

  1. Move the code and the files from one environment to another, using (S)FTP and change the wp-config.php file with the correct database information.  
  2. Move the database from one environment to another and change siteurl and home in the wp_options table with the correct base url. 
  3. Login to the website, go to Permalinks under Settings and click save. 
  4. Finally, change the absolute database paths. Install the Better Search Replace plugin and go to Tools > Better Search Replace and 'Search for' the old domain ('') and 'Replace with' the new domain (''). 

With the command line

Instead of using a plugin, you can also use WP CLI. Then a plugin (link Better Search Replace) is not needed. 

Go to the webroot of the WordPress install and run: 

wp search-replace '' '' --skip-columns=guid

The --skip-columns flag is optional. 

Moving from http to https

Better Search Replace can also be used to move a http to a https domain. In that case you have to include the full path, for example and 

Some plugins use special characters in URL's (for example Visual Composer and Revolution Slider). When changing from http to https, these can be missed. So, search the database to look for these. I use these commands in Better Search Replace when changing from http to https: 

  • For the Visual Composer URL structure: search for and replace with
  • For the Revolution Slider URL structure: search for http:\/\/ and replace with https:\/\/

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.