Random small break-fix or enlightening ideas
When moving existing WordPress installs around, you may find that the site becomes inaccessible because the site URL is contained in the database table, wp_options
to be exact. In order to make this site accessible, the site URL option needs to be changed. Where can that be changed? From the admin center. On the website. Yeah, it’s a catch 22. But, there are several alternative ways to change this option, even if your blog is not accessible.
Edit wp-settings.php
Personally, I think this is where the option should be stored. When you’re changing the URL, chances are the blog is either not accessible over HTTP now or won’t be after this change is made. Any settings that break/fix HTTP access shouldn’t be configured in a web page. Anyway, enough opinion, here is how to do it.
Open up wp-config.php
and add these lines towards the top.
define('WP_HOME','http://a16-lamp-wp'); define('WP_SITEURL','http://a16-lamp-wp');
Note that changing this only overrides what is stored in the database – it doesn’t change it. If you were to add these settings and take a peak at the admin center, it will look like this.
Those fields are disabled and showing what is configured in the flat file. You can leave it like this and know that the option is to be changed in the file the next time the blog is moved.
Edit the Database
UPDATE `wp_options` SET 'option_value` = 'http://a16-lamp-wp' WHERE `option_name` = 'siteurl' || `option_name` = 'home' LIMIT 2; |
Some things to note about this query:
- Replace ‘newurl’ with your site’s new URL
- The limit is there to prevent massive row updates in the event the conditions are missing or something else happens to where several rows are selected.
- If you did not use the default table prefix, your table name will be different.
After running this query, try and load the site again. Then go to /wp-admin and into Settings -> General to verify the updates, however, the fact that you can view this page should confirm that the updates were successful.
Edit Theme functions.php
Drop these lines in your theme’s functions.php
file.
update_option('siteurl','http://a16-lamp-wp'); update_option('home','http://a16-lamp-wp');
This code will actually update the settings in the wp-settings
table, so you only need to stick it there for a couple page loads and then remove it.