How to Install Varnish on CentOS 7

Install Varnish on CentOS 7

In this article, we will have explained the necessary steps to install Varnish on CentOS 7. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Varnish Cache (also referred to as Varnish) is a proxy and cache, or HTTP accelerator, designed to improve performance for busy, dynamic web sites. By redirecting traffic to static pages, varnish reduces the number of dynamic page calls, thus reducing load. Varnish is designed for content-heavy dynamic web sites as well as heavily consumed APIs.

Install Varnish on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

Step 2. Install Varnish.

Now install Varnish from the EPEL repository using yum command below:

After installation, you will need to start Varnish and enable it to start on boot:

To check the status of Varnish, run the following command:

Check the version of Varnish that is running:

Step 3. Configure Varnish.

Setup Varnish 5 for Apache:

Change VARNISH_LISTEN_PORT from 6081 to 80:

Now edit Apache configuration file:

Search for Listen 80 and replace it with Listen 8080:

Save and close the file, then restart Apache and Varnish to reflect the changes:

Step 4. Test Varnish.

Now you should have Varnish and Apache running together. To verify that Varnish is on and working, you can use the curl command to view the HTTP header:

You should see the output something like this:

Congratulation, you have learned how to install Varnish cache on CentOS 7. If you have any question, please leave a comment below.