Install nginx php-fpm magento 2

Install nginx php-fpm magento 2

Install nginx php-fpm magento 2 Setup dedicated server or Amazon ec2 instance for magento 2. Install nginx, php-fpm and MySql server and setup virtual host configuration. Installation of server. $sudo apt-get update $sudo apt-get install nginx -y Installing php, php-fpm supported extension for magento 2 sudo apt-get -y update sudo add-apt-repository ppa:ondrej/php5-5.6 sudo apt-get -y update sudo apt-get -y install php5 php5-mhash php5-mcrypt php5-curl php5-cli php5-mysql php5-gd php5-intl php5-xsl Installing MySql 5.6 apt-add-repository ppa:ondrej/mysql-5.6 apt-get -y update apt-get -y install mysql-server If you get error : Sub-process /usr/bin/dpkg returned an error code (1) Increase the memory limit of swap Create a 4G swap file: sudo fallocate -l 4G /swapfile Change its permission to only root could access and change: sudo chmod 600 /swapfile Make it swap: sudo mkswap /swapfile Activate: sudo swapon...
Create user on AWS ec2 instance Linux

Create user on AWS ec2 instance Linux

Create user on AWS ec2 instance Linux Create a user for providing access to other developer or use for virtual host in linux. It will also use for providing limited access for user like only read access, read or write access etc. $sudo adduser aman It will ask for new password for the user aman. Note: this password is used to login password for the user when you are using terminal. Granting permission for user aman $sudo visudo Add below mentioned line in the file #User privilege for aman aman ALL=(ALL:ALL) ALL And press CTRL+X for exit, it will ask for save modified changes, Y for the saving modified file. Creating user authorisation to the sever with public key. $su aman $cd home/aman $ssh-keygen -b 1024 -f aman -t dsa $mkdir .ssh $chmod 700 .ssh $cat aman.pub > .ssh/authorized_keys $chmod 600 .ssh/authorized_keys $sudo chown aman:ubuntu .ssh $sudo chown aman:ubuntu .ssh/authorized_keys Note: In above step aman is user and ubuntu is the defult user group. Now you need to download the key “aman” and use it for connecting ssh or...
Enable gzip and leverage cache on nginx server.

Enable gzip and leverage cache on nginx server.

Enable gzip and leverage cache on nginx server Enable gzip and leverage cache on nginx server. It will help to improve magento store speed and optimize content delivery by compressing content into gzip. Login on server with root access and create the below mentioned file. For gzip compression. vi /etc/nginx/conf.d/gzip.conf add the below mentioned code in file. gzip on; gzip_disable "MSIE [1-6]\.(?!.*SV1)"; gzip_proxied any; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp image/svg+xml; gzip_vary on; For leverage cache. Add the below mentioned code in server section in location ~* \.(js|css|png|jpg|jpeg|gif|ico)(\?ver=[0-9.]+)?$ { expires 1y; } Example server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; index index.html index.htm; } location ~* \.(js|css|png|jpg|jpeg|gif|ico)(\?ver=[0-9.]+)?$ { expires 1y; } location ~* \.(pdf)$ { expires 30d; }...
Install redis magento Ubuntu

Install redis magento Ubuntu

Install redis magento Ubuntu Install and configure redis for magento backend and fullpage caching which will improve your magento store performance and load faster. Download latest redis package. sudo wget http://download.redis.io/releases/redis-3.0.2.tar.gz sudo tar xzf redis-3.0.2.tar.gz cd redis-3.0.2 sudo make sudo make test sudo make install cd utils sudo install_server.sh Start and stop redis service sudo service redis_6379 start sudo service redis_6379 stop Setting redis in magento: By Defualt latest magento version is come with redis library and session module. You just need to download the cache backend module from the below mentioned github link https://github.com/colinmollenhour/Cm_Cache_Backend_Redis After downloading extract the files and copy the cache folder into magento/app/code/community/Cm/ After that add below mentioned code in magento magento/etc/local.xml file in global section. <!--Start caching--> <cache> <backend>Cm_Cache_Backend_Redis</backend> <backend_options> <server>127.0.0.1</server> <port>6379</port> <persistent></persistent> <database>0</database> <password></password> <force_standalone>0</force_standalone> <connect_retries>1</connect_retries> <read_timeout>10</read_timeout> <automatic_cleaning_factor>0</automatic_cleaning_factor> <compress_data>1</compress_data> <compress_tags>1</compress_tags> <compress_threshold>20480</compress_threshold> <compression_lib>gzip</compression_lib> <use_lua>0</use_lua> </backend_options> </cache> <full_page_cache> <backend>Cm_Cache_Backend_Redis</backend> <backend_options> <server>127.0.0.1</server> <port>6379</port> <persistent></persistent> <database>1</database> <password></password> <force_standalone>0</force_standalone> <connect_retries>1</connect_retries> <lifetimelimit>57600</lifetimelimit> <compress_data>0</compress_data> </backend_options> </full_page_cache> <!--End caching--> Flush magento cache. After that login with ssh in your server and type below mentioned command. redis-cli 127.0.0.1:6379>keys * You will see magento madules are caching there. Enjoy...
Nginx configration for magento 2

Nginx configration for magento 2

Nginx configration for magento 2 Here i have explained how we can do Nginx configration for magento 2 and properly map virtual host to magento root directory and how enable virtual host. ubuntu$ sudo vi /etc/nginx/sites-available/default server { listen 80; server_name _; rewrite / $scheme://$host$request_uri permanent; } server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /var/www/html; location /setup { try_files $uri $uri/ @setuphandler; } # Rewrite Setup's Internal Requests location @setuphandler { rewrite /setup /setup/index.php; } location / { index index.php index.html; try_files $uri $uri/ @handler; } # Rewrite Internal Requests location @handler { rewrite / /index.php; } location /pub/static { try_files $uri $uri/ @static; } location @static { rewrite ^/pub/static/(.*)$ /pub/static.php?resource=$1? last; } location /static/ { location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ { add_header Cache-Control "public"; expires +1y; if (!-f $request_filename) { rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last; } } location ~* \.(zip|gz|gzip|bz2|csv|xml)$ { add_header Cache-Control "no-store"; expires off; if (!-f $request_filename) { rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last; } } if (!-f $request_filename) { rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last; } } location /media/ { try_files $uri $uri/ /get.php?$args; location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ { add_header Cache-Control "public"; expires +1y; try_files $uri $uri/ /get.php?$args; } location ~* \.(zip|gz|gzip|bz2|csv|xml)$ { add_header Cache-Control "no-store"; expires off; try_files $uri $uri/ /get.php?$args; } } location /media/customer/ {deny all;} location /media/downloadable/ {deny all;} location ~ /media/theme_customization/.*\.xml$ { deny all; } location /errors/ {try_files $uri =404;} location ~ ^/errors/.*\.(xml|phtml)$ {deny all;} location ~ cron\.php {deny all;} location ~ \.php$ { if (!-e $request_filename) { rewrite / /index.php last; } try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }...
Create Magento 2 Module

Create Magento 2 Module

Create Magento 2 Module Create a simple magento 2 module. From this article you will learn how to create a simple magento 2 module. Amanweb\Common\etc\module.xml Amanweb\Common\etc\frontend\routes.xml Amanweb\Common\Controller\Index\Index.php Amanweb\Common\Block\Common.php Amanweb\Common\view\frontend\layout\common_index_index.xml Amanweb\Common\view\frontend\templates\common.phtml Step 1: Create module file in the etc folders this file contains module version information. Amanweb\Common\etc\module.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Amanweb_Common" schema_version="1.0.0" setup_version="1.0.0"></module> </config> Step 2 : Define front-end router that will create a front-end path for module. Amanweb\Common\etc\frontend\routes.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../lib/internal/Magento/Framework/App/etc/routes.xsd"> <router id="standard"> <route id="common" frontName="common"> <module name="Amanweb_Common" /> </route> </router> </config> Step 3 : Create block : Amanweb\Common\Block\Common.php <?php namespace Amanweb\Common\Block; class Common extends \Magento\Framework\View\Element\Template { public function _prepareLayout() { return parent::_prepareLayout(); } } Step 4 : Create controller Amanweb\Common\Controller\Index\Index.php <?php namespace Amanweb\Common\Controller\Index; class Index extends \Magento\Framework\App\Action\Action { public function execute() { $this->_view->loadLayout(); $this->_view->getLayout()->initMessages(); $this->_view->renderLayout(); } } Step 5 : Create layout and view : Layout Amanweb\Common\view\frontend\layout\common_index_index.xml <?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> <head> <title>Welcome to Magento 2 World</title> </head> <body> <referenceContainer name="content"> <block class="Amanweb\Common\Block\Common" name="common" template="common.phtml"> </block> </referenceContainer> </body> </page> View Amanweb\Common\view\frontend\templates\common.phtml <strike> Magento 1</strike> Magento 2 <h1> Welcome to Magento 2 </h2> <?php echo 'This is the Simple Welcome Module in Magento 2.0';?> Note : Upload Amanweb module folder inside app/code/. Add the module name inside the config file array. 'Amanweb_Common' => 1,...