ideas, experiments, work in progress, freebies & our thoughts on cutting edge tech

Installing Varnish for Faster Magento website

Varnish is an HTTP accelerator designed for content-heavy dynamic web sites. As we know Magento is too heavy when it comes to content, In addition we have multiple free modules/extension installed for having aditional functionality. Adding Varnish in front of Apache is used to speed up Magento websites.

We will use PageCache powered by Varnish Magento Extension found at in this setup.

Step One – Install Varnish.

We will use apt utility to install on apache with following comand. You will need a sudo user login to install and configure Varnish. You may need to add Varnish repos to apt sources list with following commands

sudo curl | sudo apt-key add –

Now edit apt sources.list to have

sudo nano /etc/apt/sources.list

deb lucid varnish-3.0

sudo apt-get update
sudo apt-get install varnish

Step Two – Confugure Varnish

Vernish sits in front of Apache so it can deteremine if page needs to be fetched from apache or cached page can be delivered. So we need to configure Varnish to listen on port 80 and apache on other port like 8080.

So open varnish config file and make chnages as mentioned.

sudo nano /etc/default/varnish

Uncomment all of the lines under “DAEMON_OPTS”—under Alternative 2, and make the configuration match the following code:

DAEMON_OPTS=”-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m”

Save and exit out of that file and move default_3.0.vcl file from Magento Varnich extension folder app\code\community\Phoenix\VarnishCache\etc\default_3.0.vcl to /etc/varnish/default.vcl and Open it for editing ports as below-

Configuration shall look like below in vcl file

backend default {
.host = “”;
.port = “8080”;

backend admin {
.host = “”;
.port = “8080”;
.first_byte_timeout = 18000s;
.between_bytes_timeout = 18000s;

Step Three—Configure Apache Server

As Varnish listens on port 80 we make apache to listen on 8080 so varnish can request  content from apache is it needed refresh and cached copy cannot be used.

Open apache ports config file with following command

sudo nano /etc/apache2/ports.conf

Change the port number for both the NameVirtualHost and the Listen line to port 8080, and the virtual host should only be accessible from the localhost. The configuration should look like this:


We also need to update default virtual host file, so open it with following command

sudo nano /etc/apache2/sites-available/default

The Virtual Host shall be set to port 8080 like below-


Now we need to restart apache and Varnish so changes take effect.

sudo service apache2 restart
sudo service varnish restart




Your email address will not be published.