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:
sudo yum update -y > /tmp/initfile.log
sudo yum install -y php70 php70-cli php70-common php70-gd php70-intl php70-json php70-mbstring php70-mcrypt php70-mysqlnd php70-opcache php70-pdo php70-pecl-imagick php70-process php70-soap php70-xml php70-zip httpd24 mysql56 git >> /tmp/initfile.log
sudo chkconfig httpd on
# TODO: add steps to opimize php and apache
sudo service httpd start
# Setup proper file and folder permissions
sudo groupadd www
sudo usermod -a -G www ec2-user
sudo usermod -a -G www apache
sudo chown -R apache /var/www
sudo chgrp -R www /var/www
sudo chmod 2775 /var/www
It is pretty self explanatory for those who are going to use it, but here is a short list of what we’re doing:
- Update current system and log output to a tmp file
- Install the following: php 7.0 (with all needed packages), Apache 2.4, MySQL client, and Git
- Setup Apache to start on boot
- Start Apache
- Add a group named ‘www’ and we include both ec2-user and apache users in the group
- Setup folder /var/www/ owner to apache and group to www
- 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!