Vous êtes sur la page 1sur 20

Free High Performance Web Hosting

For Magento 1.9x and 2.x

Revision 01

November 2016

ebm@affilinet.co

Honesty

This document is provided on an honesty based system for a fee

of $20USD paid to the author via PayPal ebm@affilinet.co or digital currency.

BITCOIN ETHEREUM
Contents

Free High Performance Web Hosting ........................................................................................................... 1


For Magento 1.9x and 2.x ......................................................................................................................... 1
Introduction .................................................................................................................................................. 2
Signup............................................................................................................................................................ 2
Download ...................................................................................................................................................... 2
Setup ............................................................................................................................................................. 3
AWS ........................................................................................................................................................... 3
Security Groups ..................................................................................................................................... 4
Instance ................................................................................................................................................. 4
Elastic IP ................................................................................................................................................ 5
Database ............................................................................................................................................... 5
Build .......................................................................................................................................................... 6
Core ....................................................................................................................................................... 8
PHP ........................................................................................................................................................ 8
Nginx ..................................................................................................................................................... 9
ConfigServer ........................................................................................................................................ 12
PHPMyAdmin .......................................................................................................................................... 13
Create Database .................................................................................................................................. 13
Magento ...................................................................................................................................................... 17
SSL ............................................................................................................................................................... 18
Common Commands .............................................................................................................................. 18
Conclusion ................................................................................................................................................... 19

Copyright 2016 eBookMark, all rights reserved Page 1


Introduction
This guide provides the complete instructions to build a high performance web hosting environment for
Magento 1.9x and Magento 2.x. It uses the same foundation as hosting companies which charge $100s
per month but is completely free for the first year.

The guide requires no interpretation, you only need to follow the instructions exactly as laid out and you
will have one of the highest performing sites which increases ranking and indexing with Google.

Signup
The first step is to sign up with Amazon Web Services at http://aws.amazon.com, they require your
credit card but as long as you follow these instructions you will not be charged for the first year.

Download
While waiting for the Amazon AWS account to be activated you will need to download and install
MobaXterm from http://mobaxterm.mobatek.net/ choosing the home edition which is free.

Copyright 2016 eBookMark, all rights reserved Page 2


Setup

AWS
Once your account is activated log in and you will see the dashboard. On the top right you will see the
dropdown for the region where your instances will be located, the most common is US East 1, North
Virginia USA so choose this. It is complex to change the region once you have created the instances so
please choose carefully.

Copyright 2016 eBookMark, all rights reserved Page 3


Security Groups
On the left li k Se u it G oups the li k Add Ne eati g fou g oups i total.

webdft
GroupName: webdft
Description: Web Default
Inbound: RDP / TCP / PortRange 3389 / Source 0.0.0.0/0

webpub
GroupName: webpub
Description: Web Public
Inbound: HTTP / TCP / PortRange 80 / Source 0.0.0.0/0

webrds
GroupName: webrds
Description: Web Database
Inbound: none

webint
GroupName: webint
Description: Web Internal
Inbound: MySQL / TCP / PortRange 3306 / Source 172.0.0.0/8
Inbound: Custom / TCP / PortRange 6379 / Source 172.0.0.0/8

Instance
Cli k o AMIs o the left, the hoose Pu li i ages f o the d opdo , enter ami-5492ba3c and hit
e te , this should sho the e i sta e RightI age_Ce tOS_ . _ 4_ 4. . _HVM_EBS .

1. Right click and choose Launch.


2. Choose t2.micro (important for free 1yr usage the Ne t: Co figu e I sta e Details
3. Choose a subnet for example 1b (this must be the same for web, database, etc)
4. Cli k E a le te i atio p ote tio the Ne t: Add Sto age
5. E te GB fo size a d hoose Ge e al Pu pose SSD the Ne t: Tag I sta e
6. Cli k Ne t: Co figu e Se u it G oup
7. Choose Sele t a e isti g se u it g oup a d sele t e i t e pu e dft the Re ie a d
Lau h
8. Click on Launch which will show a popup for key pair
9. Sele t eate a e ke pai a d e te a a e e ssh you must download and save this
securely, it is the only way to log in to the instance)

Copyright 2016 eBookMark, all rights reserved Page 4


Elastic IP
Once the instance is started cli k o Elasti IPs o the left a d hoose Allo ate Ne Add ess .

1. Sele t Yes, Allo ate


2. Right li k o the add ess a d hoose Asso iate Add ess
3. Click inside the instance box and choose the instance that was created
4. Select Associate and the fixed IP will be associated with the instance

Domain
Now go to your domain hosting provider and create an A record to your website following the
instructions with the IP address of the Elastic IP.

Database
U de Se i es alo g the top li k RDS in the Database section. On the left click on Instances and
hoose Lau h DB I sta e .

1. Sele t M SQL f o the optio s a d li k Sele t


2. O the e t optio s ee sele t De /Test M SQL a d hoose Ne t Step
3. U de the DB I sta e Class d .t . i o very important for free 1yr hosting)
4. For Multi-AZ Deplo e t hoose No
5. For allocated storage enter 10GB
6. The DB I sta e Ide tifie can be webdb
7. The Maste Use a e a e e d ad i a d Maste Pass o d ou hoosi g, e te it also
i the Co fi Pass o d a d hoose Ne t Step
8. Choose Pu li l A essi le as No, A aila ilit Zo e the sa e as the e i sta e so , the
Se u it G oups e ds a d e i t
9. The rest can be left as default and choose Lau h DB I sta e.

Whe lau hed ake a ote of the data ase e dpoi t hi h ill e e d ds.a azo a s. o ,
ignore the :3306.

Copyright 2016 eBookMark, all rights reserved Page 5


Build
Sta t Mo aXte a d i the top left hoose Sessio .

For the configuration to connect to your new instance enter the following.

1. Cli k SSH i the e i do a d i Re ote host * e te the Elasti IP add ess


2. U de Ad a ed SSH setti gs e a le Use p i ate ke a d sele t the e ssh ke ou
downloaded when creating the instance
3. U de Book a k setti gs e te a f ie dl a d su h as e a d li k OK

Copyright 2016 eBookMark, all rights reserved Page 6


Now double click the web session on the left and you will be show a login screen, enter the username
oot ithout the dou le uotes a d hit e te .

You will then see the following screen being logged in to your web instance.

Copyright 2016 eBookMark, all rights reserved Page 7


Core
The symbol represents you pressing the <ENTER> key on your keyboard.

[root@ip-web ~]# yum -y update


[root@ip-web ~]# echo "0 0 * * * ntpdate 0.pool.ntp.org" > /etc/cron.d/ntp
[root@ip-web ~]# mkdir /var/www
[root@ip-web ~]# mkdir /var/www/home
[root@ip-web ~]# mkdir /var/www/html
[root@ip-web ~]# cd /tmp

PHP
[root@ip-web ~]# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-
0.el7.ngx.noarch.rpm
[root@ip-web ~]# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
[root@ip-web ~]# curl 'https://setup.ius.io/' -o setup-ius.sh
[root@ip-web ~]# sudo bash setup-ius.sh
[root@ip-web ~]# sudo yum -y install php70u-fpm-nginx php70u-cli php70u-mysqlnd
[root@ip-web ~]# yum -y install php70u-opcache php70u-soap php70u-mbstring php70u-dom php70u-
pdo php70u-mcrypt php70u-gd t1lib
[root@ip-web ~]# yum -y install php70u-intl
[root@ip-web ~]# yum -y install php70u-json
[root@ip-web ~]# yum -y install telnet

[root@ip-web ~]# chkconfig nginx on


[root@ip-web ~]# chkconfig php-fpm on

[root@ip-web ~]# vi /etc/php-fpm.d/www.conf


In VI hit the a button on the keyboard for insert mode, then right click and choose paste for the
following code, then hit the esc key, do :x and then hit enter to save and exit.

Change
;php_admin_value[memory_limit] = 128M
to before save and exit
php_admin_value[memory_limit] = 256M

Copyright 2016 eBookMark, all rights reserved Page 8


Nginx
[root@ip-web ~]# touch /etc/nginx/blockips.conf
[root@ip-web ~]# mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.orig
[root@ip-web ~]# vi /etc/nginx/nginx.conf
In VI hit the a button on the keyboard for insert mode, then right click and choose paste for the
following code, then hit the esc key, do :x and then hit enter to save and exit.
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log warn;


pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '


'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_proxied any;
#gzip_http_version 1.0;
gzip_types text/plain text/css application/javascript application/x-javascript text/xml
application/xml application/xml+rss text/javascript image/jpeg image/jpg image/gif image/png;

set_real_ip_from 127.0.0.1;
real_ip_header X-Real-IP;

include /etc/nginx/conf.d/*.conf;

# Block spammers and other unwanted visitors ##


include blockips.conf;
}

Copyright 2016 eBookMark, all rights reserved Page 9


[root@ip-web ~]# mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.orig
[root@ip-web ~]# vi /etc/nginx/conf.d/default.conf
In VI hit the a button on the keyboard for insert mode, then right click and choose paste for the
following code, then hit the esc key, do :x and then hit enter to save and exit.
# Upstream to abstract backend connection(s) for php
upstream php {
#server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /var/www/html;

# Load configuration files for the default server block.


include /etc/nginx/default.d/*.conf;

location / {
index index.html index.htm index.php;
}

location /pydio/data/ {
deny all;
}

error_page 404 /404.html;


location = /40x.html {
}

error_page 500 502 503 504 /50x.html;


location = /50x.html {
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

[root@ip-web ~]# vi /etc/nginx/conf.d/web.conf


In VI hit the a button on the keyboard for insert mode, then right click and choose paste for the
following code, then hit the esc key, do :x and then hit enter to save and exit.

Change server_name to your domain name before save and exit.


server {
listen 80;
#listen 443 ssl;
server_name domain.name;
root /var/www/home/magento;
#auth_basic "Restricted";
#auth_basic_user_file /var/www/home/.htpasswd;

location / {
index index.html index.php;
try_files $uri $uri/ /index.php?$args;
expires 30d;
}

location /help {

Copyright 2016 eBookMark, all rights reserved Page 10


index index.html index.php;
try_files $uri $uri/ /help/index.php?$args;
expires 30d;
}

# Set a nice expire for assets


location ~* "^.+\.(jpe?g|gif|css|png|js|ico|pdf|zip|tar|t?gz|mp3|wav|swf)$" {
expires 30d;
access_log off;
add_header Cache-Control public;
}

## These locations would be hidden by .htaccess normally


location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }

location /var/export/ { ## Allow admins only to view export folder


auth_basic "Restricted"; ## Message shown in login window
auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
autoindex on;
}

location /. { ## Disable .htaccess and other hidden files


return 404;
}

location @handler { ## Magento uses a common front handler


rewrite / /index.php;
}

location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}

location ~ .php$ {
if (!-e $request_filename) { rewrite / /index.php last; }

expires off;
fastcgi_pass 127.0.0.1:9000; #clientphp;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


fastcgi_param MAGE_RUN_CODE '';
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params;
}
}

[root@ip-web ~]# service nginx restart


[root@ip-web ~]# service php-fpm restart

Copyright 2016 eBookMark, all rights reserved Page 11


ConfigServer
[root@ip-web ~]# yum -y install perl-libwww-perl
[root@ip-web ~]# wget https://download.configserver.com/csf.tgz
[root@ip-web ~]# tar zxvf csf.tgz
[root@ip-web ~]# cd csf
[root@ip-web ~]# ./install.sh
[root@ip-web ~]# chkconfig csf on

[root@ip-web ~]# vi /etc/csf/csf.conf


In VI hit the a button on the keyboard for insert mode, then hit the esc key when finished, do :x and
then hit enter to save and exit.
TESTING = "0"

...

#TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995"
TCP_IN = "22,80,443"

# Allow outgoing TCP ports


#TCP_OUT = "20,21,22,25,53,80,110,113,443"
TCP_OUT = "21,22,25,80,443"

# Allow incoming UDP ports


#UDP_IN = "20,21,53"
UDP_IN = "53"

# Allow outgoing UDP ports


# To allow outgoing traceroute add 33434:33523 to this list
#UDP_OUT = "20,21,53,113,123"
UDP_OUT = "53,113,123"

[root@ip-web ~]# vi /etc/csf/csf.allow


In VI hit the a button on the keyboard for insert mode, then hit the esc key when finished, do :x and
then hit enter to save and exit.
# Note: IP addressess listed in this file will NOT be ignored by lfd, so they
# can still be blocked. If you do not want lfd to block an IP address you must
# add it to csf.ignore
94.15.29.70 # csf SSH installation/upgrade IP address - Wed Nov 16 17:22:53 2016
tcp:out:d=3306:s=172.0.0.0/8
tcp:out:d=6379:s=172.0.0.0/8

[root@ip-web ~]# vi /etc/csf/csf.ignore


In VI hit the a button on the keyboard for insert mode, then hit the esc key when finished, do :x and
then hit enter to save and exit.
127.0.0.1
exe:/usr/sbin/php-fpm
exe:/usr/sbin/nginx

[root@ip-web ~]# csf r


[root@ip-web ~]# cd /tmp

Copyright 2016 eBookMark, all rights reserved Page 12


PHPMyAdmin
[root@ip-web ~]# wget https://files.phpmyadmin.net/phpMyAdmin/4.6.4/phpMyAdmin-4.6.4-all-
languages.zip
[root@ip-web ~]# unzip -d /var/www/html phpMyAdmin-4.6.4-all-languages.zip
[root@ip-web ~]# mv /var/www/html/phpMyAdmin-4.6.4-all-languages /var/www/html/phpmyadmin
[root@ip-web ~]# mv /var/www/html/phpmyadmin/config.sample.inc.php
/var/www/html/phpmyadmin/config.inc.php
[root@ip-web ~]# vi /var/www/html/phpmyadmin/config.inc.php
In VI hit the a button on the keyboard for insert mode, then hit the esc key when finished, do :x and
the hit e te to sa e a d e it. Cha ge the host to the RDS e dpoi t eated ea lie efo e sa e.
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'webdb...rds.amazonaws.com';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;

Now go to your web ip n.n.n.n/phpmyadmin in a web browser and you will see the log in to your
database. Now login using you webdbadmin username and the password your chose earlier.

Create Database
O the left li k Ne .

Copyright 2016 eBookMark, all rights reserved Page 13


E te age to fo the a e a d hoose utf _ge e al_ i fo the ollatio , hoose C eate .

Cli k o the uppe left phpM Ad i logo a d hoose Use a ou ts the Add use a ou t . E te
magento as the Use a e a d li k Ge e ate fo a e pass o d, sa e the pass o d fo late . Then
li k Go at the otto ight of the page.

Copyright 2016 eBookMark, all rights reserved Page 14


I the top hoose Data ase .

Then select magento i Add p i ileges o the follo i g data ase s : a d li k Go .

Copyright 2016 eBookMark, all rights reserved Page 15


The sele t the Che k all he k o a d u he k GRANT , li k Go he fi ished.

Copyright 2016 eBookMark, all rights reserved Page 16


Magento
The simplest way to download Magento is to go to https://magento.com/tech-resources/download and
download the version you require locally. Then once downloaded you can drag the zip file to the Sftp
window in MobaXterm and it will upload to the server.

[root@ip-web ~]# unzip -d /var/www/home/magento Magento-CE-2.1.2-2016-10-11-11-16-47.zip


[root@ip-web ~]# chown -R php-fpm:nginx /var/www/home/magento
[root@ip-web ~]# chown -R php-fpm:root /var/lib/php/fpm/session

You can now install magento with the database endpoint, and username plus password created in
PHPMyAdmin earlier.

Copyright 2016 eBookMark, all rights reserved Page 17


SSL
If you require SSL the simplest is to use a Load Balancer in AWS. Comodo have a 3mth trial and is a high
quality SSL certificate, we recommend this to start with.

I EC hoose Load Bala es u de Load Bala i g a d C eate Load Bala e . Sele t Classi Load
Bala e a d hoose Co ti ue .

Fo the Load Bala e a e e te e l a d li k the Add utto . Choose HTTPS Se u e HTTP as


the Load Balancer P oto ol a d lea e the I sta e P oto ol as HTTP . Cli k Ne t: Assig Se u it
G oups .

F o Sele t a e isti g se u it g oup hoose e i t a d e pu sele ti g Ne t: Co figu e Se u it


Setti gs . He e ou ill eed to e te the e tifi ate details as spe ified ou e tifi ate p o ide .
O e e te ed li k Ne t: Co figu e Health Che k .

O this s ee lea e the setti gs as default ut ha ge Pi g Path to /l test.php a d li k Ne t: Add


EC I sta es . Sele t ou e i sta e, the e should o l e o e, a d desele t E a le C oss-Zone
Bala i g . Cli k Ne t: Add Tags , lea e the tags la k a d li k Re ie a d C eate . The li k C eate .

Once the Load Bala e has ee added hoose Close a d ou ill see the DNS a e as si ila to
e l -...el .a azo a s. o . I ou do ai DNS setti gs fo ou do ai p o ide ou eed to
e o e the DNS e t A e o d a d eate a a e e o d ith this e l do ai , you cannot use an
IP as they change so you need to use a subdomain such as www.domain.com for your website. CName
records cannot be in the root.

In MobaXterm create the following file.


[root@ip-web ~]# vi /var/www/html/lbtest.php
In VI hit the a button on the keyboard for insert mode, then right click and choose paste for the
following code, then hit the esc key, do :x and then hit enter to save and exit.
<?php
date_default_timezone_set('UTC');
echo date("Y-m-d H:i:s");
?>

If you see a blank screen on your website it normally means that your load balancer is not working
correctly. You may have to wait for the server to re-initialize and the load balancer to pick it up.

Common Commands
service nginx restart #restart web server
service php-fpm restart #restart php
sudo reboot #restart the instance
tail /var/log/nginx/error.log #view the last errors
chown -R php-fpm:root /var/lib/php/fpm/session #occasional permission error
chown -R php-fpm:nginx /var/www/home/magento #web application permission error

Copyright 2016 eBookMark, all rights reserved Page 18


Conclusion
You will now have a fully running multi-instance high performance Magento hosting environment for
free for one full year. It is advisable to use a ping service to check your website every few minutes that it
is active.

Database backups are automatic in AWS using this guide, the web instance is not backed up and
recommend you either create an AMI by right-clicking on the left of Amazon AWS in the EC2 screen or
you backup the /var/www/home in to a zip file and download it to your local system when you make
changes.

Fo o figu atio of Mage to i ludi g i stalli g Redis ith ha e a fu the eBook Best P a ti e
Co figu atio of Mage to i ludi g Redis fo Google SEO . This eBook takes ou th ough the steps to
configure on new Magento installation for even higher performance and to index and rank you site
efficiently.

Copyright 2016 eBookMark, all rights reserved Page 19

Vous aimerez peut-être aussi