Install Varnish Cache 6.0 ( Latest) on Ubuntu 16.04 | 18.04 LTS

If you want to install Varnish cache server on Ubuntu, you can quickly fire up the terminal and run the commands sudo apt install varnish. However, doing that will not install the latest version of Varnish cache on your systems.

If you need the latest version of Varnish, you’ll have to manually compile it yourself and install. this post shows students and new users how to manually compile and install Varnish cache 6.0 which is the latest at the time of this post on Ubuntu 16.04 | 18.04 LTS servers.

For this post, we’ll install Apache2 web server and configure it to listen on port 8080. then install Varnish and configure it to listen on port 80. Varnish will cache all requests for Apache2 pages when they are made.

To get this working, please follow the steps below:

Step 1: Install Apache2 HTTP Server

To install Apache2 on Ubuntu run the commands below.

sudo apt-get update
sudo apt-get install apache2

After installing Apache2, the commands below can be used to stop, start and enable Apache2 to always startup everytime the server boots up.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

By default apache2 HTTP service automatically is bond to port 80 and 443 for HTTPS.  We want Varnish to communicate over port 80 instead. So continue below to configure Apache2 to talk on Port 8080.

To quickly change the port run the commands below to open Apache2 default port configuration file.

sudo nano /etc/apache2/ports.conf

Then make sure the file has these lines. Save when done.

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 127.0.0.1:8080

Next, open Apache2 default virtualhost config file.

sudo nano /etc/apache2/sites-available/000-default.conf

Then make the highlighted change below.

<VirtualHost 127.0.0.1:8080>

Save then file and exit.

Then restart Apache2

sudo systemctl restart apache2.service

Now to access Apache2, you’ll have to enter the server IP or hostname followed by port # 8080.

ex.

Step 2: Installing Varnish 6.0

Now that Apache2 is installed and communicating over port 8080, follow the steps below to install the latest version of Varnish.

First install all dependencies for Varnish by running the commands below.

sudo apt-get install make automake autotools-dev libedit-dev libjemalloc-dev libncurses-dev libpcre3-dev libtool pkg-config python-docutils python-sphinx graphviz autoconf-archive curl git

Next, run the commands below to download Varnish package.

cd /tmp && git clone

After that, change into varnish-cache folder and begin compiling.

cd varnish-cache
sudo sh autogen.sh
sudo sh configure
sudo make

Next, run the commands below to install Varnish cache.

sudo make install

It should take a few minutes for it to install. after that Varnish will now be installed in /usr/local. The varnishd binary is in /usr/local/sbin/varnishd. To make sure that the necessary links and caches of the most recent shared libraries are found, run

sudo ldconfig

If Varnish was successfully installed, run the commands below to start it.

sudo varnishd -a :80 -T localhost:6082 -b localhost:8080

That should do it. to test, run the commands below.

curl -I

and you should see something like the text below:

HTTP/1.1 200 OK
Date: Wed, 25 Jul 2018 17:06:30 GMT
Server: Apache/2.4.29 (Ubuntu)
Last-Modified: Wed, 25 Jul 2018 16:33:11 GMT
Vary: Accept-Encoding
Content-Type: text/html
X-Varnish: 32770
Age: 0
Via: 1.1 varnish (Varnish/6.0)
ETag: W/"2aa6-571d56f3d8a6a-gzip"
Accept-Ranges: bytes
Connection: keep-alive

Enjoy!

You may also like the post below: