Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it really neccessary to put WP_HOME, WP_SITEURL in wp-config.php or set these settings via admin panel every time when moving a WordPress instance to another url (for example: moving from dev environment to production)? Is there any better strategy?

share|improve this question
add comment

migrated from stackoverflow.com May 9 '11 at 17:27

This question came from our site for professional and enthusiast programmers.

6 Answers

What I do here is I keep an entry in my /etc/hosts file pointing the site domain to 127.0.0.1. Most of the time the line is commented so my machine points to the production site, and when I'm developing something I just uncomment the line and the domain will point to my dev box.

I know it's kinda ugly, but since Wordpress puts the domain in a lot of fields in the database (especially if you need to work with real data in your development environment), it's the fastest method I could come up with.

share|improve this answer
add comment

When you move from one server to another the problem could be URLs that WP serialized in DB. To do a safe search and replace you can use this tool search replace db.

Is very simple, follow the instructions and remember to remove the script when done.

share|improve this answer
add comment

You could put those settings in an external file and exclude it from your publishing process.

share|improve this answer
add comment

Those parameters and admin settings change the URLs in the database. The only other way to do that is run SQL queries on the DB in phpmyadmin to change them:

UPDATE wp_options SET option_value = replace(option_value, 'http://olddomain.com', 'http://newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://olddomain.com','http://newdomain.com');

UPDATE wp_posts SET post_content = replace(post_content, 'http://olddomain.com', 'http://newdomain.com');

UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://olddomain.com', 'http://newdomain.com');
share|improve this answer
2  
You should be careful with this approach because some plugins store serialized arrays in wp_options (like ContactForm7) and a brute replace (unless both domains have the exact same number of characters) may brake the plugin configuration. –  MZAweb May 9 '11 at 17:48
    
These queries correctly find/replace in serialized data and don't break the plugin or the data. –  songdogtech Apr 24 '12 at 14:49
    
Not if you have a serialized array in a meta_value in wp_postmeta, and that array contains the site url (if old and new urls have different str_len, of course) –  MZAweb Apr 24 '12 at 21:07
add comment

I don't mess with core files, I just move the themes and plugins around instead. I develop locally and zip the themes and plugins for production. I have about ten WordPress installs most internal and this has worked well for me so far.

I also, don't move much data around so this answer may not help you. There are some pretty extensive free plugins for backing up data and restoring.

share|improve this answer
add comment

Use on the top of your functions.php: update_option('siteurl','http://yoursite.com'); update_option('home','http://yoursite.com');

Navgigate through your site a bit, login the backend en remove these lines.

This should be sufficient.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.