Innovate faster and cut risk with PHP experts from Zend Services.
Beginning to advanced PHP classes to learn and earn global certification.
Help me choose >
Submit support requests and browse self-service resources.
Magento applications running on the cloud need an infrastructure suited for their specific requirements. To avoid slow page loads and ultimately lost revenue,high availability and scalability are critical for a Magento store.
This tutorial describes how to get the performance and reliability you need by describing a Magento cluster setup in AWS using Zend Server. Running a Magento cluster on Zend Server in AWS gives you the ability to easily and safely scale your operation in case of sudden spikes in traffic. You will also gain powerful application monitoring capabilities and performance optimization tools.
Zend Server’s architecture is ideal for Magento apps as it automatically propagates any changes to configurations across all the servers in the cluster. Scaling up? Applications and configurations are deployed and applied to any new server in the cluster. And with Zend Server’s Session Clustering, sessions are shared across the cluster providing your cluster with a fault-tolerant and high-performing session storage mechanism.
This tutorial describes a Magento cluster setup process that includes the following steps:
To follow the Magento cluster setup steps described in this tutorial, you will need the following.
Let’s get started!
Our first step in the Magento cluster setup is to launch the backbone of our future cluster: two Zend Servers running on AWS.
To do this, access the AWS Management Console (you’ll need to use your AWS account), and select the EC2 compute service to open the EC2 dashboard.
Click the Launch Instance button, and step 1 of the AWS instance launch wizard is displayed.
Select AWS Marketplace from the menu on the left, and use the search field at the top to search for ‘Zend Server’.
A list of all the available Zend Server AMIs is displayed.
Various Zend Server editions and versions are available, going back to Zend Server 6.3 with PHP 5.3 LTS support, but in this tutorial I’m going to go for the PHP 5.6 - Zend Server 8.5 Professional Edition (Ubuntu) image by clicking the adjacent Select button.
Select one of the available instance types. Instances are basically virtual servers with varying hardware setups. Depending on your application and the load you expect, select which combination of CPU, memory, storage, etc. you think you need.
For this setup, an m3.medium instance should suffice.
On this third step of the AWS instance launch wizard we get to configure the instance details, such as the number of instances you want to set up and networking configurations.
In our case, I’m going to enter ‘2’ for number of instances, leave the rest of the default settings as-is, and advance with the wizard until we reach step 6 - Configure Security Group.
This step is important as you’ll need to use the exact same security group for all the steps in the cluster. Be sure to make note of the name you give to the group (I’m going to name it ‘zs_cluster’).
Click Review and Launch, and then Launch, to continue on.
Your last step before the Zend Server images are created is to select an existing keypair or create a new one (for securely accessing the machines via SSH). Then, accept the note at the bottom of the dialog, and click Launch Instances.
Your Zend Server instances are launched! This will take a few minutes (you can check on their status in the Instances list within the EC2 Console), but in the meantime you can advance on to the next step of the tutorial.
Zend Server clusters require a central database on which to store the cluster blueprint and cluster configurations. Our next step in the Magento cluster setup describes how to create a MySQL database using the AWS RDS service.
So first, go back to the AWS Management Console, and select RDS under the Database section.
From the menu on the left, select Instances, and then click the Launch DB Instance button.
A list of available database engines is displayed, and MySQL is usually selected by default. If not, select it and click the Select button.
Next, depending on your needs, select whether to use Multi-AZ Deployment or not (best for production environments), and continue on to the next step.
Select a DB Instance Class from the relevant drop-down menu (again, based on your requirements), and configure your DB Instance Identifier, Master Username and Master Password (tip: write these down somewhere).
On the next step, select one of the Availability Zones, and make sure you select the same VPC Security Group used for your Zend Server cluster (‘zs_cluster’ in our case).
Then, enter a name for the database name, leave the rest of the settings as-is, and click the Launch DB button.
Your MySQL RDS instance is launched! (the initialization process usually takes a few minutes).
So, we have two Zend Server instances and one RDS instance up and running. It’s time to connect these components together and build the cluster.
Before we build the cluster, we need to configure the networking setup to allow all types of traffic within the same security group.
So once the RDS instance is ready (you can tell by the green available status in the Instances list), go back to the EC2 console, and from the left menu select Security Groups under Network and Security.
Select the security group you created, and then open the Inbound tab. Click the Edit button, and add the following rule:
Click Save when you’re done.
We now have the required networking configurations in our cluster without exposing ourselves to any critical security risks. In case of a production environment, you’ll probably want to consider a more conservative solution.
Our next step in the Magento cluster setup process is to launch the Zend Server UI for the first time.
Open the EC2 console, and select one of the instances from the Instances list. In the Description tab at the bottom of the page, copy the public IP (1).
Open your browser with the following URL:
The URL includes the public IP of the instance and the port the Zend Server UI listens on - 10081.
You will need to use the instance ID (2) to authenticate, and you’ll see the Zend Server Launch wizard.
Read and accept the license agreement on the first page of the wizard, and click Next.
You can now select which server and system settings to launch Zend Server with. Select Production (Single Server), and continue on.
On the User Passwords page, enter a password for accessing Zend Server as admin, and then complete the remaining steps of the wizard. Click Launch on the last page.
Congrats! You’ve successfully launched Zend Server!
We will now create our cluster.
In the Zend Server UI, go to the Servers | Manage Servers page (use the menu on the left), and click the Join Cluster button.
Enter the following details:
Once you’re done, hit the Join Cluster button and your cluster is created!
All that’s left now to complete the picture is to add the second server. Click the Add Server button.
Enter a display name for the second server (e.g. server2), use the private IP of the second Zend Server instance in the Server IP field, and click Add Server.
Note: You may get an error on this step which you can ignore. Just refresh the page to make sure the second server is indeed added correctly.
Before we deploy our Magento application, we’re going to add a load balancer to our cluster.
In the EC2 console, select Load Balancers from the menu on the left, and then the Create Load Balancer button.
Enter a name for the new load balancer (‘lb1’), and from the Create LB Inside drop-down menu, the default VPC.
On the next step, select your security group again (zs_cluster) and advance to the Configure Health Check step (step 4).
In the case of Magento, I’m going to change the Ping Path to ‘/’ instead of '/index.html' because in most cases we will likely be using PHP pages instead of an ‘index.html’ file.
On step 5, select the two Zend Server instances you launched, and advance to the final Review step where you can hit the Create button to create the load balancer.
AWS then automatically creates a new DNS record for you (usually looks something like http://zscluster02-1429870263.us-east-1.elb.amazonaws.com/), and because it’s a DNS change, this might take a few hours to complete.
After this URL becomes accessible from your browser you'll be able to see Apache’s default page, and your two servers will be running behind a load balancer with traffic to these servers routed to either of them randomly.
It’s important to point out that as long as you’re using Zend Server as your application server, you can add as many servers as you like. Applications and configurations are immediately deployed on any new server and sessions shared thanks to Zend Server’s Session Clustering feature.
While we’re waiting for the DNS to update, we’re going to complete the final step of this Magento cluster setup tutorial which is to deploy Magento.
Since we can’t use the same database for both Magento and the Zend Server cluster, I’m going to have to create another RDS instance exactly the same way I created the database for the Zend Server cluster.
Again, remember the credentials you define and most importantly - make sure you select the same security group!
Next, we’re going to create a new virtual host for our Magento application.
Access the Zend Server UI again, and go to the Applications | Virtual Hosts page.
Click the Add Virtual Host at the top of the page and enter a name for the virtual host (e.g. ‘www.yourdomain.com’).
The remaining default settings are good enough in most cases so you can just click Next for all the other steps of the wizard.
Next, go to the Manage Apps page, and click the Deploy Application button.
Upload the Magento application package (.ZPK) supplied with this tutorial, and click Next.
On the Application Details page, be sure to select the virtual host you created.
Continue on with the deployment wizard - read and accept the license agreement and validate application prerequisites (Zend Server will notify you if these are not met).
On the User Parameters page, enter the details of the new database you created. As the database host, use the new database’s endpoint without ‘:3306’, and enter the remaining database details as you defined when creating the new RDS instance.
Take note of the Magento admin user name and password as you will need them to access the Magento Admin panel.
Continue on with the wizard, and on the last page - click Deploy.
Zend Server deploys the Magento application onto the cluster!
To test the application in your browser, add a new record to your hosts file with the IP of the load balancer (ping the load balancer to retrieve an IP to use in the record).
To open the application you can simply click the URL in the application’s expanded view in the Zend Server UI.
To verify that the sessions and the cluster are working as expected, open the Magento admin panel at: http://www.yourdomain.com/admin and enter the credentials you chose when you deployed the application.
If login succeeds, and the Magento admin works as expected after browsing through some pages in the CMS, you can be sure that the sessions and cluster are fine.
You’ve successfully deployed your Magento app on Zend Server on AWS. Now what?
Zend Server ships with a variety of tools you can use to monitor and optimize your applications: Zend Monitoring, PHP configuration, Z-Ray, Page Cache, Job Queue - to name just a few.
A good way to get to know these features is the Getting Started page in the Zend Server UI. On this page you’ll find information and resources you can use to start getting acquainted with the various features.
If you want to learn how to run Magento on Zend Server Cluster on AWS, you can find a simple tutorial in this blog post.
Zend Server Cloud Solutions