I needed to create a Magento Staging Area for both common development tasks and testing the latest upgrades.

In order to create the staging area for my Magento store I’m going to create a mirror of it at a subdomain. I host on my own Linux server and use Godaddy to manage my domains.

My main Web site will be referred to as www.domain.com. I’ll be creating the Magento development site at dev.domain.com. Below is a step by step documentation of the steps taken to create my Magento staging area using virtual host.

Create CNAME Record:

=> login to Godaddy
=> select Domains : My Domains
=> select your domain (domain.com)
=> select Total DNS Control and MX Records
=> select Add New CNAME Record
=> enter (dev) as Alias Name
=> enter (domain.com) as Host Name

Create Staging Files:

=> copy live file directory to dev
=> run cp -R store.domain.com dev.domain.com

Create Staging Database:

=> create new Dev database
=> dump Production database
=> mysqldump –opt –user=liveuser –pass=livepass livedbname > livedbname.sql
=> load Staging database
=> mysql -u devuser -p devdbname < livedbname.sql

Setup Virtual Host in Apache:

=> locate conf file (ie httpd.conf, vhosts.conf)
=> create VirtualHost entry for dev.domain.com
=> locate apachectl
=> run ./apachectl configtest
=> run ./apachectl restart

Sync Staging Site DB Credentials:

=> editapp/etc/local.xml
=> edit lines
=> edit lines
=> edit lines

Sync Staging Site Database Settings:

=> login to MySQL dev database
=> find config to edit
=> SELECT * FROM `core_config_data` WHERE `path` LIKE ‘%base_url%’;
=> update path web/unsecure/base_url
=> update path web/secure/base_url

Cleanup Staging Site:

=> rm -rf downloader/pearlib/cache/* downloader/pearlib/download/*
=> rm -rf var/cache/* var/session/*

It might take a while to shake out the cache, but that should basically get you a Magento staging server — a snapshot of your live Magento site.

** Note: I pulled my hair out for hours trying to figure out why the dev url was not printing correctly. It just seemed that whatever I did the system wouldn’t pick up the new base_urls. What I did was restart apache which I’m assuming cleared cache and allowed for the update base_url to be picked up. Also, make sure var directory is writable.