Most Flawless Way To Transfer from Dev to Prod

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.

Read More

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.

Related posts

Leave a Reply

6 comments

  1. Any difference between dev and prod is bad. Here is what I do:

    • Have a different ip for dev server (Whether internal, external, or on local computer is unimportant) — but dev server must be the exact same setup (see bottom paragraph)
    • Change the hosts file (see here) (on yours or a testing computer or a virtual machine) to point to dev server ip
    • Result: HTTP requests sent to dev server have Host header field set as “example.com” exactly like it will be for the prod server.

    This method removes two differences often encountered otherwise:

    1. having to change domain name
    2. having dev code in a subdirectory, but prod code in root or diff subdirectory. This is because I use git to transfer files between dev and prod.

    .

    .

    The dev server is set up exactly the same as the prod server (see Chef or Puppet for how to programmatically manage servers).

  2. I do the same dev-prod kind of deployment on a regular basis, so I developed some standard queries for it:

    1. 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’;

    2. Update the upload path:

      UPDATE wp_options SET option_value = ‘[SITE_ROOT_PATH]/wp-content/uploads’ WHERE option_name = ‘upload_path’;

    3. Update the post guids:

      UPDATE wp_posts SET guid = replace(guid, ‘[DEV_URL]’, ‘[PROD_URL]’);

    4. 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.

  3. 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.