Magento on Amazon Linux EC2: Automated Script (January 2017)

Ron Peled 1:07 pm

Through the past 12 months, all of our Magento deployments go on AWS EC2. Their infrastructure, prices, and their ability to auto scale properly make it very attractive for companies to host on AWS. We’ll eventually share our terraform scripts for deploying Magento 1 or Magento 2 on AWS, however today we’ll share the automated script we use to setup Amazon Linux with the right packages in order to run Magento successfully.

So, we typically start off with the latest version, currently it is Amazon Linux AMI 2016.09.1 which was released on 2016-12-22. You’ll need the specific AMI ID which can be found on the IDs section (scroll down) of the Amazon Linux AMI page. For best performance we recommend at least an instance type of c4.large or anything larger from the compute optimized family of instances.

In our terraform script, we have a shell script that we upload and execute on to the web node which sets up the environment for Magento. Here is the script, feel free to copy and paste:

It is pretty self explanatory for those who are going to use it, but here is a short list of what we’re doing:

  1. Update current system and log output to a tmp file
  2. Install the following: php 7.0 (with all needed packages), Apache 2.4, MySQL client, and Git
  3. Setup Apache to start on boot
  4. Start Apache
  5. Add a group named ‘www’ and we include both ec2-user and apache users in the group
  6. Setup folder /var/www/ owner to apache and group to www
  7. Set the permissions with a sticky bit

We do have a variation of this script for deploying sites that are compatible with php 5.6, which is very similar and you just need to replace all php70* packages with php56* names with some exceptions since packages changed from 5.6 to 7.0.

This setup seems to be working really well for both Magento 1 and Magento 2. Magento 2 may need a few extra steps regarding folder permissions in particular with the generated folders.

I hope this saves you some time, if you have any recommendations or tips on how you setup your environment, leave a comment or let us know!


Related Posts:

Ron Peled

About Ron Peled

Builder of things. Builder of teams. Passion: eCommerce & Marketplaces. Magento expert. CTO Mentor.