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 a setup that provides both. Running Magento on a Zend Server cluster running on AWS gives you the ability to easily and safely scale your operation in case of sudden spikes in traffic, 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.
Magento Cluster Steps overview
The process described in this tutorial consists of several steps.
First, we’re going to launch two Zend Server instances on AWS. We will then connect the two servers to a MySQL RDS instance that will serve as the cluster database.
Next, we’ll set up a load balancer in charge of splitting the traffic between the two servers.
After the load balancer is up, and the cluster is functioning properly as a cluster, we’ll create another MySQL RDS instance for handling the Magento database.
Finally, we’ll deploy a Magento application on the cluster.
To follow the steps described in this tutorial, you will need the following.
- An AWS account. Create one here.
- Magento application package (.ZPK). You can download it here.
- 30 mins (approx) of spare time!
Let’s get started!
Step 1: Launching the Zend Server nodes
Our first step 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.
Step 2: Creating the cluster database
Zend Server clusters require a central database on which to store the cluster blueprint and cluster configurations. Our next step 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).
Step 3: Building the cluster
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.
Configuring cluster networking
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:
- Type – All traffic
- Source – Custom IP
- IP – the VPC ID (from the main security groups list)
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.
Launching the Zend Server UI
Our next step 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!
Creating the cluster
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:
- Server Name – a display name for your server (e.g. server1)
- Node IP – enter the private IP (3) of the Zend Server instance, can be retrieved from the instance’s Description tab
- Database Host – the IP of the server hosting the database. Go back to the RDS dashboard, select the RDS in the Instances list, and copy the RDS endpoint and then enter your RDS details. Be sure to remove the ‘:3306’ from the end.
- Database Name – the name of the RDS database
- Database Username – the username you selected for the RDS database
- Database Password – the password you selected for the RDS database
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.
Step 4: Configuring the load balancer
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.
Step 5: Deploying Magento
While we’re waiting for the DNS to update, we’re going to complete the final step of this tutorial which is to deploy Magento.
Creating another database
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!
Creating a new virtual host
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.
Deploying the application
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!
Testing the Magento app
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.
Hope you enjoyed the read! If you have any feedback, please let us know at: email@example.com