Installing and Configuring Varnish 3

This guide will briefly go over how to install and configure Varnish Caching on your webhosting account. 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 configure it to cache the contents. It typically speeds up delivery with a factor of 300 – 1000x, depending on your architecture.

Please keep in mind that this is a fairly advanced section and requires you to use root access to perform any actions described. Also, know that unless you pay for a plugin to do so you can not control varnish from the WHM interface.

Preparing to Install Varnish

This will get Apache ready which should be done prior to the installation to avoid port conflicts.

  1. Log into your servers command line interface as the root user. 
  2. Edit the following file.
    vim /var/cpanel/cpanel.config
  3. Look for the line “apache_port” and change it to the following then save the file.
    apache_port=0.0.0.0:8081
  4. Run this command to update the settings.
    /usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings

Installing Varnish

This section will show you how to install Varnish 3 onto your dedicated server.

  1. Check what version of CentOS you are running by entering the following command.
    cat /etc/centos-release
  2. Run the following commands to add the Varnish repositories to your server (Please use the correct command for the current version you are running.).
    CentOS 6 –
    rpm --nosignature -i https://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release/varnish-release-3.0-1.el6.noarch.rpm
    CentOS 5 –
    rpm --nosignature -i https://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.el5.centos.noarch.rpm
  3. Install Varnish via yum.
    yum install varnish

Configuring Varnish

Now that you have Varnish installed, we’ll show you how to set it up. This configuration does the following:

  • Listen on all IP addresses on port 80
  • Set the administrative interface on port 6082 (the default)
  • Forward requests to localhost on port 8081 (Apache server we changed earlier)
  • Set the user/group for child processes to varnish:varnish
  • Use the file storage mechanism at /var/lib/varnish/varnish_storage.bin and use only 2GB for the file.
  1. Edit the following file.
    vim /etc/sysconfig/varnish
  2. Add the following lines to the bottom of the file (After the # DAEMON_OPTS=”” line).
    DAEMON_OPTS="-a :80 \
    -T localhost:6082 \
    -b localhost:8081 \
    -u varnish -g varnish \
    -s file,/var/lib/varnish/varnish_storage.bin,2G"
  3. Save the file. 
  4. Restart the following services for the changes to take affect.
    service varnish restart

    service httpd restart
InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

11 thoughts on “Installing and Configuring Varnish 3

  1. Have you updated your Varnish versions? Because Magento 2 supports these Varnish versions 4.x, 5.X, 6.X and now Magento latest version supports varnish 7.0.

    1. Since this would have to be installed manually you can choose any version of you require. The latest version available is 7.1.1 at this time.

  2. Installing Varnish 4.1 on CentOS 7 relusts with dependency issue,

    Can you provide any suggestions?

     

    –> Running transaction check
    —> Package varnish.x86_64 0:4.1.4-1.el7 will be installed
    –> Processing Dependency: jemalloc for package: varnish-4.1.4-1.el7.x86_64
    –> Processing Dependency: libjemalloc.so.1()(64bit) for package: varnish-4.1.4-1.el7.x86_64
    –> Finished Dependency Resolution
    Error: Package: varnish-4.1.4-1.el7.x86_64 (varnish-4.1)
               Requires: jemalloc
    Error: Package: varnish-4.1.4-1.el7.x86_64 (varnish-4.1)
               Requires: libjemalloc.so.1()(64bit)
     You could try using –skip-broken to work around the problem
     You could try running: rpm -Va –nofiles –nodigest

    1. You are correct, Varnish 3 has ended its life cycle. We do not currently have other instructions for installign Varnish 4. We will test these instructions with the new version and see if new instructions need to be rewritten.

  3. Are there any potential issues or complications to doing this? (WordPress complications, server reboots, etc…?) I have several mission critical sites on my server that I cannot afford to drop but could use the performance increase.

    Are there options to have this done by managed hosting after hours?

    1. Yes, in an ideal situation, any down time would be minimal or non-existent. The restarts required are very quick. I suggest checking with Managed Hosting at your convenience to see if they can do this for you.

  4. As Varnish uses a lot of memory for the VPS1000, is there a web application accelerator recommended by IMH or perhaps a list we can refer to that would be compatible to VPS1000?

    Thanks in advance!

     

  5. Hai, 

    I have zend opcache installed on my VPS. Can I installed also varnish cache with it. I am using inmotionhosting VPS 1000. 

    1. While you can, you likely should not do this on a VPS1000 due to the memory requirements for Varnish. It will likely slow your site further instead of making it faster.

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+