Install varnish cache on cPanel server

[Total: 4    Average: 5/5]

Varnish is a caching technology. Varnish is a web accelerator and also referred as HTTP accelerator or reverse HTTP proxy, which will significantly enhance the performance of your website.
Once Varnish is installed in your server, it will listen in the port 80. Make Apache to listen in any other port other than 80. When a client requests for a page in your website, Varnish will try to serve the page from its cache memory. This is cache hit. If the page is not in its cache memory, then Varnish will request to HTTP (Apache) to serve the page and caches it for future reference.
Below are the simple steps to Install varnish cache on cPanel server:

1. Make Apache listen in any other port other than 80. Here I am making Apache to listen in port 8080. It can be done in two ways. Either editing the httpd.conf file or editing the Tweak settings in WHM

a] Editing httpd.conf file
#

vi /usr/local/apache/conf/httpd.conf

Locate the following line in /usr/local/apache/conf/httpd.conf file and change the port from 80 to 8080

Listen 0.0.0.0:80

Once edited, the Apache config file for “Listen” should be as follows:

# cat /usr/local/apache/conf/httpd.conf | grep listen 
Listen 0.0.0.0:8080

OR

b] Editing WHM – Tweak settings
WHM >> Tweak Settings >> Apache non-SSL IP/port
Set the port to 8080 and save the settings.
Install varnish repository
You can install varnish through YUM or manually download varnish RPM.

yum install varnish

OR

wget https://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release/varnish-release-3.0-1.el6.noarch.rpm
rpm ivh varnish-release-3.0-1.el6.noarch.rpm

2. Edit the configuration file for varnish /etc/sysconfig/varnish and change the value of VARNISH_LISTEN_PORT to 80

# grep VARNISH_LISTEN_PORT /etc/sysconfig/varnish
VARNISH_LISTEN_PORT=80

3. Edit Varnish config: /etc/varnish/default.vcl . Correct the IP address in this file to your IP address and port to 80

backend default {
  .host = "YOUR IP ADDRESS";
  .port = "80";
}

4. Start Varnish service on your server

 chkconfig varnish on
# service varnish start
# service varnish start
Starting Varnish Cache:                                    [  OK  ] 

That’s it!!

You can check this by using the netstat command.

netstat -plan | grep :80