Enable Varnish on cPanel. Varnish is a caching technology. It is a web accelerator and also referred as HTTP accelerator or reverse HTTP proxy, which will significantly enhance the performance of your website.
Varnish cache is really fast thereby, speed up the delivery depending on your architecture.
It will enhance your website’s performance. Varnish stores a copy of the page which is served by the web server the first time a user visits the website. Next time, when the user requests for the same page, varnish will serve the copy instead of serving it from the web server.
Thus, your webserver needs to handle only less traffic and there by increase the website performance and also reduce the server load.
Working of Varnish Cache
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.
Features of Varnish
1. Reduces the server load
2. High speed (cache + stored in RAM)
3. Useful to gain more visitors
Enable Varnish on cPanel. Installation
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:
# grep -iw listen /usr/local/apache/conf/httpd.conf
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.
2. Install Varnish repository
Download and install the varnish repository depending on your architecture. For CentOS 5 and Redhat5 use el5 whereas for CentOS 6 and Redhat6 use el6.
For me, it was el5.
# wget http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm # rpm -Uvh varnish-release-3.0-1.noarch.rpm
3. Install Varnish
# yum install varnish
4. 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
5. 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";
}
6. 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
Example:
# netstat -plan | grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15129/varnishd
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 12897/httpd
Now, you can start monitor your Varnish with varnishstat
If you need to change your the configuration file and you can test the configuration before restarting the Varnish service by
# varnishd -C -f /etc/varnish/default.vcl
Easy way to install Memcached and memcache in a cPanel server
Install Memcached and memcache, that’s what we are discussing in this article. In website hosting industry, speed is one of the most important factor that we prefer. The website speed depends upon many factors. Of-course, the speed of the website depends upon the plugins or other third party application installed with it.
Note: While doing “yum install varnish” if you are getting libedit error, then follow the steps below:
varnish-3.0.5-1.el5.centos.x86_64 from varnish-3.0 has depsolving problems
--> Missing Dependency: libedit.so.0()(64bit) is needed by package varnish-3.0.5-1.el5.centos.x86_64 (varnish-3.0)
Error: Missing Dependency: libedit.so.0()(64bit) is needed by package varnish-3.0.5-1.el5.centos.x86_64 (varnish-3.0)
You could try using --skip-broken to work around the problem
You could try running: package-cleanup --problems
package-cleanup --dupes
rpm -Va --nofiles --nodigest
The program package-cleanup is found in the yum-utils package.
In this case, you need to install the libedit rpm which is suitable for your architecture. You can find the rpm from http://rpmfind.net/linux/rpm2html
# wget ftp://rpmfind.net/linux/dag/redhat/el5/en/x86_64/dag/RPMS/libedit-20090923-3.0_1.el5.rf.x86_64.rpm
# rpm -ivh libedit-20090923-3.0_1.el5.rf.x86_64.rpm
Example:
# rpm -ivh libedit-20090923-3.0_1.el5.rf.x86_64.rpm
warning: libedit-20090923-3.0_1.el5.rf.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing... ########################################### [100%]
1:libedit ########################################### [100%]
Done!!!
Related:
The XCache
Memcached and memcache in a cPanel server
How to install Softaculous on cPanel server
Awesome tutorial solved my issue. I want to know can I change listening port to any other number as some tutorial on web say change it to 82 but you said 8080 ?
Thanks a lot.
Hello Salman,
Thank you for the feedback. I am glad to know my post has helped you to solve your problem. Yes, you can make Apache listening to any other port. For my convenience, I have used here the Apache port as 8080.
Thanks..! It’s awesome.
Thanks for your feedback mate..!
Hi,
Your tutorial is very useful! I have one question: my website has a SSL certificate and it is accessed via https on port 443. Do I need to follow these steps as you described or is something different I need to do?
And on this server I am running a WordPress Multisite Network. So my website will be the only one accessible through port 443, the others are accessed using standard 80 port.
Thanks,
Radu
You should use nginx as SSL termination, and forward request to Apache
https://www.digitalocean.com/community/tutorials/how-to-configure-varnish-cache-4-0-with-ssl-termination-on-ubuntu-14-04
Is this work’s with Cloudlinux installed on cPanel ?
yes it works
Thanks Machaney!!! 🙂 🙂
hey Heba..
Hope you remember me..this post is really awesome and helpful..
thank you works fine
You are welcome 🙂
Step 5 backend_defualt{
}
Two things:
What If i have a server with 4 ip addresses? Also using port 80 didn’t work for me. I had to use 8080 which worked for some reason.
Jake,
You can use the default IP address.
Thanks, I’ll give it a try!
Thank you it helped me alot and solved my server problem
You’re welcome!
Does it make sense to use Varnish for WordPress site? And I am using Cloud Flare. Can I use Varnish with it?
Sure, it’s a server side caching.
However, I moved this to our forums discussion.
http://crybit.com/discussions/topic/varnish-wordpress-cloudflare/
Hello Arun,
in the back end default should we use the port of apache or varnish.
Most reliable and sensible tutorial without any complications. Well done.
On behalf of Heba you are most welcome, Akhil!
Thanks, Arun keep rocking.
This repo is invalid
# wget http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.noarch.rpm
Hi, I was looking for ssl termination, this varnish configuration works with ssl? Did you test the “hit” in the header?
Thanks
hello
thanks for this great tutorial – however, I am getting stuck on point number 4. varnish is installed but I dont have a file /etc/sysconfig/varnish to edit – in the sysconfig folder there is no varnish file to edit 🙁 I’m not sure what to do now
Hi Thanks for great tutorial.
I followed same steps.. Everything is ends up with success message
But in CPanel I’m not able to view varnish cache option?
Have you tried out varnish and nginx configuration. The process is little complicated, but it works like a charm. Here: http://www.cloudways.com/blog/configure-varnish-cache/
It is better to use Nginx as well with varnish because the loading time can be further improved. If you are using Memcached as well, then this would be great for database performance as well.
Hi.
I followed the steps for CentOS7 server with cpanel but /etc/varnish/varnish.params file doesn’t get created so am unable to update varnish port.
Please suggest.
Please suggest as waiting for your update for /etc/varnish/varnish.params file not created
It says
wget: unable to resolve host address ‘repo.varnish-cache.org’
Is the repo url changes? where I can find the updated one?