3

I've inherited a WP Networks production server which needs a few updates. However, some users have made some customizations to themes (without creating a child theme).

Ideally, I'd like to 'clone' this machine. However, this may be beyond my control. In lieu, I wanted to fire up a vagrant VM (perhaps running Centos) and directly copy file trees. That is I'd rsync or scp over /var/www/html move the databases via mysqldump and mysql < database.dump.sql.

My questions, specifically, is (1) is the above reasonable and (2) how do I handle the domain name coded in the database? Would using my host system's /etc/hosts file enough?

I'd even be happy with something that can help a site use a relative URL. Is this possible? Does WP need an absolute URL in wp-config.php and the database?

Running:

  • Server RHEL 6.3, Santiago
  • WordPress Networks 3.9
  • mysql Ver 14.14
1
  • Yea, I've always used my hosts file for local development on both windows or *nix. Nov 14, 2014 at 18:30

1 Answer 1

3
+50
  1. Yes, reasonable. Setting up development clones of WordPress is very easy.

    • Copy your files (rsync/scp are fine) to your dev server
    • Setup a new database and database user (and setup permissions) on your dev server
    • Update your wp-config.php file with your new database info: DB_NAME, DB_USER, DB_PASSWORD, DB_HOST (if other than localhost)
    • Update: If this is Multisite, you will also need to update DOMAIN_CURRENT_SITE to your dev server domain.
  2. I use the following tool: https://interconnectit.com/products/search-and-replace-for-wordpress-databases/ to run a search and replace on the database. (Using something like this is key, because there is typically serialized data in your WordPress tables. Usually in wp_options or wp_postmeta.

Just dump it in your base WP dir and pull it up in your browser. It will automatically populate your database details (if it doesn't, you can manually enter them), and enter your search/replace parameters.

You have the opportunity to do a dry run to see what (if any) rows will be updated.

The only other things I'd say do/check for is place the following in your wp-config.php file (replacing http://example.com with your dev domain, remove or update domain for production):

define('WP_HOME','http://example.com');
define('WP_SITEURL','http://example.com');

and make sure there are no hard coded paths in any of the theme files that your scripts might rely on.

Between defining those and the DB search/replace you should be golden.

Lastly, here is WP documentation for migrating to another server. Might be a handy reference for you: http://codex.wordpress.org/Moving_WordPress

Update

You'll want to make sure that your .htaccess file (located in the base WP directory) is carried over as well.

  • For a normal WordPress install, you could simply refresh the permalinks (Dashboard > Settings > Permalinks > Save/Update) which will automatically rebuild the .htaccess file for you (if WP can write to the directory). Otherwise you'll have to manually create it, and use the rules displayed on the Permalinks page.

  • For a Multisite install, there are specific rewrite rules depending on your setup that you can pull from Network Settings > Network Setup.

7
  • Got me a good bit of the way there! Upvoted. Waiting for time limit to reward bounty. For the database, I ended up doing sed -e 's/domain/IP/g' < wp.sql > wp2.sql. This seemed to do the S&R stuff. Only trouble now is access sub-blogs. Root and wp-admin show up just dandy. Any thoughts? For example 192.168.33.10/test errors as Not Found The requested URL /test was not found on this server.
    – Rick
    Nov 18, 2014 at 17:43
  • You can't access sub-blogs at all? Or just wp-admin?
    – BODA82
    Nov 18, 2014 at 17:48
  • I can't access sub blogs. I can access root (/) and root's wp-admin. Though I probably should open this up to another question - wordpress.stackexchange.com/questions/168798
    – Rick
    Nov 18, 2014 at 18:03
  • 1
    Make sure you've copied over the .htaccess file in the root wp directory. There are specific rewrite rules that need to reside in there.
    – BODA82
    Nov 18, 2014 at 18:22
  • 1
    @Richard The problem with doing the database replacement with »sed« is that it won't take care of serialized data. Well it will take care of it, but won't update it, in regards of serialized data the length is important, which won't be handled by something like »sed«, the »search and replace« plugin, like others will do that, so it preferable to use such solution, otherwise you will constantly run into problems. Nov 18, 2014 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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