Varnish is one of my favorite ways to speed up and scale WordPress. Some hosts like Cloudways and WPEngine have Varnish configured on the server to help deliver fast pages to your users. If you want to install Varnish on your own Vultr server this guide is for you. The Varnish packages have been moved to packagecloud repositories so we won’t have to download any deb files manually :).
Install Varnish 5 on Debian 9
Check your CPU architecture
You should see this output showing that we are using modern software.
x86_64
If you see i686
then you will have to compile Varnish 5 from source which will be covered in another article.
Add the packagecloud GPG key so that the repository will be authenticated and verified.
Make sure you have these packages for using https repositories
Add the Varnish 5 repository from packagecloud for debian stretch
Install Varnish 5.x on Debian 9 with this command
Now you probably want to make Varnish listen on port 80, we do that by modifying the systemd script safely so that it survives updates.
Please make sure to change your nginx and/or Apache virtual hosts to not use port 80 or Varnish won’t be able to use port 80!
Make Varnish systemd Port 80
The way systemd works we have to create a drop-in systemd file that overrides the ExecStart line. This ensures that the changes made directly to the systemd service are not overwritten when there is an upgrade.
Paste these lines, the 80
is for the port so if your system requires Varnish to run on a different port besides 80
then make sure to change it.
Ctrl+X, Y and Enter
Varnish must be restarted when the port is changed
Check Varnish is listening on port 80
If you see any output you will see the IP addresses (0.0.0.0
signifying all addresses and 127.0.0.1
meaning the virtual loopback adapter) and ports Varnish 5 is listening on: ports 80
and 6082
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5359/varnishd
tcp 0 0 127.0.0.1:6082 0.0.0.0:* LISTEN 5359/varnishd
tcp6 0 0 :::6081 :::* LISTEN 5359/varnishd
tcp6 0 0 ::1:6082 :::* LISTEN 5359/varnishd
Done! If you would like to see a sample Varnish vcl for WordPress see this post.
I have Memcached and OPCache with Nginx + php7. Can I install and combine with Varnish ??
You definitely can! Varnish is used for page caching so unless you are using a page cache with nginx then it should be a welcome addition to your stack