Working with wordpress for the last few years I’ve always had some difficulty building a website which has a production/development environments. It always seemed to be somewhat impossible to figure out how to have the two sites running in parallel.
Creating a wordpress development environment that was hidden from search engines which was password protected always seemed to be the easy way or doing things. Once you get your wordpress development site all created you can unleash it to the world!
The steps you probably took to get there were most likely the scenario described below.
1) Build your development site!
2) install a new wordpress installation on your production url
3) use wordpress export feature from development
4) import your xml file you got from development export
5) copy paste wp-content folder
6) reset all your settings on your theme and such.
Step 6 always seemed to be the stickler you seem to make all the right moves but you spend so much time making sure that everything is hooked up correctly. In the end its more of a headache to make things hook up and push your site live.
In recent projects I have found it more of demand to run a dev and prod site in tandem. I was forced and not in a good way to figure this out. Instead of the above steps explained I have decided to detail for you how to actually achieve moving your wordpress from a development state to a production state and make it seemless to the user… this process takes about 5 minutes once you do it a few times.
1. Log into PHPmyAdmin and export the database. This should be available in any hosting provider.
Wait a minute… I see I have about 15 databases how can I tell which one is the correct DB for my development site vs production vs another clients site? This seemed difficult at first for me because I found myself having to dig deeper into the database and look at the user tables(something which Im not comfortable doing because I’m not a database guru.) The easiest way to find out which DB your environment is point to is look at the wp-config.php file.
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
/** MySQL database username */
/** MySQL database password */
2. Create your new database! If you are not familiar with SQL databases no problem, your cpanel should have some sort of wizard which will allow you to create a new database. In the creation process your going to give your database a name/username/password. Provide whatever information you deem necessary and make sure you write it down so you don’t forget it.
3. Once you create the new database you will want to re-open your wp-config and make sure your database name/ username/ password match exactly to the database you created in step 2.
4. re-upload the wp-config.php file to your folder structure and you should be pointing to the database
Simple as that! Now you can create a development environment for your wordpress with ease and not have to worry about copying and pasting a bunch of files.
Here is a list of some simple SQL queries that get all of the nitty gritty changed. I have used this method for moving sites within an hour TOPS
Change Siteurl & Homeurl
WordPress stores the absolute path of the site URL and home URL in the database. Therefore, if you transfer your WordPress site from the localhost to your server, your site will not load online. This is because the absolute path URL is still pointing to your localhost. You will need to change the site URL and the home URL in order for the site to work.
UPDATE wp_options SET option_value = replace(option_value, 'http://www.DEVURL.com', 'http://www.PRODURL.com') WHERE option_name = 'home' OR option_name = 'siteurl';
After you have migrated your blog from the localhost to your server or from another domain to a new domain, you will need to fix the URLs for the GUID field in wp_posts table. This is crucial because GUID is used to translate your post or page slug to the correct article absolute path if it is entered wrongly.
UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.DEVURL.COM', 'http://www.PRODURL.com');
Change URL in Content
WordPress uses absolute path in the URL link instead of a relative path in the URL link when storing them in the database. Within the content of each post record, it stores all the old URLs referencing the old source. Therefore you will need to change all these URLs to the new domain location.
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://www.DEVURL.com', 'http://www.PRODURL.com');
Change Image Path Only
If you decide to use Amazon CloudFront as your Content Delivery Network (CDN) to offload the delivery of images from your server. After your have created your CNAME record, you can use the query below to change all the image paths in WordPress to load all your images from Amazon CloudFront.
UPDATE wp_posts SET post_content = REPLACE (post_content, 'src="http://www.DEVURL.com', 'src="http://www.PRODURL.com');
You will also need to update the GUID for Image Attachment with the following query:
UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.DEVURL.com', 'http://www.PRODURL.com') WHERE post_type = 'attachment';
Update Post Meta
Updating Post Meta works almost the same way as updating the URL in post content. If you have stored extra URL data for each post, you can use the follow query to change all of them.
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://www.DEVURL.com','http://www.PRODURL.com');