If you quickly need to change the WordPress site url on a VPS or dedicated server with WP CLI installed or installable WP-CLI is your friend. It is a great command line based option dealing with url changes during site migration. There are of course great plugins to help out too, but believe me with full server access or VPS access a command line tool like wp-cli can deal with the url issues in no time!

Development to Production

If you just need to move the database from development to production as you will go live with the content you can do this. You replace the database on the production server with the one on the development box. Then you use WP-CLI and then change the urls in a jiffy. Just ssh into your production server and run the search-replace command like this:

wp search-replace 'example.dev' 'example.com' --skip-columns=guid

Afterwards all will work well. All content will be loaded properly with the right urls. Images should be loaded too as long as you moved those to the server as well. I do this often for all new Trellis LEMP box setups at Digital Ocean and I can tell you it works really well. A lot better than the WordPress Importer tool from the Dashboard. Though the importer does work quite well from the command line you still need to deal with images.

Dry Run – Better Safe than Sorry

You can also do a dry run first with –dry-run added. This to see what urls will be changed and to make sure you are running the correct command. So the command will then be

wp search-replace 'example.dev' 'example.com' --skip-columns=guid --dry-run

Actually pretty smart to use. Especially if you are talking a lot data and or complicated url. Better safe than sorry. Will safe you restoring it all with or without backup.

Backup, backup!

Do remember it is always good to backup the database before you do this. Just in case you do not fill in the urls properly once you run things live. Sequel Pro is a great OSX database management tool for backups, changes and replacements of databases.

There is more..

You can do way more with wp-cli than just searching and replacing urls. You can set up full WordPress installations, install themes, plugins, add fields, backup setups and more. I will be sure to write some other applications again as soon as I have the time. Stay tuned!

2 Responses

  1. This command didn’t work for me (after uploading the local db to Production), as I get the error ‘Site not found: example.com’.

    So, in order for it to work on Production, I created a wp-cli.yml file containing my Production URL ie:

    URL: example.com

    Then my wp-cli search-replace works OK.

    Do you ever get this error with wp-cli?

  2. Hi Henry,

    No I never got that error. Can you tell exactly tell me what command you ran exactly? I mean you did do “search-replace https://domain.dev https://domain.com” ? You could also try adding –verbose or do to see more information on the issue.
    Did you run it on Windows perhaps? There are some other possible issues using the command on Windows I read on Github- see https://github.com/wp-cli/wp-cli/issues/1592#issuecomment-170246332 .
    Also, when using multisite you need the –url parameter. As I often run stand alone setups I forgot to mention that here.

Leave a Reply

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