Migrating your WordPress site to SSL

There are two steps to migrating your WordPress site over to SSL (https instead of http) after you have set up your certificate and web server configuration.

The first is relatively easy: update your Settings > General and change the WordPress Address (URL) and Site Address (URL) from http to https.

The second, part is a bit trickier.

Basically for SSL to work correctly you want to avoid mix-mode content. This is where content is being served both via http (non-SSL) and https (SSL). When this happens your browser won’t show the site as being 100% SSL, and instead display different messages depending on your browser. Its enough to deter users from using the site if they are expecting the “green” secure padlock.

To fix this, you need to find and replace references to non-SSL content (hardcoded with http://) in two places — your code and your database.

For your code, the first place to check is your theme code and settings. Look for and replace any instances of http:// with https://

You can use your browser’s debugging/inspector to check for files that are not loading via https://. Note too these might be external resources and scripts (e.g. external Javascript libraries, Google fonts etc). This can also be an issue in plugins, particularly when authors start hardcoding the absolute URL with http://.

For your database, use a tool like Better Search & Replace to search your WordPress site for references to http://<yoursite>.com and replace it with https://<yoursite>.com.

PHP database can’t connect to localhost but 127.0.0.1 works

There are many reasons for this, so first check that MySQL/MariaDB is running properly, that you are using the correct credentials and that the the appropriate user@localhost has access.

Also check you aren’t using skip-name-resolve and bind-address in your my.cnf file if accessing from outside of the localhost. These are things you will find with a google search.

Apart from this one other reason why 127.0.0.1 will work and localhost will not work is if you are using something other than the default socket=/var/lib/mysql/mysql.sock location in your my.cnf.

If that is the case, you’ll need to update the relevant default_socket= parameter in php.ini (for each driver) to match that socket – see the entries under my.cnf [mysql] and [mysqld] sections for the socket parameter. This is more likely to occur if you are using MariaDB for example.