Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of Apache web server and configure it to cache the contents. Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 – 1000x, depending on the specifics of your architecture.
Installation on Amazon Linux takes no more than a few minutes because a package is already available via yum. However, I was bothered by the fact that Amazon’s repository for Varnish is version 3.x, meanwhile Varnish 6.0 was just released. Being the obsessive-compulsive person that I am, I was unenthusiastic about installing a package that is knowingly three full versions behind the curve. While I never got to the bottom of why this is the case, and further, I opened a can of Linux worms trying to create a more up-to-date local repository. Since the however, I’ve concluded that the version 3.x package works just fine inside a standard Apache web server environment.
Incidentally, I was also spooked by the “reverse proxy” nomenclature as I wasn’t entirely sure what this meant. In hindsight, I now know that it means a page cache that sits in front of Apache. Varnish is especially effective because it resides in front of Apache. Varnish is superior to localized plugin-based caching solutions because with php-based applications like WordPress, a lot happens inside php and in the file system; even in cases when you get a page hit with a plugin-based caching solution. By contrast, Varnish is intended to listen on your main traffic port (probably 80 and/or 443), intercepting and intervening on behalf of both Apache and WordPress. For highly dynamic environments like for example, Woo Commerce sites, the performance increase is absolutely stunning. Note that this blog runs behind a Varnish cache.
A final observation before we go to work: this tutorial is derived from an excellent article from Aaron Kili at Tecmint, “Install Varnish Cache 5.2 to Boost Apache Performance on CentOS 7”. I adjusted for the various nuances in the default file storage locations in Amazon Linux, and importantly, this article recommends a different (older) version of Varnish that seems to be the path of least resistance for Amazon Linux. And lastly, I’ve supplemented Aaron’s original guide with some specifics recommendations on how to get WordPress to work well.