Speed-up your Magento Store with varnish cache.

Most of the users face speed and performance issue due to the heavy traffic on their Magento store and want to explore some methods to improve the same.

Varnish cache is a kind of HTTP accelerator designed for sites having heavy dynamic content and large traffic as well. Varnish speed up the performance by using the concept of virtual memory and stores the dynamic content in that virtual memory, It only focussed on HTTP protocol and supports the load balancing with the help of two algorithms which are round robin and random director.

Varnish provides the flexibility to configure multiple backend servers and cache limits etc. with the help of vcl (Varnish Configuration Language) files.


Now lets explore the installation and configuration process on your magento store.


1 – Install the varnish on your Linux Distro accordingly.

For Debian Based Distros (UBUNTU, KUBUNTU, DEBIAN)

sudo apt-get install varnish

For RPM Based Distros (Centos, RHEL)

yum install varnish


2 – Change the listening port of your apache server from 80 to 8080 or whatever port you want.


3 – Now open the configuration file of vagrant which is located at

/etc/sysconfig/varnish (RPM distros)

/etc/default/varnish (DEBIAN distros)

For Debian Based Distros find the content written as

DAEMON_OPTS="-a :6081 \

-T localhost:6082 \

-f /etc/varnish/default.vcl \

-S /etc/varnish/secret \

-s malloc,256m"

Edit the line “-a :6081 \” to “-a :80 \” which means that your varnish cache now listen on port 80 or you can select whatever port you want.

In that content a line written as “-f /etc/varnish/default.vcl” indicates the file which is included to define the rules and backend servers which are providing the dynamic content to varnish cache.

For RPM Based Distros find the content written as


Change the port from 6081 to 80 or whatever port you want.

Again find the content written as


This line indicates the file which has configuration and backend servers details.


4 – Now open the file located at /etc/varnish/default.vcl and find the content written as

backend default {

.host = "";

.port = "80";


Now change the port from 80 to the port on which apache is running (8080 in this example)

backend default {

.host = "";

.port = "8080";


save the content of the file.


5 – Now restart the varnish and apache server by following command.

Apache Restart

/etc/init.d/apache2 restart(DEBIAN distros)


/etc/init.d/httpd restart (RPM distros)

Varnish Restart

/etc/init.d/varnish restart (DEBIAN and RPM distros)


Real Facts and Figures

We have tested the varnish capability on our Magento Store with the help of AB (Apache Benchmark) tool and we got the surprising results which are enough to prove that varnish improve the performance of website 5 times.

We generated around 40000 requests with 1000 requests concurrently and run apache on our 8080 port and varnish on 800 port and the outcome which we got really surprised us.


  AB testing on Varnish cache


S11creenshot from 2015-07-27 12:47:00

AB testing on Apache Server


From the above comparison we can see that varnish increases the Requests per second as compared to apache and reduces the time taken to full-fill the request. So, we can say that if the traffic on your magento store increases day by day and your page load time increases too then you definitely need varnish cache to improve the performance of your store.

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Need Any Help?

Got Stuck with something serious or you wish to hire us for a while. We are here to hear from you, feel free to reach us and we'll get back to you as soon as possible.

Contact Us
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home