After the IP address of my WordPress site had changed,
I had to hard code its address in wp-config.php
:
define('WP_HOME','http://54.77.99.66');
define('WP_SITEURL','http://54.77.99.66');
When I delete the lines in wp-config.php
, my site is no longer accessible.
How can I get rid of the hard coded entries and set my site’s address in the UI (which is currently greyed out)?
I routinely move sites between domains as I test features, restore and test backups, etc. and I always just change the domain throughout the database. The problem with this approach is that many options are store in MySQL as serialized PHP arrays which include the length of a string as a value so you can’t just perform a blind search and replace. However, a company called interconnect/it has a free product called Search Replace DB that is able to safely traverse and update these arrays. I say “safely” in that I’ve run it hundreds of times without issue but they still always recommend backing up your database first.
search
box enter your old site’s domainreplace
box enter your new site’s domaindatabase
area enter your WP database informationdry run
button just to see what the tool thinks should be updated. You’ll usually see one or two items inwp_options
and a bunch inwp_posts
andwp_postmeta
. If you have blogwp_comments
might get some updates. Depending on your plugins you might get others, too. You can even click theview changes
links to see what it thinks it should update.live run
button and let it perform the updates.There are some things to be aware of when replacing text. If my site is
example.net
and my email address ischris@example.net
and I perform a replace on justexample.net
it will change my email address, too. If my site iswww.example.net
(with the WWW) then I would search onwww.example.net
which wouldn’t catch. I always audit the users just to make there aren’t any domain conflicts. If there are, I just perform the above steps a second time, once for each user to change the email addresses back, but this is pretty rare.The other thing to watch is text-based content about your domain. For instance, if you are keeping your old domain at
example.net
and spinning off a blog atexample.com
, the latter might have a blog post about how awesome products are at the former but the replace would point to the latter.These are the only two edge cases that I’ve ever run into with this tool, however. Using this tool you should be able to avoid the
WP_HOME
andWP_SITEURL
constants completely.Also, just in case you are worried, the actual WordPress codex even references and recommends this product.
This seems to work for me. Honestly not sure how it works:
I guess it does ‘http://
<yoursite>
‘ where<yoursite>
is replaced with whatever the address of the server is in your URL bar. Doing this, I can access my site both locally (i.e. via the local IP) and from other networks without issue.