Easy steps to install Magento2 with PHP7 on Amazon EC2 ?

Install Magento2

If you are planning to run an online store for your products, the first choice you get from eCommerce experts would be Magento eCommerce store. Magento is vastly used eCommerce platform by online sellers. Once Magento platform has been chosen next challenge to select hosting where your store run smoothly. Amazon EC2 is most preferred hosting service and widely used by eCommerce store owners. But how can someone install Magento2 on amazon EC2 without any technical help? The answer is to use the Amazon Machine image(AMI) which has in built environment for Magento.

It has been a long time since Magento2 is being launched and now it is replacing Magento1.9.x with powerful features. It’s easier to use Magento2 with php5.6.x and apache2 but the problems occur when you want to install Magento2 latest third party plugins.

is there any issue to install Magento2 plugins or it’s a rumor by Magento2 critics ? Well, it’s not a rumor and we faced this issue while working on one of our clients. In this article, we are going to cover these issues for Magento2 server configuration and explore the available solutions.

How did it happen ?

We used scalable Magento2 stack AMI for an online store with the following configuration.

It works quite well for default Magento2 but things went nasty when we try to install the one of the latest plugins.

magetno2-plugin-error

magetno2-plugin-error

What were our key issues finding ?

1. PHP version : There is not standard binary for php7 for Amazon Machine at the time of writing and we faced following issues:

  • Should it would be compatible with currently running apache server. We tried to install php7-php module from remi but it’s not compatible with Apache 2.4
  • Are all required PHP extensions by Magento available ?

2. PHP extensions :
It is very easy to install PHP extension but consider when one of the extension have library dependencies.

  • How did we find the correct version of the library ?

There may be lots of available libraries, we only have the options to hit and try.
3. Setting Cron for Magento : This is also quite complex like permission fight, the issue with default php.ini path after installing PHP7 etc.

How do we solve these problems and install Magento2 on the Amazon Ec2 with Php 7?

1. Install PHP7.0.7 from Remi

Remove php if available

sudo yum remove php5*

Add the following repository:

wget http://mirrors.mediatemple.net/remi/enterprise/remi-release-6.rpm
sudo yum install remi-release-6.rpm

Edit the following file

/etc/yum.repos.d/epel.repo and set enabled=1

Execute the following command

sudo yum upgrade -y
sudo yum install php70


Install the following extension

sudo yum install php70-php-fpm
sudo yum install php70-php-xml
sudo yum install php70-php-pdo
sudo yum install php70-php-mysqlnd
sudo yum install php70-php-pdo
sudo yum install php70-php-imap
sudo yum install php70-php-intl
sudo yum install php70-php-zip
sudo yum install php70-php-pecl-apcu
sudo yum install php70-php-mbstring
sudo yum install php70-php-mcrypt
sudo yum install php70-php-opcache

To add php70-php-gd extension execute the following command

sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/libwebp-0.4.3-3.el6.x86_64.rpm
sudo yum install php70-php-gd

Start the fpm daemon manually each time server rebooted

sudo /etc/init.d/php70-php-fpm start

or to auto start PHP on reboot use the following

sudo chkconfig php70-php-fpm on

Switch Apache from prefork to mpm event process (this is required because mod_php isn’t thread safe) in /etc/httpd/conf.modules.d/00-mpm.conf

LoadModule mpm_event_module modules/mod_mpm_event.so

and comment others.

Instruct apache to pass all php requests to php-fpm by adding the following lines in /etc/httpd/conf/httpd.conf

<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9000"
DirectoryIndex /index.php index.php
<FilesMatch>

Restart apache using sudo service httpd restart. If everything went ok you should be able to verify the installation by requesting a php file containing phpinfo().

If you have existing shell scripts that use php’s cli interpreter and thus start with #!/usr/bin/php, you have to set up a symlink to /usr/bin/php since the binary is now named /usr/bin/php70. You can do this as follows:

sudo ln -s /usr/bin/php70 /usr/bin/php

2. Install Magento2

Now download Magento and upload it to /var/www/html/ or you can install using composer.
Give appropriate permission of app/etc, cron.php and var/ directory.
create a cron tab for Magento user eg.

sudo crontab -u ec2-user -e

add following lines:

* * * * * sudo /usr/bin/php70 -c /etc/opt/remi/php70/php.ini /var/www/html/bin/magento cron:run >> /var/www/html/var/log/magento.cron.log
* * * * * sudo /usr/bin/php70 -c /etc/opt/remi/php70/php.ini /var/www/html/update/cron.php >> /var/www/html/var/log/update.cron.log
* * * * * sudo /usr/bin/php70 -c /etc/opt/remi/php70/php.ini /var/www/html/bin/magento setup:cron:run >> /var/www/html/var/log/setup.cron.log

now check:

sudo crontab -u ec2-user -l

restart cron service

sudo service crond restart

A Quick and Easy Solution : Magento2 stack AMI on AWS

If you are a non-technical person, want to setup your eCommerce website in few minutes ? Use Magento2 stack AMI and run your online store in few minutes on amazon cloud. It is ready to run, prebuilt environment setting for scalability, performance and high availability for your online store.
Following are the some vendor that provide Magento Stack AMI on AWS:
Magento2 stack AMI – by iPragmatech
Deploy Magento on Amazon Web Services by Bitnami

Conclusion

In this article, we have described the common issue of Magento2 server configuration which is quite a time taken as well. Though there may be more configuration issue which someone face and may take few hours to a day. We suggest using easy to go solution which saves time and effort instead of configuring everything by your own.

Reference

Magento
Magento Cron Setup
Install PHP 7 on EC2 t2.micro Instance running Amazon Linux Distro

Easy steps to install Magento2 with PHP7 on Amazon EC2 ? was last modified: June 8th, 2016 by Manish Kumar