InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Wordpress How-Tos

  • angularjs in wordpress
  • Convert wordpress page to posts and vice versa
  • Find all user created wordpress custom field keys
  • How to automate wordpress sandbox setup on Linux
  • How to capture php code or included file output in a variable
  • How to check the performance of a plugin using mysql query log
  • How to migrate wordpress from root to sub directory
  • How to upgrade wordpress manually
  • How to view wordpress current version
  • Setup xdebug for remote wordpress debugging
  • Wordpress - disable theme and plugin editing
  • Wordpress - get wpdb class method names
  • Wordpress multisite network vs normal installation
  • display method names from php WP_Query object
  • find if a wordpress page is leaf page
 
  • Home
  • > Tutorials
  • > Wordpress
  • > Wordpress How To

How to automate wordpress sandbox setup on Linux

By admin | Last updated on Mar 20, 2016

Maintaining a wordpress site can be pretty involving task specially when you have so many plugins with regular updates. Many time you have to experiment new plugins, remove old plugins, do performance tuning, etc. The best workflow is to maintain a sandbox wordpress environment and constantly synchronize it with the main production environment.

Here are the steps to automate the syncing process on Linux which I follow and so far these have been working great for me. I’m using Bash script on ubuntu linux instance in Amazon AWS EC2 environment.

  1.  Create a sandbox setup on a subdomain. e.g. sandbox.infoheap.com
  2. Assuming this sandbox is using sandbox_blog database and main database is prod_blog, you can have a script containing code similar to the following
    mysqldump -u root --password="whatever_is_password" -h localhost prod_blog | mysql -u root --password="whatever_is_password" -h localhost sandbox_blog
    (make sure database sandbox_blog is already created)
    
    ## update blog name
    echo "update wp_options set option_value='sandbox InfoHeap' where option_name='blogname';" | mysql -u root --password="whatever_is_password" -h localhost sandbox_blog
    
    # update domain
    echo "update wp_options set option_value='http://sandbox.infoheap.com' where option_name='siteurl';" | mysql -u root --password="whatever_is_password" -h localhost sandbox_blog
    echo "update wp_options set option_value='http://sandbox.infoheap.com' where option_name='home';" | mysql -u root --password="whatever_is_password" -h localhost sandbox_blog
    echo "update wp_options set option_value='sandbox InfoHeap' where option_name='blogname';" | mysql -u root --password="whatever_is_password" -h localhost sandbox_blog
    
    ## update Yoast Google analytics (in case you are using it with subdomain tracking)
    echo 'update wp_options set option_value=replace(option_value, "s:12:\"infoheap.com\"", "s:20:\"sandbox.infoheap.com\"") where option_name = "Yoast_Google_Analytics";' | mysql -u root --password="whatever_is_password" -h localhost sandbox_blog
    (The number after s: is string length. You may have to change old and new value after s according to your domain name string length. I accept that this is big hack and there must be more polished ways to do it using deserialization-serialization. I'll update it once I find a cleaner way.)
    
    ## Unset ping sites to avoid pinging http://rpc.pingomatic.com/, etc. when we update a blog.
    echo "update wp_options set option_value = '' where option_name = 'ping_sites';" | mysql -u root --password="whatever_is_password" -h localhost sandbox_blog
    
    # images 
    sudo -u www-data rsync -r [PROD_BLOG_HOME]/wp-content/uploads/* [SANDBOX_BLOG_HOME]/wp-content/uploads/

 

This takes care of most of the stuff. Some points to note:

  1. The image links still may point to production images in blogs. You can modify the script to do a search replace in wp_post table in case you really need that.
  2. There may be more plugins which may need modifications. But this script is a good starting point and you can add stuff to it.
  3. Also have a robots.txt in sandbox blog to block search engines from crawling you sandbox blog. You may want to allow Mediapartners-Google in case you want to test adsense ads on your sandbox setup.
    User-agent: *
    Disallow: /
    
    User-agent: Mediapartners-Google
    Disallow:
  4. Copying database will case sandbox to have same active plugin as production.  Make sure whatever plugin is present on production environment is present on sandbox as well. The extra plugins will become inactive after the sync. You can manually activate those if you need extra plugins.

Suggested posts:

  1. How to find mysql query rate on Linux
  2. prevent wordpress xmlrpc.php attack
  3. Using Google analytics SDK v2 for android app real time tracking
  4. WordPress themes for beginners worth considering
  5. How to kill unresponsive ssh session using escape sequence
  6. How to install mysql 5.7 on Amazon Linux 2
  7. Find which process is listening on a port on Linux
  8. How to migrate wordpress from root to sub directory
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Linux, Tutorials, Wordpress, Wordpress How To
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress