When you add an SSL certificate to a WordPress site, you have to update all the own references on the website, changing the ‘http’ string to ‘https’.
In this post I will explain how to do it with the ‘search-replace‘ subcommand of WP-CLI.
Backup
First I will make a backup.
$ mysqldump -uroot -p mydatabase > 20191014-mydatabase.sql
Search and replace
I will use the ‘search and replace’ command. I have to be in the WordPress root directory:
$ cd /var/www/example_com
Then I will execute the command with the ‘dry-run’ parameter, so I can see the output without executing the command:
$ wp search-replace 'http://www.example.com' 'https://www.example.com' --dry-run +-------------------+-----------------------+--------------+------+ | Table | Column | Replacements | Type | +-------------------+-----------------------+--------------+------+ | qwp_postmeta | meta_value | 1854 | PHP | | qwp_posts | post_content | 2049 | SQL | | qwp_posts | guid | 4098 | SQL |
You can see the number of replacements (8.001 updates) and in which tables it will be executed.
To execute the command you have to remove the ‘dry-run’ parameter:
$ wp search-replace 'http://www.example.com' 'https://www.example.com'