Loading..
Processing... Please wait...

Product was successfully added to your shopping cart.



Magento 2 on AWS Debian Jessie 8 Dirty Cheap with Spot Instance

For my performance benchmarks I often need a Magento 2 instance for a limited period of time.

I have found out that using Amazon EC2 instances is the cheapest way to have magento 2 sandbox. And coupled with spot instance requests it becomes dirty cheap (as low as $0.0089 per hour ie 0.0089*24*30 = $6.4 per month!).

AWS Spot Instances Prices AWS Spot Instances Prices

 

1. Amazon Spot Instance Request for Magento 2

I will show you how to get cheap AWS spot instance.

1. First go to Amazon dashboard and click on Instances > Spot Requests on the left:

AWS Spot Requests AWS Spot Requests

2. Click on blue button Request Spot Instances.

Spot Instance Settings Spot Instance Settings

3. Choose instance type. Choose AMI. I prefer Debian 8 - you can find Debian Jessie image IDs here.

4. Click on Next. Create key pairs and security group. Click on Review and then create spot request.

5. It should allocate your instance within minutes. Then you are ready for step 2.

 

2. Magento 2 on Debian 8

1. Mysql 5.7

First we need to install database. The latest Magento 2.1.3 supports Mysql 5.6 and 5.7.

If we try to install mysql 5.6:

apt-get install mysql-server-5.6

we get dependency problem in return:

root@ip-172-31-29-113:/var# apt-get install mysql-server-5.6
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mysql-server-5.6 : Depends: mysql-common (>= 5.6.22-1~) but 5.5.54-0+deb8u1 is to be installed
                    Recommends: libhtml-template-perl but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Debian 8 won't allow us to install Mysql 5.6 but there is a workaround.

1. Download Mysql APT configuration tool:

wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb

2. Install it:

dpkg -i mysql-apt-config_0.7.3-1_all.deb

It will ask for database version (5.6 or 5.7):

Mysql Server 5.7 on Debian 8 Mysql Server 5.7 on Debian 8

Select whatever version you like (I prefer 5.7) and OK.

3. Update repository:

apt-get update

4. Install Mysql Database:

apt-get install mysql-community-server

Originall published as How to Install Mysql Server 5.6 or 5.7 on Debian 7 or 8

Create magento 2 database:

mysql> create database magento2;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on magento2.* to 'magento2'@'localhost' identified by 'magento2';
Query OK, 0 rows affected, 1 warning (0.00 sec)

 

2. PHP-FPM 7

1. Add these two lines to /etc/apt/sources.list

deb http://packages.dotdeb.org jessie all
deb-src http://packages.dotdeb.org jessie all

2. Install GPG keys:

wget https://www.dotdeb.org/dotdeb.gpg
sudo apt-key add dotdeb.gpg

3. Update repository:

apt-get update

4. Install PHP 7 and required modules:

apt-get install php7.0\ 
                     php7.0-apcu \
                     php7.0-cli \
                     php7.0-curl \
                     php7.0-curl \
                     php7.0-fpm \
                     php7.0-gd \
                     php7.0-intl \
                     php7.0-json \
                     php7.0-mbstring \
                     php7.0-mcrypt \
                     php7.0-mysql \
                     php7.0-opcache \
                     php7.0-redis \
                     php7.0-soap \
                     php7.0-xml \
                     php7.0-xsl \
                     php7.0-zip

Taken from How to install php 7 on debian linux

Increase max execution time in /etc/php/7.0/fpm/php.ini for browser requests - otherwise you won't be able to install magento 2 with setup wizard:

max_execution_time = 300

Of course you can still install magento 2 via command line:

./magento setup:install --admin-firstname="John" --admin-lastname="Doe" --admin-email="your@email.com" --admin-user="john" --admin-password="password1" --db-name="magento" --db-host="localhost" --db-user="magento" --db-password="password"

See official documention on how to use magento cli.

 

3. Nginx

Installing web server Nginx is simple:

apt-get install nginx

Magento 2.1.3 comes with nginx.conf.sample file that could be used as a reference to configure nginx.

Here is my /etc/nginx/sites-enabled/default file.

 

4. Magent 2.1.3 with sample data

Download the latest magento 2.1.3 from the official Magento Download page.

Extract it into /var/www/html folder - the default Nginx folder for site files.

apt-get install bzip2
cd /var/www/html
tar jxvf /home/admin/Magento-CE-2_1_3_sample_data_tar_bz2-2016-12-13-09-29-31.tar.bz2

Grant www-data user permissions to /var/www/html folder:

chown -R www-data:www-data /var/www/html
chmod -R 775 /var/www/html

Now go to web browser and type in public IP of your AWS instance - you should be presented with Magento 2 Setup Wizard screen.

Go through steps and install magento 2.

Magento 2 install on Debian 8 Magento 2 install on Debian 8
Magento 2 Successfully installed Magento 2 Successfully installed

Once it is installed you need to setup cron. Magento 2 is heavily relied on it.

export EDITOR=vim
export VISUAL=vim
crontab -u www-data -e

Then add these three jobs:

* * * * * /usr/bin/php  /var/www/html/bin/magento setup:cron:run
* * * * * /usr/bin/php  /var/www/html/bin/magento cron:run
* * * * * /usr/bin/php  /var/www/html/update/cron.php

Now it is all ready and you should have Magento 2.1.3 up and running.

 

 

 

If you find this post interesting do not hesitate to sign up for our newsletter and join the 721 people who receive Magento news, tips and tricks regularly.

Thank You!