Deployment of Magento in a scalable and redundant fashion is an important, yet complex task. Since Magento is often used for making online stores and shops, it’s important to ensure maximum availability and performance, as downtime can directly affect a company’s revenue.
In this blog, I am going to walkthrough how to setup and deploy Zend Server Cluster, which automatically scales from 2 to 10 nodes depending on the load on cluster nodes, along with Magento. For this walkthrough, we’ll focus on how to complete this set up on AWS, but the basic principles could be applied to other deployment options.
To achieve our goal, here are the steps we’ll take:
- Subscribe to Zend Server on AWS Marketplace and download the CloudFormation template.
- Deploy CloudFormation stack from the template downloaded. After deploying stack, we’ll have Zend Server Cluster that will automatically scale depending on load on the nodes.
- Deploy Magento on Zend Server Cluster.
This is the final step after which we will have Magento running on high available and auto scaled cluster.
Since we are going to run cluster on AWS you will need AWS account. Additionally it is expected that you know basic AWS terms like VPC, EC2 Instance, RDS Instance, etc. Additionally you have to be familiar with basic CloudFormation terms. Additionally I expect you to have a VPC for deployment (you can use default VPC if you want) and EC2 key pair ready for use.
CloudFormation allows allocation of AWS resources as described by template files which utilize JSON format. CloudFormation operates with stacks of resources where each stack is created using a template.
CloudFormation template for Zend Server Cluster can be acquired from 2 sources:
- AWS Marketplace has basic template that can be used to spin cluster.
- We have CloudFormation template generator on our website that has some additional functionality like adding additional RDS server or ElastiCache service to template.
In this blog, we’ll use the first method as it is the simplest one. Since we are going to deploy sample Magento web application, we’ll use same RDS instance that Zend Server uses for storing cluster information. However, I strongly recommend to setup separate RDS instance for Magento database when deploying real production environment (either by adding another RDS in CloudFormation template or by setting it up manually).
You can find list of Zend Server products on AWS Marketplace. Zend Server is available on Ubuntu Server 14.04 LTS or RHEL 7 Operating System. Additionally there are three Zend Server editions – Developer, Professional, and Enterprise (note that Developer Edition does not have clustering capabilities and is intended for development and testing use only). There are also two versions of PHP supported – 5.6 and 7.0. For the purpose of our demonstration we will use PHP 7.0 – Zend Server Professional Edition (Ubuntu).
Deploying Zend Server Cluster
Here are the steps to deploy Zend Server Cluster on AWS:
- Login to your AWS account.
- Open PHP 7.0 – Zend Server Professional Edition (Ubuntu) or other Zend Server product page on AWS Marketplace (note the Developer Edition has no cluster support).
- Click yellow “Continue” button in the right column.
- Ensure that “Manual Launch” tab is selected.
- Click yellow button “Accept Software Terms” on the right column. If you do not have such button, then you already have subscription to Zend Server product and should skip to step 7.
- You will be presented “Thank you” page with information and next steps. Read them and click blue button “Return to Product Page”. You will be taken back to launch page (reminder – ensure that “Manual Launch” tab is selected).
- In “Region” section, select region in which you want to launch your cluster.
- In “Deployment Options” select “Zend Server Cluster” (you can click “view” link next to it to see description schematic diagram of what Zend Server Cluster consists of)
- Click yellow “Launch with CloudFormation Console” button. If the button is grey and you see a message “Subscription is not ready. You will be able to launch in a few minutes.” just wait a few minutes (from what I know it takes something like 5 minutes until subscription is ready).
- You will be taken to CloudFormation Create Stack wizard on AWS Console. URL for template is already prefilled, so all you need to do at this step is click “Next”.
- Next you have to fill all parameters that are required by the template. Please read carefully descriptions of parameters. A few notes:
· Subnets – you must specify at least 2 subnets in different Availability Zones.
· KeyName – existing EC2 key pair to allow SSH connections to instances of cluster.
· ClusterPassword – password to access Zend Server UI, must be at least 4 characters long.
· DatabasePassword – password for admin user on RDS instance, must be at least 8 characters long.
· Minimum and maximum size of auto scaling group – specifies limits to scale number of nodes. Take into account that CloudFormation template spins single server separately from auto scaling group. We want our cluster to automatically scale between 2 and 10 nodes as needed, therefore minimum must be set to 1 and maximum to 9.
· SSHLocation – IP address range from which SSH connections are allowed to nodes of cluster. For example w.x.y.z/32 to specify single IP address. 0.0.0.0/0 to allow SSH from anywhere.
- Once all parameters are filled, click “Next”.
- Options allow you to customize some CloudFormation allocation parameters. It is safe to leave defaults. Just click “Next” to go on.
- Final step is “Review”. Here you will be presented with summary. One important note here is to ensure that checkbox “I acknowledge that AWS CloudFormation might create IAM resources” is checked. Then click “Create” button.
- All that is left now is to wait till CloudFormation sets up Zend Server Cluster for you. It will take a few minutes.
- Once cluster is ready, click on stack and open “Outputs” tab. There you will find DB credentials, URL of Load Balancer, and URL of Zend Server UI – you will need those to deploy Magento in next section.
- Open Zend Server UI (use link in “ZendServerUI” output of CloudFormation stack deployment) and login with password you specified during the CloudFormation template deployment.
- In Zend Server select in menu on the left “Applications” > “Manage Apps”.
- Click on “Deploy application” button on top of the page. Application deployment wizard will be shown.
- Click “Choose File” button and select Magento ZPK you downloaded.
- Wait till ZPK is uploaded and then click “Next” button.
- Next step is “Application Details” where you can customize path under which application is deployed and Virtual Host. Deploying Magento to root of Virtual Host on AWS can lead to unwanted result because ELB expects our nodes to return HTTP 200 when request is made to / on server, while Magento will return 302. This will lead to a situation where ELB will consider all nodes of cluster unavailable and return error. This can be avoided by adding health check file to Magento ZPK and modifying ELB configuration to check against this file. But this is outside of scope of this article. Instead we will simply deploy Magento under “magento” path. For this just enter “magento” in path and click “Next” to continue. all values at this step at their defaults and just click “Next”.
- Next step is “License Agreement”. You have to agree to Magento License Agreement by setting checkbox “I have read and agree to the license agreement” and clicking “Next”.
- Next step is “Prerequisites Validation” that validates that PHP configuration and extension requirements are met. If validation is not passed, you will have to go to “PHP” > “Extensions” and check PHP and it’s extensions configuration there (Tip: to easily find needed directive on “PHP Extensions” page, you can use search box located in top right corner). Once validation is passed, click on “Next” button.
- Now you have to fill in all parameters of Magento ZPK. For this demo use database parameters that are available on CloudFormation outputs tab. Other than that, please read descriptions of parameters carefully. Once all parameters are filled, click “Next” to continue to next step.
- Last step before deployment shows you everything for a review before starting deployment. Click “Next” to start deploying Magento application.
- 11.Wizard will now close and we are back to list of applications, but this time it’s not empty. Once deployment is finished the application will appear as deployed. This means that we can take ELB URL from CloudFormation output, append “magento” to it and see our shop up and running.
We are going to deploy Magento 2.1.2 which is the latest version of Magento available as of writing of this blog. We are going to deploy Magento using Zend Deployment which simplifies deployment of PHP applications on Zend Server and provides additional features like customizable hooks for different stages of deployment and rollbacks.
Zend Deployment deploys Zend Deployment Package files, which is basically a zip archives with some predefined structure. You can read more about Zend Deployment here.
Zend Server ships with a few demo ZPK (Zend Application Package) applications including Magento. Unfortunately Magento ZPK that is shipped with Zend Server 9.0 is Magento 220.127.116.11. Although next version of Zend Server will have new Magento version, it is not ready yet. So for this article I developed my own Magento ZPK which utilizes Magento CLI in hook scripts to automate deployment. ZPK is available freely here. Please feel free to use this package as starting point for your customizations as needed.
Steps to deploy Magento on Zend Server Cluster:
We now have fully working Magento running on top of Zend Server Cluster which automatically scales between 2 and 10 nodes as needed.
This is a very basic setup of Magento. To make things more like production, we could create additional VirtualHost dedicated for our Magento shop and deploy application on it. This would allow deploying Magento to root of Virtual Host and ELB would still make it’s health check requests against default Virtual Host, which is empty and would return HTTP 200.
What is really important is that you can use this guide as a starting point if you want to run your own Magento 2 store on AWS with high availability and auto scaling. Source of ZPK is available in GitHub repository.
If you look into sources of ZPK, especially pre-activate and post-deactivate scripts, you will find that this ZPK even sets up Magento cron for you. Therefore Magento deployed from this ZPK is almost fully ready for production use.