Ancient Post Alert! This entry was published 17 years ago and contains technical information that may no longer be accurate. Proceed with caution.

Better Than the SQL If you’ve set up WordPress in a localhost testing environment you may already be familiar with the vagaries of site_url and home.

Basically, these values correspond to the “WordPress address” and “Blog address” fields under the “Options” section of the WP admin interface. For a localhost install you’d, quite naturally, want to pick something based off of localhost. This won’t be too useful though if you plan to view your WordPress site from other machines. (That includes virtual machines on the same computer—like, say, testing Internet Explorer from Parallels on your MacBook.) WordPress will hand out URLs literally containing localhost, prompting your remote machine to immediately turn around and begin contemplating its own navel. No good.

Okay then, so what about using an IP address instead?

Therein lies the rub. What if your machine moves from network to network (like said MacBook) or is on DHCP? That’s a rhetorical question of course, since I wouldn’t be writing this if I hadn’t already gone ahead and done this (precocious lad that I am). If you hard-code an IP as the value of site_url or home, and the IP of the host changes, large swathes of your WordPress site (including the ever-important admin) will become inaccessible.

It really comes down to what’s more valuable to you. If you simply need a self-contained development environment, stick with localhost. If you’re like me though, and need a platform to test against, the IP address is really the only way to go that I know of. So what’s really needed to make this latter case workable is a quick way to update site_url and home. And no, you can’t just go into the WP admin and change them. (The admin will be out of commission by the time you find out what your new IP is, remember?)

There are instructions out there for doing this kind of update via phpMyAdmin, but I prefer going straight to MySQL. To see what the current values are use the following SQL statements (where blog is the name of your own WordPress database):

SELECT * FROM blog.wp_options
WHERE option_name = 'siteurl';

SELECT * FROM blog.wp_options
WHERE option_name = 'home';

The current addresses will be under the option_value column. To edit these use the following, again replacing blog with the name of your WordPress database and inserting your own IP/blog path where appropriate (without trailing slashes):

UPDATE blog.wp_options
SET option_value = "http://xxx.xxx.xxx.xxx/blog"
WHERE option_name = 'siteurl';

UPDATE blog.wp_options
SET option_value = "http://xxx.xxx.xxx.xxx/blog"
WHERE option_name = 'home';

And there you have it. A fast update that lets you maintain a portable WordPress testing environment.