I always encounter two main problems when it comes to the deployment of small- and medium-sized Magento shops. First, when I take over a shop, there is often no deployment process at all. Second, when people talk about the deployment process for Magento shops, it is always about big projects. I understand that this is more challenging and may sound more attractive to some of you, but I think it is also important to talk about the deployment process of smaller Magento shops. So here we go!
But first of all, if you work for big shops, you may be more interested in the following resources:
- Rock-solid Magento Deployments (and Development) by Fabrizio Branca
- AOEpeople Magento Deployment Scripts
- Continuous Integration with Magento Community 1.7-1.9 by Aleksey Razbakov (also available as a YouTube video)
- Magentify – Magento Deployment with Capistrano (by the way, this one may also work well for smaller shops)
Most of the approaches discussed there are just overkill for moderately sized shops running on a single web server. But having a deployment process is equally important to them. Why is that the case? Why don’t we just copy and paste the files somehow on the server?
- Version Control System: We all use a version control system, preferably git. You should not expose your .git directory. So you are not able to do something simple like a git pull.
- Database Updates: Install/upgrade scripts may run multiple times which can lead to various problems.
- Inconsistent extension state: When you simple copy and paste the files, an extension may be in an inconsistent state. Some files of the extension may already have been updated, while others may not. This can lead to various problems, including that database updates of this extension are not executed at all.
Convinced that we need a somehow more sophisticated approach? Alright, so what should we basically be doing when rolling out a new version?
- Getting the specific version from the version control system (preferably git).
- Preparing the code for use in production, meaning:
- [only necessary when not using modman] Copying the local.xml with the live database credentials and settings to app/etc.
- [only necessary when not using modman] Removing the .git directory (yes, you should do that).
- [only necessary when not using modman] Symlinking the media folder
- [only necessary when not using modman] Copying session files
- Enabling the maintenance mode
- Exchanging the old with the new code
- Clearing the cache (including APC)
- Running the install/upgrade scripts
- Disabling the maintenance mode
Interested in some real sample code? I created a GitHub repository containing two sample bash release scripts. One assumes that you have all the Magento code under version control, the other one assumes that you use modman and only have the .modman folder under version control (my preferred way). In order to use them, you theoretically simply need to change the settings in the first section. But since systems and requirements are quite diverse, you may want to simply use the scripts as a template and optimise them for you. Mind that these scripts come with absolutely no warranty. You should test them thoroughly on a test system before using them in production. Feel free to contribute!
Update 2015-08-16: Daniel Fahlke gave me the hint to have a look at Deployer. Interesting idea, although Bash has the advantage that it does not have any dependencies and can be run „everywhere“.
Thanks for the valuable hints.
Using „git pull“ for deployment is well possible. If your Magento dir is in a sub directory (like „www“ or „htdocs“ or whatever), your .git dir won’t be exposed as the web root will also point to that sub directory. I do agree though that some sort of deployment makes sense especially because of the need to run update scripts in maintenance mode.
I’d also recommend using composer in addition to modman as it makes it easier to handle the modules.
Thanks, Andreas! Means much from you!
Regarding git: When writing this bullet point I knew someone would say that 🙂 Anyway, I guess people barely do it this way.
Composer is a good addition. I think Magento 2 will be the entry point for me to finally use Composer 🙂