{"id":486,"date":"2018-03-14T02:59:44","date_gmt":"2018-03-14T07:59:44","guid":{"rendered":"https:\/\/linuxhostsupport.com\/blog\/?p=486"},"modified":"2020-08-02T11:49:04","modified_gmt":"2020-08-02T16:49:04","slug":"how-to-speed-up-drupal-using-varnish-on-debian-9","status":"publish","type":"post","link":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/","title":{"rendered":"How to Speed Up Drupal Using Varnish on Debian 9"},"content":{"rendered":"<div id=\"linux-3356262168\" class=\"linux-before-1st-paragraph linux-entity-placement\" style=\"margin-top: 15px;margin-bottom: 15px;\"><a href=\"https:\/\/www.rosehosting.com\/managed-vps-hosting\/?mtm_campaign=blogs&#038;mtm_source=lhs&#038;mtm_medium=blog&#038;mtm_content=managed-vps&#038;mtm_cid=1339&#038;mtm_placement=inline\" aria-label=\"Untitled\"><img src=\"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2020\/12\/1340090_NVMeGoogleAds_728x90_041322.jpg\" alt=\"\"  srcset=\"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2020\/12\/1340090_NVMeGoogleAds_728x90_041322.jpg 728w, https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2020\/12\/1340090_NVMeGoogleAds_728x90_041322-300x37.jpg 300w\" sizes=\"(max-width: 728px) 100vw, 728px\" width=\"728\" height=\"90\"  style=\"display: inline-block;\" \/><\/a><\/div><p>We&#8217;ll show you how to speed up Drupal using Varnish on a Debian 9 VPS. Drupal is a popular open source <span class=\"st\">web content management<\/span> software written in PHP. Drupal is compatible with Varnish 3 and Varnish 4. It is a cross-platform application and supports all popular operating systems, but this tutorial was written for Debian 9 OS. At the time of writing this tutorial, the latest stable version of Drupal is 8.4.4, and it requires:<\/p>\n<p><!--more--><\/p>\n<ul>\n<li>PHP 5.5.9 or higher (preferably PHP 7.0), with GD library, JSON, cURL, mysqli , Mbstring, DOM, OpenSSL and XML PHP extensions enabled. PHP 7.2 is not supported on the current release.<\/li>\n<li>MySQL &#8211; 5.5.3 (MariaDB 5.5.20, Percona 5.5.8) or higher with an InnoDB-compatible primary storage engine, PostgreSQL &#8211; 9.1.2 or higher, or QLite &#8211; 3.6.8 or higher<\/li>\n<li>Apache web server 2.2 or higher compiled with mod_rewrite module and AllowOverride set to &#8216;All&#8217; (please note, the default setting for AllowOverride in Apache 2.3.9 and higher is &#8216;None&#8217;).<\/li>\n<\/ul>\n<p>This install guide assumes that Apache and MySQL\/MariaDB are already installed and configured on your virtual server.<br \/>\nLet&#8217;s start with the installation procedure.<\/p>\n<h2>1. Update the System Packages<\/h2>\n<p>Make sure your server Debian 9 OS packages are fully up-to-date:<\/p>\n<pre>apt-get update \r\napt-get upgrade<\/pre>\n<h2>2. Install the Required Packages<\/h2>\n<p>Install the required PHP packages for Drupal 8:<\/p>\n<pre>apt-get install php7.0 php7.0-cli php7.0-common php7.0-mbstring php7.0-curl php7.0-gd php7.0-json php7.0-mcrypt php7.0-mysql php7.0-xml<\/pre>\n<h2>3. Enable Apache Rewrite Module<\/h2>\n<p>Enable Apache rewrite module if it is not already done so:<\/p>\n<pre>a2enmod rewrite<\/pre>\n<h2>4. Restart Apache<\/h2>\n<p>Restart the Apache service for the changes to take effect:<\/p>\n<pre>service apache2 restart<\/pre>\n<h2>5. Download and Extract Drupal 8 Files<\/h2>\n<p>Download Drupal 8 and install if from source, or install Drupal 8 using Composer.<\/p>\n<h3>5.1 Download Drupal 8 from source<\/h3>\n<p>Download the latest version of Drupal available at https:\/\/www.drupal.org\/download in the \/opt\/ directory on the server:<\/p>\n<pre>cd \/opt\/\r\nmkdir -p \/var\/www\/html\/yourdomain.com\/\r\nwget -O drupal8.tar.gz https:\/\/ftp.drupal.org\/files\/projects\/drupal-8.4.4.tar.gz\r\ntar -xvzf drupal*\r\nmv drupal-*\/* \/var\/www\/html\/yourdomain.com\/<\/pre>\n<h3>5.2 Download and Install Drupal 8 using Composer &#8211; a PHP dependency manager<\/h3>\n<p>If you downloaded and extracted Drupal from source, you can <strong>skip this step<\/strong> and go to step 6.<br \/>\nInstall Composer:<\/p>\n<pre>apt-get install composer<\/pre>\n<pre>mkdir -p \/var\/www\/html\/yourdomain.com\/\r\ncd \/var\/www\/html\/yourdomain.com\/<\/pre>\n<p>To install the Drupal 8 website on a development server, run:<\/p>\n<pre>composer create-project drupal-composer\/drupal-project:8.x-dev \/var\/www\/html\/yourdomain.com\/ --stability dev --no-interaction<\/pre>\n<p>Optionally, install Twig C extension:<\/p>\n<pre>composer require twig\/twig:~1.0<\/pre>\n<p>To install the Drupal 8 website on a production server, you also need to run:<\/p>\n<pre>composer install --no-dev<\/pre>\n<p>This will run the composer install process again remove everyhing from the &#8220;require-dev&#8221; section from the composer.lock file.<\/p>\n<h2>6. Set Proper Ownership of Drupal Files<\/h2>\n<p>All files have to be readable by the web server, so set a proper ownership:<\/p>\n<pre>chown www-data:www-data -R \/var\/www\/html\/yourdomain.com\/<\/pre>\n<h2>7. Create MySQL Database and User<\/h2>\n<p>Create a new MySQL database and user:<\/p>\n<pre>mysql -u root -p\r\nmysql&gt; SET GLOBAL sql_mode='';\r\nmysql&gt; CREATE DATABASE drupaldb;\r\nmysql&gt; CREATE USER 'drupaluser'@'localhost' IDENTIFIED BY 'y0uR-pa5sW0rd';\r\nmysql&gt; GRANT ALL PRIVILEGES ON drupaldb.* TO 'drupaluser'@'localhost';\r\nmysql&gt; FLUSH PRIVILEGES;\r\nmysql&gt; quit<\/pre>\n<p>Do not forget to replace &#8216;y0uR-pa5sW0rd&#8217; with a strong password.<\/p>\n<h2>8. Install and Configure Varnish<\/h2>\n<pre>apt-get install varnish<\/pre>\n<p>Configure Varnish to listen on port 80. Edit the &#8216;\/etc\/default\/varnish&#8217; Varnish configuration file:<\/p>\n<pre>nano etc\/default\/varnish<\/pre>\n<p>Add these lines at the end:<\/p>\n<pre>DAEMON _OPTS=\"-a :80\\\r\n  -T localhost:6082\r\n  -f \/etc\/varnish\/default.vcl\r\n  -s malloc,512m\"\r\n  -S \/etc\/varnish\/secret<\/pre>\n<p>Create a new varnish startup script for systemd:<\/p>\n<pre>nano \/etc\/systemd\/system\/varnish.service<\/pre>\n<pre>[Unit]\r\nDescription=Varnish HTTP accelerator\r\nDocumentation=https:\/\/www.varnish-cache.org\/docs\/4.1\/ man:varnishd\r\n\r\n[Service]\r\nType=simple\r\nLimitNOFILE=131072\r\nLimitMEMLOCK=82000\r\nExecStart=\/usr\/sbin\/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f \/etc\/varnish\/default.vcl -S \/etc\/varnish\/secret -s malloc,512m\r\nProtectSystem=full\r\nProtectHome=true\r\nPrivateTmp=true\r\nPrivateDevices=true\r\n\r\n[Install]\r\nWantedBy=multi-user.target<\/pre>\n<p>Run the following command to reload systemd manager configuration:<\/p>\n<pre>systemctl daemon-reload<\/pre>\n<p>Back up default.vcl:<\/p>\n<pre>mv \/etc\/varnish\/default.vcl \/etc\/varnish\/default.vcl.bak<\/pre>\n<p>Create a new default.vcl file (do not forget to <strong>change <\/strong><span style=\"color: #ff0000;\">yourdomain.com<\/span> with the actual domain name):<\/p>\n<pre>nano \/etc\/varnish\/default.vcl<\/pre>\n<p>Add these lines<\/p>\n<p>backend default {<\/p>\n<p>.host = &#8220;<span style=\"color: #ff0000;\">yourdomain.com<\/span>&#8220;;<\/p>\n<p>.port = &#8220;8080&#8221;;<\/p>\n<p>}<\/p>\n<p># Access control list for PURGE requests.<br \/>\n# Here you need to put the IP address of your web server<br \/>\nacl purge {<br \/>\n&#8220;127.0.0.1&#8221;;<br \/>\n}<\/p>\n<p># Respond to incoming requests.<br \/>\nsub vcl_recv {<br \/>\n# Add an X-Forwarded-For header with the client IP address.<br \/>\nif (req.restarts == 0) {<br \/>\nif (req.http.X-Forwarded-For) {<br \/>\nset req.http.X-Forwarded-For = req.http.X-Forwarded-For + &#8220;, &#8221; + client.ip;<br \/>\n}<br \/>\nelse {<br \/>\nset req.http.X-Forwarded-For = client.ip;<br \/>\n}<br \/>\n}<\/p>\n<p># Only allow PURGE requests from IP addresses in the &#8216;purge&#8217; ACL.<br \/>\nif (req.method == &#8220;PURGE&#8221;) {<br \/>\nif (!client.ip ~ purge) {<br \/>\nreturn (synth(405, &#8220;Not allowed.&#8221;));<br \/>\n}<br \/>\nreturn (hash);<br \/>\n}<\/p>\n<p># Only allow BAN requests from IP addresses in the &#8216;purge&#8217; ACL.<br \/>\nif (req.method == &#8220;BAN&#8221;) {<br \/>\n# Same ACL check as above:<br \/>\nif (!client.ip ~ purge) {<br \/>\nreturn (synth(403, &#8220;Not allowed.&#8221;));<br \/>\n}<\/p>\n<p># Logic for the ban, using the Cache-Tags header. For more info<br \/>\n# see https:\/\/github.com\/geerlingguy\/drupal-vm\/issues\/397.<br \/>\nif (req.http.Cache-Tags) {<br \/>\nban(&#8220;obj.http.Cache-Tags ~ &#8221; + req.http.Cache-Tags);<br \/>\n}<br \/>\nelse {<br \/>\nreturn (synth(403, &#8220;Cache-Tags header missing.&#8221;));<br \/>\n}<\/p>\n<p># Throw a synthetic page so the request won&#8217;t go to the backend.<br \/>\nreturn (synth(200, &#8220;Ban added.&#8221;));<br \/>\n}<\/p>\n<p># Only cache GET and HEAD requests (pass through POST requests).<br \/>\nif (req.method != &#8220;GET&#8221; &amp;&amp; req.method != &#8220;HEAD&#8221;) {<br \/>\nreturn (pass);<br \/>\n}<\/p>\n<p># Pass through any administrative or AJAX-related paths.<br \/>\nif (req.url ~ &#8220;^\/status\\.php$&#8221; ||<br \/>\nreq.url ~ &#8220;^\/update\\.php$&#8221; ||<br \/>\nreq.url ~ &#8220;^\/admin$&#8221; ||<br \/>\nreq.url ~ &#8220;^\/admin\/.*$&#8221; ||<br \/>\nreq.url ~ &#8220;^\/flag\/.*$&#8221; ||<br \/>\nreq.url ~ &#8220;^.*\/ajax\/.*$&#8221; ||<br \/>\nreq.url ~ &#8220;^.*\/ahah\/.*$&#8221;) {<br \/>\nreturn (pass);<br \/>\n}<\/p>\n<p># Removing cookies for static content so Varnish caches these files.<br \/>\nif (req.url ~ &#8220;(?i)\\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js)(\\?.*)?$&#8221;) {<br \/>\nunset req.http.Cookie;<br \/>\n}<\/p>\n<p># Remove all cookies that Drupal doesn&#8217;t need to know about. We explicitly<br \/>\n# list the ones that Drupal does need, the SESS and NO_CACHE. If, after<br \/>\n# running this code we find that either of these two cookies remains, we<br \/>\n# will pass as the page cannot be cached.<br \/>\nif (req.http.Cookie) {<br \/>\n# 1. Append a semi-colon to the front of the cookie string.<br \/>\n# 2. Remove all spaces that appear after semi-colons.<br \/>\n# 3. Match the cookies we want to keep, adding the space we removed<br \/>\n# previously back. (\\1) is first matching group in the regsuball.<br \/>\n# 4. Remove all other cookies, identifying them by the fact that they have<br \/>\n# no space after the preceding semi-colon.<br \/>\n# 5. Remove all spaces and semi-colons from the beginning and end of the<br \/>\n# cookie string.<br \/>\nset req.http.Cookie = &#8220;;&#8221; + req.http.Cookie;<br \/>\nset req.http.Cookie = regsuball(req.http.Cookie, &#8220;; +&#8221;, &#8220;;&#8221;);<br \/>\nset req.http.Cookie = regsuball(req.http.Cookie, &#8220;;(SESS[a-z0-9]+|SSESS[a-z0-9]+|NO_CACHE)=&#8221;, &#8220;; \\1=&#8221;);<br \/>\nset req.http.Cookie = regsuball(req.http.Cookie, &#8220;;[^ ][^;]*&#8221;, &#8220;&#8221;);<br \/>\nset req.http.Cookie = regsuball(req.http.Cookie, &#8220;^[; ]+|[; ]+$&#8221;, &#8220;&#8221;);<\/p>\n<p>if (req.http.Cookie == &#8220;&#8221;) {<br \/>\n# If there are no remaining cookies, remove the cookie header. If there<br \/>\n# aren&#8217;t any cookie headers, Varnish&#8217;s default behavior will be to cache<br \/>\n# the page.<br \/>\nunset req.http.Cookie;<br \/>\n}<br \/>\nelse {<br \/>\n# If there is any cookies left (a session or NO_CACHE cookie), do not<br \/>\n# cache the page. Pass it on to Apache directly.<br \/>\nreturn (pass);<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p># Set a header to track a cache HITs and MISSes.<br \/>\nsub vcl_deliver {<br \/>\n# Remove ban-lurker friendly custom headers when delivering to client.<br \/>\nunset resp.http.X-Url;<br \/>\nunset resp.http.X-Host;<br \/>\n# Comment these for easier Drupal cache tag debugging in development.<br \/>\nunset resp.http.Cache-Tags;<br \/>\nunset resp.http.X-Drupal-Cache-Contexts;<\/p>\n<p>if (obj.hits &gt; 0) {<br \/>\nset resp.http.Cache-Tags = &#8220;HIT&#8221;;<br \/>\n}<br \/>\nelse {<br \/>\nset resp.http.Cache-Tags = &#8220;MISS&#8221;;<br \/>\n}<br \/>\n}<\/p>\n<p># Instruct Varnish what to do in the case of certain backend responses (beresp).<br \/>\nsub vcl_backend_response {<br \/>\n# Set ban-lurker friendly custom headers.<br \/>\nset beresp.http.X-Url = bereq.url;<br \/>\nset beresp.http.X-Host = bereq.http.host;<\/p>\n<p># Cache 404s, 301s, at 500s with a short lifetime to protect the backend.<br \/>\nif (beresp.status == 404 || beresp.status == 301 || beresp.status == 500) {<br \/>\nset beresp.ttl = 10m;<br \/>\n}<\/p>\n<p># Don&#8217;t allow static files to set cookies.<br \/>\n# (?i) denotes case insensitive in PCRE (perl compatible regular expressions).<br \/>\n# This list of extensions appears twice, once here and again in vcl_recv so<br \/>\n# make sure you edit both and keep them equal.<br \/>\nif (bereq.url ~ &#8220;(?i)\\.(pdf|asc|dat|txt|doc|xls|ppt|tgz|csv|png|gif|jpeg|jpg|ico|swf|css|js)(\\?.*)?$&#8221;) {<br \/>\nunset beresp.http.set-cookie;<br \/>\n}<\/p>\n<p># Allow items to remain in cache up to 6 hours past their cache expiration.<br \/>\nset beresp.grace = 6h;<br \/>\n}<\/p>\n<h2>9. Change Apache Listening ports<\/h2>\n<pre>nano \/etc\/apache2\/ports.conf<\/pre>\n<pre>Change:\r\nListen 80\r\nto\r\nListen 8080<\/pre>\n<p>Edit the main Apache configuration file (\/etc\/apache2\/apache2.conf), search for &#8221; and change &#8216;AllowOverride None&#8217; to &#8216;AllowOverride All&#8217; so it looks like:<\/p>\n<p>&lt;Directory \/var\/www\/&gt;<br \/>\nOptions Indexes FollowSymLinks<br \/>\nAllowOverride All<br \/>\nRequire all granted<br \/>\n&lt;\/Directory&gt;<\/p>\n<p>Also, change the port from 80 to 8080 in all virtual hosts located in \/etc\/apache2\/sites-available directory.<\/p>\n<h2>10. Create a New Virtual Host in Apache<\/h2>\n<p>Create a new virtual host directive in Apache. For example, create a new Apache configuration file named \u2018yourdomain.conf\u2019 on your virtual server:<\/p>\n<pre>touch \/etc\/apache2\/sites-available\/yourdomain.conf\r\nln -s \/etc\/apache2\/sites-available\/yourdomain.conf \/etc\/apache2\/sites-enabled\/yourdomain.conf\r\nnano \/etc\/apache2\/sites-available\/yourdomain.conf<\/pre>\n<p>Then, add the following lines:<\/p>\n<p>&lt;VirtualHost *:8080&gt;<br \/>\nServerAdmin admin@your-domain.com<br \/>\nDocumentRoot \/var\/www\/html\/yourdomain.com<br \/>\nServerName yourdomain.com<br \/>\nServerAlias www.yourdomain.com<br \/>\n&lt;FilesMatch \\.php$&gt;<br \/>\nSetHandler application\/x-httpd-php<br \/>\n&lt;\/FilesMatch&gt;<br \/>\n&lt;Directory \/&gt;<br \/>\nOptions FollowSymLinks<br \/>\nAllowOverride All<br \/>\n&lt;\/Directory&gt;<br \/>\n&lt;Directory \/var\/www\/html\/yourdomain.com&gt;<br \/>\nDirectoryIndex index.php<br \/>\nOptions Indexes FollowSymLinks MultiViews<br \/>\nAllowOverride All<br \/>\nRequire all granted<br \/>\n&lt;\/Directory&gt;<br \/>\nErrorLog \/var\/log\/apache2\/yourdomain.com-error_log<br \/>\nCustomLog \/var\/log\/apache2\/yourdomain.com-access_log common<br \/>\n&lt;\/VirtualHost&gt;<\/p>\n<p>If you downloaded Drupal 8 using Composer, replace &#8216;\/var\/www\/html\/yourdomain.com&#8217; with &#8216;\/var\/www\/html\/yourdomain.com\/web&#8217; in the &#8216;DocumentRoot&#8217; and &#8216;Directory&#8217; virtual host directives.<\/p>\n<h2>11. Restart Apache and Varnish<\/h2>\n<p>Restart Apache and Varnish services for the changes to take effect:<\/p>\n<pre>service apache2 restart\r\nservice varnish restart<\/pre>\n<h2>12. Install Drupal 8<\/h2>\n<p>Open http:\/\/yourdomain.com in a web browser , choose install language, click on the &#8216;Save and continue&#8217; button, select an installation profile (standard), enter the database name, username and password and start the installation. Once installed, you will automatically be redirected to the Drupal 8 administration back-end.<\/p>\n<h2>13. Configure Caching<\/h2>\n<p>Go to the Drupal 8 administration back-end, click Configuration &gt;&gt; Performance &gt;&gt; set the page cache maximum age and click on the &#8216;Save configuration&#8217; button:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-489\" src=\"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9-1.png\" alt=\"How to speed up Drupal using Varnish on Debian 9\" width=\"883\" height=\"619\" srcset=\"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9-1.png 883w, https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9-1-300x210.png 300w, https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9-1-768x538.png 768w\" sizes=\"(max-width: 883px) 100vw, 883px\" \/><\/p>\n<h2>14. Install Purge and Varnish Purger Modules in Drupal 8<\/h2>\n<p>Install the Purge module from the Drupal 8 administration back-end by clicking on Extend &gt;&gt;\u00a0Install new module , then enter: https:\/\/ftp.drupal.org\/files\/projects\/purge-8.x-3.0-beta8.tar.gz in the &#8216;Install from a URL&#8217; field and click on the &#8216;Install&#8217; button.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-490\" src=\"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/speed-up-Drupal-using-Varnish-on-Debian-9.png\" alt=\"speed up Drupal using Varnish on Debian 9\" width=\"808\" height=\"481\" srcset=\"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/speed-up-Drupal-using-Varnish-on-Debian-9.png 808w, https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/speed-up-Drupal-using-Varnish-on-Debian-9-300x179.png 300w, https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/speed-up-Drupal-using-Varnish-on-Debian-9-768x457.png 768w\" sizes=\"(max-width: 808px) 100vw, 808px\" \/><\/p>\n<p>Then, install the Varnish Purger module by clicking on Extend &gt;&gt;\u00a0Install new module &gt;&gt; enter: https:\/\/ftp.drupal.org\/files\/projects\/purge-8.x-3.0-beta8.tar.gz in the &#8216;Install from a URL&#8217; field and click on the &#8216;Install&#8217; button.<\/p>\n<p>Open http:\/\/yourdomain.com\/admin\/modules and select Purge, Purge Drush, Purge Tokens, Purge UI, Cron processor, Late runtime processor, Core tags queuer, Varnish Focal Point Purger, Varnish Image Purge, Varnish Purger and Varnish Purger Tags, then click on the &#8216;Install&#8217; button.<\/p>\n<h2>15. Configure Varnish Purger<\/h2>\n<p>Open http:\/\/yourdomain.com\/admin\/config\/development\/performance\/purge , click Add purger &gt;&gt; Varnish Purger and click on the &#8216;Add&#8217; button. Click on the newly created button, select configure and add &#8216;Varnish Purger&#8217; in the name field:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-492\" src=\"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/how-to-speedup-Drupal-using-Varnish-on-Debian-9.png\" alt=\"how to speed up Drupal using Varnish on Debian 9\" width=\"1507\" height=\"745\" srcset=\"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/how-to-speedup-Drupal-using-Varnish-on-Debian-9.png 1507w, https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/how-to-speedup-Drupal-using-Varnish-on-Debian-9-300x148.png 300w, https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/how-to-speedup-Drupal-using-Varnish-on-Debian-9-768x380.png 768w, https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/how-to-speedup-Drupal-using-Varnish-on-Debian-9-1024x506.png 1024w\" sizes=\"(max-width: 1507px) 100vw, 1507px\" \/><\/p>\n<p>Configure the Purger&#8217;s headers by clicking on Headers &gt;&gt; and enter &#8216;Cache-Tags&#8217;\u00a0 in the header field with the value [invalidation:expression] and click on the &#8216;Save configuration&#8217; button.<\/p>\n<h2><strong>16. Test if Varnish Caching works<\/strong><\/h2>\n<p>In order to test if Varnish caching is woking properly, run the following command on your server:<\/p>\n<pre>curl -s --head http:\/\/yourdomain.com\/about | grep -i cache\r\nCache-Tags: MISS<\/pre>\n<p>Then, run it once again:<\/p>\n<pre>curl -s --head http:\/\/yourdomain.com\/about | grep -i cache<\/pre>\n<p>You should receive an output like this:<\/p>\n<pre>Cache-Tags: HIT<\/pre>\n<p>You can also use varnishadm, varnishstat and varnishlog command line utilities to check if everything works OK.<\/p>\n<p>That is it. Drupal 8 has been configured to use Varnish.<\/p>\n<hr \/>\n<p>Of course you don\u2019t have to speed up Drupal using Varnish on Debian 9, if you use one of our <a href=\"https:\/\/linuxhostsupport.com\/per-incident-support.html\">Linux Server Support Services,<\/a> in which case you can simply ask our expert Linux admins to do this for you. They are available 24\u00d77 and will take care of your request immediately.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>PS<\/strong><span style=\"color: #000000;\">.<\/span><\/span> If you liked this post, on how to speed up Drupal using Varnish on Debian, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.<\/p><div id=\"linux-2166332921\" class=\"linux-after-8th-paragraph linux-entity-placement\" style=\"margin-top: 15px;margin-bottom: 15px;\"><a href=\"https:\/\/www.rosehosting.com\/managed-vps-hosting\/?mtm_campaign=blogs&#038;mtm_source=lhs&#038;mtm_medium=blog&#038;mtm_content=managed-vps&#038;mtm_cid=1340&#038;mtm_placement=inline\" aria-label=\"Untitled\"><img src=\"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2020\/12\/1340095_VPSGoogleAds_728x90_042622.jpg\" alt=\"\"  srcset=\"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2020\/12\/1340095_VPSGoogleAds_728x90_042622.jpg 728w, https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2020\/12\/1340095_VPSGoogleAds_728x90_042622-300x37.jpg 300w\" sizes=\"(max-width: 728px) 100vw, 728px\" width=\"728\" height=\"90\"  style=\"display: inline-block;\" \/><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ll show you how to speed up Drupal using Varnish on a Debian 9 VPS. Drupal is a popular open source web content management software written in PHP. Drupal is compatible with Varnish 3 and Varnish 4. It is a cross-platform application and supports all popular operating systems, but this tutorial was written for Debian [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":487,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[81,88,71,89],"class_list":["post-486","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-debian-9","tag-drupal","tag-speed-up","tag-varnish"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Speed Up Drupal Using Varnish on Debian 9 | LinuxHostSupport<\/title>\n<meta name=\"description\" content=\"We&#039;ll show you how to speed up Drupal using Varnish on a Debian 9 VPS. Drupal is a popular open source web content management software written in PHP.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Speed Up Drupal Using Varnish on Debian 9 | LinuxHostSupport\" \/>\n<meta property=\"og:description\" content=\"We&#039;ll show you how to speed up Drupal using Varnish on a Debian 9 VPS. Drupal is a popular open source web content management software written in PHP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxHostSupport\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/linuxhostsupport\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-14T07:59:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-02T16:49:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9.png\" \/>\n\t<meta property=\"og:image:width\" content=\"750\" \/>\n\t<meta property=\"og:image:height\" content=\"410\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@lnxhostsupport\" \/>\n<meta name=\"twitter:site\" content=\"@lnxhostsupport\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/#\\\/schema\\\/person\\\/53a9571ea078cdf350137a1e97423cfb\"},\"headline\":\"How to Speed Up Drupal Using Varnish on Debian 9\",\"datePublished\":\"2018-03-14T07:59:44+00:00\",\"dateModified\":\"2020-08-02T16:49:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/\"},\"wordCount\":1809,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/03\\\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9.png\",\"keywords\":[\"debian 9\",\"drupal\",\"speed up\",\"varnish\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/\",\"url\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/\",\"name\":\"How to Speed Up Drupal Using Varnish on Debian 9 | LinuxHostSupport\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/03\\\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9.png\",\"datePublished\":\"2018-03-14T07:59:44+00:00\",\"dateModified\":\"2020-08-02T16:49:04+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/#\\\/schema\\\/person\\\/53a9571ea078cdf350137a1e97423cfb\"},\"description\":\"We'll show you how to speed up Drupal using Varnish on a Debian 9 VPS. Drupal is a popular open source web content management software written in PHP.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/03\\\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9.png\",\"contentUrl\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/wp-content\\\/uploads\\\/2018\\\/03\\\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9.png\",\"width\":750,\"height\":410,\"caption\":\"How to speed up Drupal using Varnish on Debian 9\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/how-to-speed-up-drupal-using-varnish-on-debian-9\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Speed Up Drupal Using Varnish on Debian 9\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/\",\"name\":\"LinuxHostSupport\",\"description\":\"Linux Tutorials and Guides\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/#\\\/schema\\\/person\\\/53a9571ea078cdf350137a1e97423cfb\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ed83c63a34114218f977e1f913be03906d17c7d9c800788fcac345f5edaf6cfa?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ed83c63a34114218f977e1f913be03906d17c7d9c800788fcac345f5edaf6cfa?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/ed83c63a34114218f977e1f913be03906d17c7d9c800788fcac345f5edaf6cfa?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\\\/\\\/linuxhostsupport.com\\\/blog\\\/author\\\/r0s3admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Speed Up Drupal Using Varnish on Debian 9 | LinuxHostSupport","description":"We'll show you how to speed up Drupal using Varnish on a Debian 9 VPS. Drupal is a popular open source web content management software written in PHP.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/","og_locale":"en_US","og_type":"article","og_title":"How to Speed Up Drupal Using Varnish on Debian 9 | LinuxHostSupport","og_description":"We'll show you how to speed up Drupal using Varnish on a Debian 9 VPS. Drupal is a popular open source web content management software written in PHP.","og_url":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/","og_site_name":"LinuxHostSupport","article_publisher":"https:\/\/www.facebook.com\/linuxhostsupport","article_published_time":"2018-03-14T07:59:44+00:00","article_modified_time":"2020-08-02T16:49:04+00:00","og_image":[{"width":750,"height":410,"url":"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9.png","type":"image\/png"}],"author":"admin","twitter_card":"summary_large_image","twitter_creator":"@lnxhostsupport","twitter_site":"@lnxhostsupport","twitter_misc":{"Written by":"admin","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/#article","isPartOf":{"@id":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/"},"author":{"name":"admin","@id":"https:\/\/linuxhostsupport.com\/blog\/#\/schema\/person\/53a9571ea078cdf350137a1e97423cfb"},"headline":"How to Speed Up Drupal Using Varnish on Debian 9","datePublished":"2018-03-14T07:59:44+00:00","dateModified":"2020-08-02T16:49:04+00:00","mainEntityOfPage":{"@id":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/"},"wordCount":1809,"commentCount":0,"image":{"@id":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9.png","keywords":["debian 9","drupal","speed up","varnish"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/","url":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/","name":"How to Speed Up Drupal Using Varnish on Debian 9 | LinuxHostSupport","isPartOf":{"@id":"https:\/\/linuxhostsupport.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/#primaryimage"},"image":{"@id":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/#primaryimage"},"thumbnailUrl":"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9.png","datePublished":"2018-03-14T07:59:44+00:00","dateModified":"2020-08-02T16:49:04+00:00","author":{"@id":"https:\/\/linuxhostsupport.com\/blog\/#\/schema\/person\/53a9571ea078cdf350137a1e97423cfb"},"description":"We'll show you how to speed up Drupal using Varnish on a Debian 9 VPS. Drupal is a popular open source web content management software written in PHP.","breadcrumb":{"@id":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/#primaryimage","url":"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9.png","contentUrl":"https:\/\/linuxhostsupport.com\/blog\/wp-content\/uploads\/2018\/03\/How-to-speed-up-Drupal-using-Varnish-on-Debian-9.png","width":750,"height":410,"caption":"How to speed up Drupal using Varnish on Debian 9"},{"@type":"BreadcrumbList","@id":"https:\/\/linuxhostsupport.com\/blog\/how-to-speed-up-drupal-using-varnish-on-debian-9\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linuxhostsupport.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Speed Up Drupal Using Varnish on Debian 9"}]},{"@type":"WebSite","@id":"https:\/\/linuxhostsupport.com\/blog\/#website","url":"https:\/\/linuxhostsupport.com\/blog\/","name":"LinuxHostSupport","description":"Linux Tutorials and Guides","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linuxhostsupport.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/linuxhostsupport.com\/blog\/#\/schema\/person\/53a9571ea078cdf350137a1e97423cfb","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/ed83c63a34114218f977e1f913be03906d17c7d9c800788fcac345f5edaf6cfa?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/ed83c63a34114218f977e1f913be03906d17c7d9c800788fcac345f5edaf6cfa?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ed83c63a34114218f977e1f913be03906d17c7d9c800788fcac345f5edaf6cfa?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/linuxhostsupport.com\/blog\/author\/r0s3admin\/"}]}},"_links":{"self":[{"href":"https:\/\/linuxhostsupport.com\/blog\/wp-json\/wp\/v2\/posts\/486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxhostsupport.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxhostsupport.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxhostsupport.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxhostsupport.com\/blog\/wp-json\/wp\/v2\/comments?post=486"}],"version-history":[{"count":5,"href":"https:\/\/linuxhostsupport.com\/blog\/wp-json\/wp\/v2\/posts\/486\/revisions"}],"predecessor-version":[{"id":1229,"href":"https:\/\/linuxhostsupport.com\/blog\/wp-json\/wp\/v2\/posts\/486\/revisions\/1229"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxhostsupport.com\/blog\/wp-json\/wp\/v2\/media\/487"}],"wp:attachment":[{"href":"https:\/\/linuxhostsupport.com\/blog\/wp-json\/wp\/v2\/media?parent=486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxhostsupport.com\/blog\/wp-json\/wp\/v2\/categories?post=486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxhostsupport.com\/blog\/wp-json\/wp\/v2\/tags?post=486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}