Goldlilys Media Logo

How To Install Varnish

To significantly speed up web applications, there is a HTTP web caching accelerator called Varnish. Its main point is to cache contents to speed up the delivery of web pages to its end users. The installation of Varnish may be troublesome, but here are the steps I use to get it working on my own server and for Drupal sites:

  1. Choose your type of server environment. My server runs on CentOS so these steps may not match exactly depending on your server setup.
  2. Get Varnish by https://varnish-cache.org/docs/7.6/installation/install.html
  3. Start it up: /etc/init.d/varnish start.
  4. Once Varnish has been downloaded and installed on your server, next comes the configurations. Verify your Apache Listen Port from vi /etc/httpd/conf/httpd.conf. It is usually set to Port 80 so make sure that you will be using a different Port for Varnish. Why? Because I made a mistake of using the same port for Varnish and Apache (all of my sites) pretty much won’t start up. To check, use sudo netstat -ltnp | grep ':80' and make sure the results only include httpd, which stands for the Apache server.
  5. The default settings for varnish is located at vi /etc/sysconfig/varnish and make sure VARNISH_LISTEN_PORT=6081 is set. If this is the same port as Apache, change it to another port. Save your changes or leave the default options.
  6. Then configure the logic of Varnish at vi /etc/varnish/default.vcl and that the .port= "80" or whatever the Apache Listen Port is setup as. This is the reverse proxy port that’s used, so it’s not supposed to be the same as the Varnish Listen Port. My default config looks like:backend default { .host = "127.0.0.1"; .port = "80"; .connect_timeout = 600s; .first_byte_timeout = 600s; .between_bytes_timeout = 600s; }
  7. For more expert advice on how to better setup the .vcl, I used FourKitchens Varnish as reference.
  8. After all of the configurations, it is now time to restart your server /etc/init.d/httpd restart and varnish /etc/init.d/varnish restart.
  9. Wait, your job is not done yet. We have to get this setup for Drupal. Drush and install Varnish module.
  10. Edit your site’s settings.php and include these on the bottom.

    $conf['cache_backends'][] = 'sites/all/modules/varnish/varnish.cache.inc'; $conf['cache_class_cache_page'] = 'VarnishCache'; $conf['reverse_proxy'] = TRUE; $conf['page_cache_invoke_hooks'] = FALSE; $conf['cache'] = 1; $conf['cache_lifetime'] = 0; $conf['page_cache_maximum_age'] = 21600; $conf['reverse_proxy_header'] = 'HTTP_X_FORWARDED_FOR'; $conf['reverse_proxy_addresses'] = array('127.0.0.1'); $conf['omit_vary_cookie'] = TRUE;

  11. Enable the module and make sure to set the expired caching in the /admin/config/development/performance.
  12. Then in /admin/config/development/varnish verify that the control terminal has the 127.0.0.1:6082 and your varnish control key comes from vi /etc/varnish/secret.
  13. Save configuration and if all is done right, the Status on the bottom should be a Green Checkmark with “Varnish running”.
fgo
Author Bio

Frances Naty Go is the founder of Goldlilys Media, where she helps mission-driven organizations turn their websites into clear, durable systems that support meaningful work over time. She works with museums, nonprofits, health and wellness brands, higher education, life sciences, travel organizations, and expert-led businesses.

With a background in Computer Science from UC San Diego, Frances brings a thoughtful, strategic approach to building digital experiences that educate, orient, and build trust, without unnecessary complexity.

Categories: * * * *
15 Warning Signs Your Website Is Holding You Back Cover

15 Warning Signs Your Website Is Holding You Back

The most costly website problems aren’t obvious.

They show up as hesitation, doubt, and missed opportunities.

This checklist helps you see what visitors experience, before they decide whether to trust you.
Still Using Wix or Squarespace? That Might Be Costing You More Than You Think Cover

When Wix or Squarespace No Longer Fits

Template platforms often make sense early on.

Growth is where their limits start to matter.

This guide helps you assess whether your website still supports where you’re headed.

Related Articles

Imagine your website as amasterpiecebuilt for what comes next.

Thoughtful insights for leaders who want their website decisions to support growth, usability, and long-term confidence, without constant rebuilding or second-guessing.
Frances on her cellphone looking right and smiling
performance optimization
create a website masterpiece
Frances Go standing by the Prado with a big smile holding a Michelangelo maroon book and artworks behind her

Let’s talk about fit

Book a short conversation to discuss where you’re headed and whether your website still supports it.
Still Using Wix or Squarespace? That Might Be Costing You More Than You Think Cover

Does your website still fit where you’re headed?

A short guide to help you assess whether your current setup supports what comes next.
15 Warning Signs Your Website Is Holding You Back Cover

See what’s quietly getting in the way

A short checklist to help you identify subtle website issues that affect trust, traffic, and action.

Wait! Before you go...

Not ready to commit yet?
I get it.

Get my free guide:

"15 Warning Signs Your Website Is Holding You Back"