Changed URL of WordPress Site Now it Wont Load

Warning! These are command line instructions for how to ssh and edit MySQL tables. This is advanced stuff, and you could potentially wipe out the contents of your WordPress site. Do it at your own risk of potentially messing something up.

About half an hour ago I totally broke one of my WordPress websites. Whoops. I was in the WordPress settings and accidentally added a HTTPS prefix to my site, when the site is setup for HTTP only at the moment. Changing the URL of your WordPress site can cause the whole site to go do and be totally unreachable to anyone, including not being able to get back to the settings page. It's a big mistake.

Luckily, when you change the URL of your WordPress site, that change lives in two database entries. To get the site back up and running you just need to change those two entries back to what they were before you changed the URL.

You can do this using tools like phpMyAdmin, but I like to do things the old fashioned way and just SSH and MySQL through the command line.

So, to change the URL of your WordPress site through the command line, first SSH into the host machine. For me, this is a Vultr VPS.

ssh [email protected]

Where username is are username on that machine and example.com is the URL or IP address your site is hosted on. If you don't know either of these, you should contact your hosting provider.

You may be asked for a password, which you need to provide.

Once you are logged into the machine which is hosting your website, you need to connect to the MySQL database which contains your WordPress information.

mysql -u database-username -p

This creates a connection to MySQL. Note that the database-username is your database username, which might be different from the SSH username you used above. The -p flag tells MySQL to ask for your password.

Once connected you should be able to see all the databases that exist by typing

show databases;

You should then select the database that contains your WordPress information. If the database were called "database-name" you should select it using the command:

use database-name;

Then look at all the tables in the database:

show tables;

You should see a table that is called wp_options or something similar. The prefix might be different. This is the table you need to edit. An easy way to find what you are looking for is to search for the bad URL:

select * from wp_options where option_value = 'https://BAD-URL.com';

You can then simply update those rows with the correct URL:

update wp_options set option_value = 'http://GOOD-URLs.com' where option_value = 'http://BAD-URL.com';

And that's it. The database has been changed to the correct URL and you should be able to access your WordPress site again. `