cPanel INSTALLATIONS

Install varnish on cPanel

install varnish cache
install varnish cache

Install varnish on cPanel

This post helps you to install Varnish on cPanel server. Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configures it to cache the contents. Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 – 1000x, depending on your architecture.

How to install varnish cache on cPanel

Step 1

First, you need to update the Apache non-SSL IP/port to any port other than 80. Here I am using a custom port 8080. To change the Apache non-SSL IP/port to 8080, please go to WHM -> Tweak Settings -> Apache non-SSL IP/port.

OR

If you are working on a no-control panel server, edit the Apache configuration file (/etc/httpd/conf/httpd.conf) and search for below line.

Listen 80

then change it to the following and restart Apache.

Listen 8080
Step 2

Once the Apache default port has been changed, we can go ahead and install several dependency packages using EPEL repository.

yum install epel-release
yum install pygpgme yum-utils
Step 3

Add official Varnish Cache repository by creating a file named varnishcache_varnish41.repo.

vim /etc/yum.repos.d/varnishcache_varnish41.repo

Then add the following into it.

[varnishcache_varnish41]
name=varnishcache_varnish41
baseurl=https://packagecloud.io/varnishcache/varnish41/el/7/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/varnishcache/varnish41/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[varnishcache_varnish41-source]
name=varnishcache_varnish41-source
baseurl=https://packagecloud.io/varnishcache/varnish41/el/7/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/varnishcache/varnish41/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
[varnishcache_varnish41]
name=varnishcache_varnish41
baseurl=https://packagecloud.io/varnishcache/varnish41/el/6/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/varnishcache/varnish41/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[varnishcache_varnish41-source]
name=varnishcache_varnish41-source
baseurl=https://packagecloud.io/varnishcache/varnish41/el/6/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/varnishcache/varnish41/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

Update your local yum cache by running

yum -q makecache -y --disablerepo='*' --enablerepo='varnishcache_varnish41'
Step 4

Now install Varnish from your repository.

yum install varnish
Step 5

Then you need to edit the varnish configuration file to change the listen port to 80.

vim /etc/varnish/varnish.params

Edit the following field.

VARNISH_LISTEN_PORT=80

Next is to edit the varnish basic VCL configuration file.

vim /etc/varnish/default.vcl

Change the .host field with your server IP address and .port field with the port 8080 (Apache non-SSL port).

backend default {
.host = "Your_IP_Address";
.port = "8080";
}
Step 6

Now start Varnish service on your server:

systemctl enable varnish
systemctl restart httpd
systemctl start varnish
chkconfig varnish on
/etc/init.d/httpd restart
/etc/init.d/varnish start

Also, you can check if the port 80 is listing varnish by netstat command.

netstat -plan | grep :80

One of the key features of Varnish Cache, in addition to its performance, is the flexibility of its configuration language, VCL. VCL enables you to write policies on how incoming requests should be handled.

That’s it!!

If you like this post and wish to receive more articles from us, please like our FB page: Grepitout

Your suggestions and feedbacks will encourage us and help to improve further, please feel free to write your comments.

For more details on our services, please drop us an E-mail at info@grepitout.com