Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento staging and production

I have been developing with magento for a while now and things are starting to make sense and become much more deliberate and organised. One aspect though still seems quite messy - moving a site from development to production.

Can anyone offer some good processes for this - up to now I have simply been exporting/importing the the development database, copying source files over, clearing out test orders, customers etc then changing base urls, htaccess files etc.

It all seems a bit messy and error prone. Do any of the more experienced Magento developers have a good process in place for this task that they could share.

like image 610
David Avatar asked Feb 06 '11 14:02

David


People also ask

What is Magento staging?

Staging functionality enables you to create scheduled campaigns, manage campaigns on dashboard and manipulate each future store object update. Moreover, you can preview a storefront during the future campaign.

Is staging the same as Production?

A staging environment (stage) is a nearly exact replica of a production environment for software testing. Staging environments are made to test codes, builds, and updates to ensure quality under a production-like environment before application deployment.

How do I sync staging and Production?

Under Staging Site, select the Actions menu and then select Sync Sites. Select Push staging to production. Only select Overwrite content if you want to overwrite the database as well as the files in your live production site. Select Sync.

What are 3 key benefits of the Magento cloud Production architecture?

Fastly Content Delivery Network (CDN), Image Optimization (IO), and added security with generous bandwidth allowances. The Web Application Firewall (WAF) service is available on Production environments only.


1 Answers

My process is usually managed around a source control repository (SVN in my case), which makes things much easier (or possible, really...). The idea is to keep everything possible in the repo and use SVN updates and tags to publish changes.

local.xml: I move this file in SVN to local.xml.dist and ignore the actual local.xml file in the repo. This lets you use different database credentials and hosts on your installations without polluting the codebase.

other ignores: Check out this question for more files that should be ignored in the database. Basically, anything unique to the environment should be kept out of version control and handled on the actual host. Your .htaccess files will be relevant here.

host setup: My staging environment and dev environments are set to run off of /trunk from the repository. Development occurs here, and can be pushed to stage periodically (or on demand) via svn up to show new features to the client and do UAT. The production environment needs some protection from the Wild West of trunk, though, so that environment runs off of tags. Whenever a feature set is ready to go out, I create a new tag from trunk and do an svn switch to move to the new code set. Doing things this way also gives me an easy undo for production (switch back to the last tag). Thus I have removed all manual file pushes from my life, which is good.

An even better system (which I've had no need for yet) would be to use svn export to create a complete copy of the code tree on the production system, and use ln to switch between them. Something like this:

> cd /home/apacheuser
> ls -l
www -> /home/apacheuser/tag_1.0.1
tag_1.0.1

> svn export /url/for/repo/tags/1.0.2 tag_1.0.2
... svn exports here ...

> rm www; ln -s /home/apacheuser/tag_1.0.2 www

That way, version changes are instantaneous.

db sync back from production: To allow me to work on production-ish data, I have a cron-job set up to dump the production database and import it into staging. While this is happening, the script will remove sensitive customer data (and change customer email addresses so that all emails go to me). It will also change credit card gateway settings to a test gateway and change the base_url parameters so that the staging site URLs work properly.

new development: You may notice here that different environments run off of roughly the same codebase (minus any new changes), which may seem troublesome to you from what you've noted about database changes etc.

The only way to manage this complexity (and the right way, at the same time!) is to make sure that the code itself keeps track of necessary changes to the environment. Magento supports automatic module version upgrades, including database scripts, which you should use to make schema changes, etc. This means that, as you deploy new code to staging/production (or as you get it from another developer in your dev environment), all database patches are applied automatically.

This also means that you need to write new functionality to be as non-destructive as possible. Magento themes, disabled modules and such can be used to make this a reality. For example, when creating a new theme for the site, make sure not to modify any of the core behavior, and keep all new assets in a theme that will be inert on production until deployed.

more developers: This setup is based around a relatively small number of developers on a project. There is an implicit assumption that, when you want to tag a new release, you can get trunk into a working state to do so. With more developers, this will be the case less and less, so a more complex repo setup is necessary. If I run into that, my plan is to move over to using git instead of SVN and to use feature branches for new development.


Let me know if any of that was unclear. Hope that helps!

Thanks, Joe

like image 113
Joe Mastey Avatar answered Oct 04 '22 17:10

Joe Mastey