How to Install Varnish Cache 6.0 on Ubuntu Linux

|

|

The post describes the step-by-step process of manually installing the Varnish cache server on Ubuntu. It begins with configuring the Apache2 HTTP Server to communicate over port 8080. Then, the process of installing necessary dependencies, downloading the Varnish package, compiling, and finally installing Varnish is presented. After installation, Varnish is set to start and its…

This article explains how to install Varnish Cache version 6.0 on Ubuntu Linux.

If you want to install the Varnish cache server on Ubuntu, quickly fire up the terminal and run the command sudo apt install Varnish. However, doing that will not install your system’s latest version of the Varnish cache.

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

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

To get this working, please follow the steps below:

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 stop, start, and enable Apache2 always to start whenever the server boots up.

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

The apache2 HTTP service is automatically bound to ports 80 and 443 for HTTPS by default. However, 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 the 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 the Apache2 default virtual host config file.

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

Then, make the highlighted change below.

<VirtualHost 127.0.0.1:8080>

Save the file and exit.

Then restart Apache2

sudo systemctl restart apache2.service

To access Apache2, enter the server IP or hostname followed by port # 8080.

ex. http://localhost:8080

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 the Varnish package.

cd /tmp && git clone https://github.com/varnishcache/varnish-cache

After that, change into a 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 the 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 varnish 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 http://localhost

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!


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



2 responses to “How to Install Varnish Cache 6.0 on Ubuntu Linux”

  1. Lucas Barzagli Avatar
    Lucas Barzagli

    How to make systemctl restart varnishd service?

  2. Jakke Avatar
    Jakke

    Who can or will use a configuration without SSL?

Leave a Reply to Lucas BarzagliCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading