Published by Mijingo

movie icon image

ExpressionEngine How-to Articles

Topics range from beginner to advanced, but are all born out of real world, professional, day-to-day use of ExpressionEngine. Need more information? Get training videos and ebooks on ExpressionEngine from Mijingo.

Automatically Rebuilding an EE Sandbox

As part of this site and other development work, I find myself testing a lot of EE add-ons. I also work on my own add-ons. For both of these activities it’s required to have a local install of ExpressionEngine, configured just how I like it. I call it my EE Sandbox, a place where I can play in EE. I had been creating my sandbox manually each time I needed to refresh it, but that quickly became too much work each and every time I needed to start over.

I began to put together an automated way to do this and came across this shell script in the EE forums, which I used as an inspiration for my own script. My script does a complete restore of ExpressioneEngine; this includes the database and all of the files. Because of this, you only want to use this script on a true sandbox—an EE installation that is not at all sacred.

Be Prepared

In order to have an EE sandbox that you will find useful over and over again, you need to do some work up front configuring your EE installation just to your liking. Install your favorite add-ons, tweak your settings and preferences, create some sample users; do whatever you need to make EE your ideal setup. Since I’m using my sandbox to test and develop add-ons, I kept my set up very minimal and as near “fresh install” as I can.

Some of my sandbox settings:

  • Pages Module enabled and a custom tab created pointing to it
  • “Weblog” changed to “section”
  • Two sections: Pages and Site
  • Two sample users, in addition to the Admin user. This comes in handy if I need to quickly test something with more than one user.

                                   

With my ideal EE sandbox all set up, it’s now time to “freeze” it by creating a database dump (using phpMyAdmin or mysqladmin) and saving it somewhere on my computer. I also create a tarball of the entire site files and store those in the same location as the database dump.

Meet the Script

This script is for advanced users. If you feel uncomfortable running scripts from the command line, you should probably not use this script.

Running the EE Sandbox Restore Script

Running the EE Sandbox restore script from the command line.

 
Here’s how it works:

  • The sandbox database is dropped and then recreated from a database dump.
  • The existing application files are deleted from the web root.
  • A tarball containing the EE application files is copied over to your web root location and unpacked. The tarball is then removed.
  • Permissions are set on certain files and directories, as required by ExpressionEngine.

Every time you run the script the existing sandbox is completely destroyed and then rebuilt from your database dump and tarball of the site files.

To install and use the script:

  • Create your ideal EE sandbox. Dump the database and tarball the files.
  • Download the script and make it executable.
  • Fill out the settings at the top of the script.
  • Run the script from the command line to restore your EE Sandbox.

Watch me use the script to restore my sandbox.

Posted on Jan 21, 2009

Filed Under: How-To, ExpressionEngine Development,

Ryan Irelan
About Ryan Irelan

Ryan Irelan is the Technology and Development Director at Happy Cog, a web design and development firm. He is a noted ExpressionEngine expert, having created a wildly popular video training series on ExpressionEngine. Additionally, Ryan is the publisher of EE Insider, a well-known news and information site for the ExpressionEngine community. In his spare time, Ryan is the production director of A List Apart Magazine, which is one of the most popular ExpressionEngine-powered sites on the web. Recently, Ryan published a book on ExpressionEngine 2 called "ExpressionEngine 2: A Quick-Start Guide."