Setting Up A Magento Staging Area

The best way to test out a new Magento release without potentially destroying your production store is to setup a staging area.

A staging area is a duplicate of your primary store that you can use to see if the upgrade process will go smoothly, and also allow you to use both the frontend and backend of your site to see if everything is running properly.

This article is written with our clients in mind, but the principles will apply no matter where you are hosted or what control panel you’re using.

Jump To Section

Create Staging Sub Domain

The first thing we want to do is setup a sub domain for our staging store:

  1. Login to cPanel for your domain, and click on the Sub Domains icon.
  2. For both the Sub Domain and Document Root, we’ll enter staging.
  3. Click on the Create button.

Create Staging Database

While we’re still in cPanel, let’s setup a blank database for our staging store:

  1. Go back to the main screen for cPanel, and click on the MySQL Database Wizard icon.
  2. For the New Database, we’ll enter staging.
  3. Click on the Next Step button.
  4. For the Username, we’ll enter staging, and for the Password, enter whatever you’d like here.
  5. Click on the Next Step button.
  6. Click on the box next to ALL PRIVILEGES.
  7. Click on the Next Step button.

Copy Production Store

Now that our sub domain and database has been setup, we need to copy our production store over to the sub domain directory.

  1. Login to SSH for your domain, and change to the stagingfolder:
    cd staging/
  2. Copy all of the data from the directory where Magento is installed, which is usually in the public_html directory, to the stagingdirectory:
    cp -R ../public_html/* ../public_html/.htaccess .

For the next step, you’ll need to know the database information for the production store. If you don’t remember this, open up the following file:


Lines 43-46 will contain your hostname, username, password, and database name.

Next, we need to copy the data from the production database over to our staging database. We’ll be doing this from SSH as well.


You’ll be prompted to enter the password for the user that has privileges to the production database, so type that in and hit the Enter key.

This can take a couple seconds to a couple minutes depending on the size of your database, so just wait until it finishes.

Once it finishes, we need to import this data to our staging database:

mysql -u STAGING_DBUSER -p STAGING_DBNAME < data.sql

Just like before, you’ll be prompted to enter a password, but this time it will be for the user who has privileges for the staging database.

Update Configuration

Using your favorite text editor, open up the following file from the staging directory:


Replace the values for lines 44-46 with the database details for our staging database.

Now we need to do is update the Unsecure and Secure URL for our staging store:

  1. Login to cPanel for your domain, and click on the phpMyAdmin icon.
  2. From the sidebar on the left, click on the _staging link.
  3. Click on the SQLtab, and in the text area, run the following command:
    SELECT * FROM `core_config_data` WHERE `path` LIKE '%base_url%';
  4. Click the Check All link and then click on the pencil icon.
  5. Update the value fields with the URL for your staging site.
  6. Click on the Go button at the very bottom to save your changes.

Upgrade Staging Store

Before You Upgrade

Please read this article in our Magento Group before you upgrade your store! There are numerous posts on the Magento forum about users who have tried to upgrade a copied store and inadvertently upgraded the wrong store.

Now that our staging store is setup, we can upgrade it to make sure everything goes smoothly. These commands will be done via SSH in the staging directory.

A little cleanup first:

rm -rf downloader/pearlib/cache/* downloader/pearlib/download/*

Set the permissions on the pear file so we can run it:

chmod 550 pear

Initialize the PEAR channel just in case:

./pear mage-setup .

And then we can upgrade:

./pear upgrade-all

If it tells you that there’s Nothing to upgrade, you’ll need to do this instead:

./pear install magento-core/Mage_All_Latest

Cleanup & Permissions

Lastly, we need to clear out any temporary and cached data. These commands will be done via SSH in the staging directory.

rm -rf downloader/pearlib/cache/* downloader/pearlib/download/* rm -rf var/cache/ var/session/ var/report/ media/tmp/

And then reset our file and directory permissions:

find . -type f -exec chmod 644 {} ; find . -type d -exec chmod 755 {} ; chmod 550 pear

You can now open up your staging site in your browser to see if the upgrade process worked or not.

After You Upgrade

After you upgrade your store, don’t assume everything is working correctly because your site is coming up without errors. Use this time wisely to go through your entire site, including the backend:

  • If your navigation has dropdown items, make sure they work
  • Search for a product to see if anything comes up in the results
  • Make sure you can add a product to your cart and purchase it
  • Check if your layered navigation is intact
  • Create or edit an existing product, making sure you can save it

If you do come across any errors, check the community forum to see if others are experiencing the same issue.

If you can’t find anything, create a new thread to see if anyone can assist you.