How to Install Varnish On cPanel?

How to Install Varnish On cPanel?

Varnish is a Web application accelerator also known as a caching HTTP reverse proxy, which is listening to port 80. It is a very useful tool for speeding up the server especially during the high traffic. Since Varnish is very simple to set up and start using from a beginner level, it is highly recommended to everyone try installing it to gain benefits from the speed boosts!

Varnish is listening to port 80 so we need to change the Apache listening port to 8080. You can do the same from WHM by following the below steps.

1) Login to WHM.

2) Navigate to “Tweak Settings” under “Server Configuration”.

Install Varnish


3) Then click on the “System” tab.


4) Change the Apache non ssl port to 8080.


5) Then you need to login to the server with root user via SSH.

# ssh root@serverIP


6) Install varnish repository on your server using the below command.

# rpm -Uvh


7) install varnish using the below command.

# yum install varnish


8) After the installation, you need to configure the varnish to listen to the port 80. So you need to edit the configuration file as below.

open the varnish configuration file and add the below line.

# vi /etc/sysconfig/varnish



Finally, follow the below steps to change the Apache listening port to 8080.

# cd /etc/varnish/


Then rename the default config file and create a new one and add the below code to it.

# mv default.vcl default_bak.vcl

# vi  default.vcl

backend default {

.host = “<your server’s IP address>”;

.port = “8080”;


sub vcl_recv {

if (req.url ~ “\.(png|gif|jpg|swf|css|js)$”) {




# strip the cookie before the image is inserted into cache.

sub vcl_fetch {

if (req.url ~ “\.(png|gif|jpg|swf|css|js)$”) {

unset beresp.http.set-cookie;




9) You need to enable and start the service by using the below commands.

# chkconfig varnish on

# service varnish start


10) You can monitor your varnish cache performance using the below command.

# varnishstat


If you need any further help please do reach our support department.