Setting up a Magento Staging Area
Posted on March 16th, 2011 in Magento | 4 Comments »
Copy Production Store
-
Login to SSH and go to the Document Root for the staging directory
cd staging -
Copy all data from the live site to the staging directory
cp -R ../public_html/* ../public_html/.htaccess .
-
Copy production database to staging database
mysqldump -u PRODUCTION_DBUSER -p PRODUCTION_DBNAME > data.sql
mysql -u STAGING_DBUSER -p STAGING_DBNAME < data.sql
-
Change credentials to store staging database configuration in:
~/staging/app/etc/local.xml
-
Run the following sql query on the staging database and update the values to point to the staging url:
SELECT * FROM `core_config_data` WHERE `path` LIKE '%base_url%';
Update (7/21/2011): Git
Not sure why it took me this long to finally get the Tech And House site on Git, but finally did it today. I’m currently versioning just the app and skin folders and the themes that are in use, everything else has been placed in .gitignore. Since the staging domain is on the same server as the production domain, my hosting provider flips and disables my backups because I’m not allowed to have that many files on the server. I have to make my updates on dev, test on staging and right after pushing to production, I need to clear out my staging server. If you’re in this boat, here are the steps I follow:
Steps on Staging Server:
- Make changes on development box, git commit, git push
- Prep staging server by pulling production code to staging folder
cp -R ../public_html/* ../public_html/.htaccess .
- Since we keep deleting all the files on the staging server, reset it to the last committed state of the git repo:
git reset --hard HEAD - Pull changes that were made on the development machine:
git pull
- Set permissions and clear cache and sessions
find . -type f -exec chmod 644 {} \; find . -type d -exec chmod 755 {} \; chmod o+w var var/.htaccess includes includes/config.php app/etc chmod -R o+w media chmod -R 755 var rm -rf var/cache rm -rf var/session chmod 550 mage chmod 550 pear #chmod 550 pear Magento <= 1.5 chmod 550 mage for Magento >= 1.5
- Update database connection details to point to the staging servers db: /app/etc/local.xml
Maybe “Update 2″ will have Capistrano involved handling the deploy as well, but for now, I’m ok with this little setup. Usually just skip staging all together as thats the most time consuming process due to hosting providers TOS. Change/Test on dev, git pull straight to production.
4 Responses
Once the staging site is correct, how do you move folders and files from the staging area back down to …./public_html/ using SSH
Hi Col,
As of this moment, I make module and core changes on the staging server. If it works, I perform the update on the production server.
If you are developing your own modules or actively making any changes to your site, I’d recommend using git to version control your app and skin directories. If everything works on staging, git pull to your production server.
Hope this helps,
Amit
Hey Amit,
Would this be the proper way to do a local to staging to prod setup?
Make Local Changes > Push to GIT Repo > GIT repo to Staging > Staging to Production
Thanks in advance.
Hi Justin,
Yes, that would be a proper local, staging to prod setup.
Amit