So I’ve been working with WordPress for a while now and I usually develop locally and then upload everything to my Prod server… however, I’ve experienced a lot of differing results, especially when using plugins.
I usually export the database, but things like the location of the domain don’t always seem to get changed even after changing them within the WP admin beforehand.
What’s the best way to move from Dev to Prod and keeping everything intact?
Then, what’s the best way to move your site from a subdirectory on the same domain?
Please don’t point me in the direction of the WP docs… it’s the first place I looked.
Any difference between dev and prod is bad. Here is what I do:
This method removes two differences often encountered otherwise:
.
.
The dev server is set up exactly the same as the prod server (see Chef or Puppet for how to programmatically manage servers).
In my experience, I’ve used the Search and Replace plugin to re-reference all of the references to the old domain. Not the cleanest solution, but seems to work.
I do the same dev-prod kind of deployment on a regular basis, so I developed some standard queries for it:
Update the site url:
UPDATE wp_options SET option_value = replace(option_value, ‘[DEV_URL]’, ‘[PROD_URL]’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’ OR option_name = ‘fileupload_url’;
Update the upload path:
UPDATE wp_options SET option_value = ‘[SITE_ROOT_PATH]/wp-content/uploads’ WHERE option_name = ‘upload_path’;
Update the post guids:
UPDATE wp_posts SET guid = replace(guid, ‘[DEV_URL]’, ‘[PROD_URL]’);
Update urls in posts:
UPDATE wp_posts SET post_content = replace(post_content, ‘[DEV_URL]’, ‘[PROD_URL]’);
Replace the bracketed variables with actual values eg.
[DEV_URL] -> http://example-local-pc.com
[PROD_URL] -> http://example-online-server.com
[SITE_ROOT_PATH] -> /home/client/domains/example-online-server.com/html
That typically takes care of any references to the dev environment. You should note, however, that:
i) Many plugins also store absolute urls either in wp_options or custom tables. These you have to investigate on a case by case basis.
ii) Running an update replacement query (such as 1. and 2. above) shall almost certainly corrupt data in serialized fields. I haven’t come across a clean and fast technique yet of doing this replacement other than letting the associated plugins do the update themselves. The success of this depends on the robustness of the plugin.
I like to develop on a sub-directory so I can let my clients have access to the test site. when I’m ready to publish I use a plugin (recomendations below) to duplicate the whole thing to another sub-directory and then just point WordPress to load from the new one. Leaving the dev area active for testing.
Use a plugin like duplicator (free) or backupbuddy (paid). Also see if my question here helps you.
There is no flawless way due to how WordPress stores content in the database.
For pushing code around it can be as flawless as using git/mercurial/svn or even just file over-writes.
But that is not the case for any content stored in the database (plugins, posts, categories, etc) and there is no good way to sync two databases.
How to: Easily Move a WordPress Install from Development to Production?
I use this search replace tool:
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
It works for other software as well as wordpress.
As for deploying, I set up an environment on the server which I can then switch via domain mapping/vhosts to make live. The install Dev is always on a separate server, and is never made live.