Running Drupal on Nginx with Varnish support can improve your site performance. When looking for a fast and easy way to speed up your Drupal websites the steps below are a good place to start. When dealing with high-traffic Drupal websites or blogs you may want to implement some kind of caching mechanism to speed up the sites. One of the popular proxy servers that are also caching servers is Varnish. If you want to build a fast Drupal site with lots of web traffic, setting up Varnish as a proxy caching server will go a long way. As described above, Running Drupal on Nginx with Varnish support can improve your site performance. When looking for a fast and easy way to speed up your Drupal websites the steps below are a good place to start. Below is how to set up Drupal with Apache and Varnish proxy servers on Ubuntu Linux.

Install Apache

First, install Apache. To do that, run the commands below: Next, run the commands below to stop, start and enable the Apache2 service to always start up with the server boots.

Install Varnish

Now that Apache is installed, run the commands below to install Varnish. By default, Varnish packages are available in Ubuntu repositories. After installing Varnish, the commands below can be used to start, stop and enable Varnish to always start up when the server boots.

Switch the Apache port to 8080

By default, Apache listens on port 80. Since we want Varnish to listen for all traffic coming to port 80, we will have to configure Apache to use another port number instead. For this article, we will configure Apache to listen on port 8080. To do that, open the Apache default port configuration file at /etc/apache2/ports.conf and change the Listen value to 8080. Then make sure the file has these lines. Save when done. Next, open the Apache2 default virtual host config file. Then make the highlighted change below. Save the file and exit. After that, run the commands below to disable the Apahce2 default site. Then restart Apache2 Now Apache default site is disabled.

Install MariaDB

To install MariaDB run the commands below. After installing, the commands below can be used to stop, start and enable the MariaDB service to always start up when the server boots. After that, run the commands below to secure the MariaDB server by creating a root password and disallowing remote root access. When prompted, answer the questions below by following the guide.

Enter current password for root (enter for none): Just press the Enter Set root password? [Y/n]: Y New password: Enter password Re-enter new password: Repeat password Remove anonymous users? [Y/n]: Y Disallow root login remotely? [Y/n]: Y Remove test database and access to it? [Y/n]:  Y Reload privilege tables now? [Y/n]:  Y

PHP 7.1 isn’t available on Ubuntu default repositories. to install it, you will have to get it from third-party repositories. Run the commands below to add the below third-party repository to upgrade to PHP 7.1 Then update and upgrade to PHP 7.1 Run the commands below to install PHP 7.1 and related modules. After installing PHP 7.1, run the commands below to open the Apache2 PHP default file. Then make the changes on the following lines below in the file and save. The value below is a great setting to apply in your environments.

Create Drupal Database

Now that you’ve installed all the packages are installed, run the commands below to create a blank Drupal database. Login to the MariaDB database server Then create a database called drupal Create a database user called drupaluser with a new password Then grant the user full access to the database. Finally, save your changes and exit.

Download Drupal Latest Release

Next, visit the Drupal site and download the latest package. or run the commands below to download and extract Drupal content. After downloading, run the commands below to extract the downloaded file and move it into a new Drupal root directory. Then run the commands below to set the correct permissions for Drupal to function properly.

Configure Apache

Finally, configure the Apache2 configuration file for Drupal. This file will control how users access Drupal content. Run the commands below to create a new configuration file called drupal.conf Then copy and paste the content below into the file and save it. Replace the highlighted line with your domain name and directory root location. Save the file and exit.

Enable Drupal virtual host

After configuring the Virtual Host above, enable it by running the commands below To load all the settings above, restart Apache2 by running the commands below.

Set up Varnish to use port 80

Now that port 80 is free, let’s configure Varnish to use that port instead. To assign port 80 to Varnish, run the commands below. Varnish default configure file is located at /etc/default/varnish Open it by running the commands below: Then look for the config block under Alternative 2 and make the highlighted changes as shown below. Save the file when you’re done. Next, run the commands below to open the default.vcl file Then add the highlighted lines shown below under sub vcl_recv and sub vcl_backend_response Save the file and close. When you’re done, restart Varnish and Apache2 Next, run the commands below to start Varnish if it won’t start. After that, open your browser and browse your domain name to launch the WordPress configuration wizard. And you should see the WordPress setup wizard Follow the wizard until you’ve successfully set up WordPress. That’s it!