Running Magento on Zend Server Cluster on AWS – Simple walkthrough

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:

  1. Subscribe to Zend Server on AWS Marketplace and download the CloudFormation template.
  2. 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.
  3. 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 template

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:

  1. AWS Marketplace has basic template that can be used to spin cluster.
  2. 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:

    1. Login to your AWS account.
    2. 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).
    3. Click yellow “Continue” button in the right column.

      Screen shot 1

    4. Ensure that “Manual Launch” tab is selected.
    5. 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.
      Screen shot 2
    6. 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).
      Screen shot 3
    7. In “Region” section, select region in which you want to launch your cluster.
    8. 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)
    9. 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).
      Screen shot 4
    10. 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”.Screen shot 5
    11. 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. to allow SSH from anywhere.
    12. Once all parameters are filled, click “Next”.Screen shot 6
    13. Options allow you to customize some CloudFormation allocation parameters. It is safe to leave defaults. Just click “Next” to go on.
    14. 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.
      Screen shot 7
    15. All that is left now is to wait till CloudFormation sets up Zend Server Cluster for you. It will take a few minutes.
      Screen shot 8
    16. 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.Screen shot 9

    Deploying Magento

    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 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:

    1. Open Zend Server UI (use link in “ZendServerUI” output of CloudFormation stack deployment) and login with password you specified during the CloudFormation template deployment.
    2. In Zend Server select in menu on the left “Applications” > “Manage Apps”.
    3. Click on “Deploy application” button on top of the page. Application deployment wizard will be shown.Screen shot 10
    4. Click “Choose File” button and select Magento ZPK you downloaded.
      Screen shot 11
    5. Wait till ZPK is uploaded and then click “Next” button.
    6. 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”.
      Screen shot 12
    7. 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”.
    8. 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.
    9. 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.
    10. Last step before deployment shows you everything for a review before starting deployment. Click “Next” to start deploying Magento application.
      Screen shot 13
    11. 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 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.

    The following two tabs change content below.

      Dima Zbarski

      Cloud Integration Engineer at Zend Technologies