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; }...
MySql 5.6 Installation

MySql 5.6 Installation

MySql 5.6 Installation Install Latest MySql in dedicated servers or in cloud servers like Amazon ec2, Digital Ocean, Linode for UBUNTU operating system. Magento 2 need 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...
Add Multiple Field Filter (addFieldToFilter) and Multiple Attribute Filter (addAttributeToSelect) in Magento.

Add Multiple Field Filter (addFieldToFilter) and Multiple Attribute Filter (addAttributeToSelect) in Magento.

There are the following difference between addAttributeToSelect() : As you know that the magento prducts are having many attributes, so the addAttributeToSelect() method is used to select the attributes that we want to use. Its retrive only attributes its not filter the collection, however when we use addAttributeToSelect(‘*’) its select all attriutes of the products. addAttributeToFilter() : This method is used to filter the attributes, its used to filter the collection based on the specific conditional parametters. addFieldToFilter() : This method is used to filter collection but non-EAV models. Example : In below mentioned code we have used product collection and selected name and price attribute with addAttributeToSelect() method and filter the collection with greater than equal to 5 with addAttributeToFilter() method. $collections = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect(array('name', 'price')) ->addAttributeToFilter('price',array('eq' => 5.00)) ->load(); Below is the list of conditions that you use to filter the collection: Attribute Code SQL Equivalent Example eq = $collections->addAttributeToFilter('price', array('eq' => 5.00)); neq != $collections->addAttributeToFilter('price', array('neq' => 5.00)); like LIKE $collections->addAttributeToFilter('name', array('like' => '%Pattern%')); nlike NOT LIKE $collections->addAttributeToFilter('name', array('nlike' => '%Pattern%')); in IN () $collections->addAttributeToFilter('id', array('in' => array(1,2,3,4,5))); nin NOT IN () $collections->addAttributeToFilter('id', array('nin' => array(1,2,3,4,5))); is IS notnull IS NOT NULL $collections->addAttributeToFilter('description', 'notnull'); null IS NULL $collections->addAttributeToFilter('description', 'null'); moreq >= $collections->addAttributeToFilter('price', array('moreq' => 5.00)); gt > $collections->addAttributeToFilter('price', array('gt' => 5.00)); lt = $collections->addAttributeToFilter('price', array('gteq' => 5.00)); lteq = $collection->addAttributeToFilter('created_at', array( 'from' => '10 December 2014', 'to' => '15 December 2014', 'date' => true ));...
Set Get and Delete cookie in Magento Server Side.

Set Get and Delete cookie in Magento Server Side.

Set Get and Delete cookie in Magento. Setting cookie Server Side : Mage_Core_Model_Cookie class contains function to Set, Get and delete cookies in magento. $name : Name of the cookie. $value : value of the cookie. $period : expiry time of the cookie. $path : path of the server on which cookie is available if set ‘/’ the cookie is availble entire domain ‘/directoryname/’ this means cookie available directory and all sub directory. $domain : The doamin the cookie is available ‘www.example.com’; $secure : Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client. it is boolean that is TRUE or FALSE. $httponly : When TRUE the cookie will be made accessible only through the HTTP protocol. $name and $value are mandatory while setting cookies and other parameters are not mandatory. Setting cookie : <?php Mage::getModel('core/cookie')->set($name, $value, $period, $path, $domain, $secure, $httponly); ?> Getting cookie : Only pass cookie name in $name variable to get cookie. <?php Mage::getModel('core/cookie')->get($name); ?> Get all cookie value as array : <?php Mage::getModel('core/cookie')->get(); ?> Deleting cookie : Only $name is mandatory and other variable are optional. <?php Mage::getModel('core/cookie')->delete($name, $path, $domain, $secure, $httponly); ?> Example : <? $name = 'name'; $value = 'Aman'; $period = time()+60*60*24*30; //expiration time is set to a month (60 sec * 60 min * 24 hours * 30 days); $path = '/'; $domain = 'www.example.com'; $secure = false; $httponly = false; Mage::getModel('core/cookie')->set($name, $value, $period, $path, $domain, $secure, $httponly); ?> OR <?php $name = 'name'; $value = 'Aman'; Mage::getModel('core/cookie')->set($name, $value); echo Mage::getModel('core/cookie')->get('name'); //it print value of set cookie. ?> Deleting Cookie: <?php Mage::getModel('core/cookie')->delete('name');...