In this tutorial, we are going to provide you with step by step instructions on how to speed Up Drupal using Varnish on Ubuntu 16.04. Drupal is one of the leading open source content management platforms. At the time of writing this tutorial, the latest stable version of Drupal is 8.3.2 and it requires:
- PHP 5.5.9 or higher (preferably the latest), with XML, openssl, JSON, cURL, mysqli and GD PHP extensions enabled.
- MySQL 5.0.15, MariaDB 5.1.44, SQLite 3.3.7 or PostgreSQL 8.3 or higher.
- Nginx, or Apache web server 2.0 or higher with proper PHP support and mod_rewrite module enabled.
This install guide assumes that Apache is already installed and configured on your virtual server.
Let’s start with the installation.
Table of Contents
1. Update the system
Make sure your server Ubuntu OS packages are fully up-to-date:
2. Install PHP packages
Install the required PHP packages:
3. Enable Apache rewrite module
Since clean URLs are enabled by default, mod_rewrite needs to be installed and enabled for Drupal 8 to work, so enable Apache rewrite module if it is not already done so:
Restart the Apache service for the changes to take effect:
4. Install Varnish
Once installed, Varnish ships with a default configuration file at ‘/etc/varnish/default.vcl’ that should get you up and running, but in order to take advantage of Varnish cache, you may want to do some Drupal specific tuning. These should always be adapted to fit your specific Varnish version and website’s needs.
5. Install Drupal
Download the latest version of Drupal available at https://www.drupal.org to the /opt/ directory on the server:
All files have to be readable by the web server, so set a proper ownership:
6. Create new database
Create a new MySQL database and user:
Do not forget to replace ‘y0uR-pa5sW0rd’ with a strong password.
7. Configure Apache web server
Edit the /etc/apache2/ports.conf Apache configuration file and change the Apache listening port:
to:
Create a new virtual host in Apache. Make sure the new Apache virtual host configuration contains the ‘AllowOverride All’ directive to allow Drupal’s .htaccess file to be used. For example, create a new Apache configuration file named ‘your-domain.conf’ on your virtual server:
Then, add the following lines:
Remove the 000-default.conf file:
8. Configure Varnish
Stop Varnish:
Edit the ‘/etc/default/varnish’ file :
Change port 6081:
to 80:
Edit the systemd unit script:
Change port 6081:
to port 80:
Reload systemd using the following command:
Edit the ‘/etc/varnish/default.vcl’ file and add/modify the following lines:
Enable varnish service to start automatically on server boot using the following command:
9. Restart Apache
Restart the Apache web server for the changes to take effect:
10. Start Varnish
Start the Varnish service:
Open http://your-domain.com in your favorite web browser, and follow the simple on-screen instructions.
Then, log in to your Drupal administration back-end and configure it according to your needs.
That is it. Drupal 8 and Varnish have been installed on your Ubuntu server.
Of course, you don’t have to do any of this if you use one of our Drupal VPS Hosting services, in which case you can simply ask our expert Linux admins to speed Up Drupal using Varnish for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.
Varnish can act as a load balancer or only as cached proxy?
You can use Varnish as load balancer too.