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:
- 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.
- Move the database from one environment to another and change siteurl and home in the wp_options table with the correct base url.
- Login to the website, go to Permalinks under Settings and click save.
- 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 ('example.dev') and 'Replace with' the new domain ('example.com').
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 'http://example.dev' 'http://example.com' --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 http://example.dev and https://example.com.
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 http%3A%2F%2Fexample.dev and replace with https%3A%2F%2Fwww.example.com
- For the Revolution Slider URL structure: search for http:\/\/example.dev and replace with https:\/\/www.example.com