Useful Snippets


This blog is used to collect useful snippets related to Linux, PHP, MySQL and more. Feel free to post comments with improvements or questions!

Are your smart devices spying on you? Make better purchasing choices and find products that respect your privacy at

RSS Latest posts from my personal blog

Most viewed posts

Subscribe to RSS feed

Migrating a WordPress Site From HTTP to HTTPS with WP-CLI

Stanislav KhromovStanislav Khromov

It’s as easy as:

Take a backup

wp db export

Test rewriting from HTTP to HTTPS

wp search-replace '' '' --dry-run

If everything is looking good, it’s time to rewrite:

wp search-replace '' ''

Some tutorials recommend adding the --skip-columns=guid flag. The train of thought is that old posts will be visible to RSS readers as new ones. I don’t think this is a big problem, and it’s much cleaner to not keep non-SSL urls in your database. It can also cause issues if you are using the GUID field to grab image urls/ids from attachments. (It’s a very popular way of mapping a URL to an attachment ID). With that in mind, I find it’s best to omit this flag.


Web Developer at Aftonbladet (Schibsted Media Group)
Any opinions on this blog are my own and do not reflect the views of my employer.
Twitter Profile
Visit my other blog

Comments 3
  • Anh Tran
    Posted on

    Anh Tran Anh Tran

    Reply Author

    I really love WP-CLI and search-replace is my favorite command!

  • R Green
    Posted on

    R Green R Green

    Reply Author

    Thanks, this was useful. One thing I did wrong the first time was to put a slash after the domain name. For best results use and not With the trailing slash it missed some instances. Also, here is a command you can run afterward to check your work:
    wp search-replace ‘http://’ ‘https://’ –log –dry-run | less
    This shows you all remaining instances of http:// in the database. (Don’t run this without –dry-run or you’ll need that backup!)