How to optimize your Drupal website

In this tutorial, we examine the fundamental optimization steps required to enhance the performance of your Drupal website.

Read more Drupal tutorials:

A Basic Guide to Drupal Website Management

 Drupal Website Maintenance tutorial

 Drupal Website Security Tutorial

Drupal Optimization Guide

Drupal is a powerful content management system designed for rugged performance. A Drupal website that is well-optimized for performance can handle several million visits each day.  That had been one of the advantages going for Drupal.

There are several ways to configure Drupal for optimal performance. These include optimizing MySQL, implementation of a Content Delivery Network (CDN), and different modes of caching such as View Caching and Page Caching. Apart from these, Drupal offers a range of options to reduce or optimize bandwidth requirements.

Also read:

 Drupal configuration tutorial

 Drupal's Paragraphs Module Tutorial

 How to Speed Up Your Drupal Website

 How to address "failed Drupal Clean url

Installing a new Drupal website 

This post is more of  checklist of performance optimization good for a Drupal website. Here are the recommended steps:

1. Update core module, contribs module, and themes of Drupal site

 You always want to keep the core, contribs module, and themes updated.
a.    To run updates, navigate to “Reports” → “Available Updates”
b.    Click on “Check manually” to scan for additional updates

2. Use Content Delivery Network

Implementing a Content Delivery Network (CDN) with Drupal is a fast and easy way to instantly reduce load times for your website and ensure you are serving your static content (product images, JavaScript, CSS) from CDN.

3. Utilize Caching

Caching is fundamental to improving the speed performance in Drupal. Drupal provides caching options. This is probably the easiest way to speed up Drupal performance on your site.

a.    Page Caching

    To enable caching, navigate to Configuration → Development→ Performance
    Enable “Cache pages for anonymous users” and also “Cache blocks.” You can then choose a time for minimum cache lifetime and expiration of cached pages.

b. Views Caching

1. To enable views caching, navigate to Administration → Structure→ Views
2. Click “Edit” on the view where you want to enable caching
3. Expand the “Advanced box”
4. Select “Time-based” and click on “Apply (all displays)”

c. PHP Caching

PHP Cache (APC) is well-known to increase the speed of Drupal installs. Add the below code .htaccess to enable PHP caching

<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
<IfModule mod_deflate.c>
  # Compress HTML, CSS, JavaScript, Text, XML and fonts
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE font/opentype
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/xml

  # Remove browser bugs (only needed for really old browsers)
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  Header append Vary User-Agent
</IfModule>
# Requires mod_expires to be enabled.
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 30 seconds"
ExpiresByType text/html "access plus 15 days"
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpg "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
ExpiresByType text/js "access plus 1 months"
ExpiresByType text/javascript "access plus 1 months"
</IfModule>

Here are some other caching options that can be used to improve the performance of the Drupal website.

d.   Memcache
e.   File Cache
f.    Redis
g.   Boost (turns all Drupal pages into flat HTML files)

4. Optimize Your Images

You can change the compression ratio of an image. By default in Drupal 7, it is set to 75%.
1. To change the ratio, navigate to Configuration → Image toolkit
2. You can then change the % amount and click on “Save configuration"

5. Use Fast 404 module to reduce 404 error in Drupal

6. Aggregate CSS/JS

By aggregating your CSS and JavaScript files, you can improve the performance of your front-end and download times. This happens because the browser doesn’t have to fetch files, reducing the number of HTTP requests.

1. To enable, navigate to Configuration → Development → Performance
2. Now click on “Aggregate and compress CSS files” and “Aggregate JavaScript files”

3. Click on “Save configuration”

You can also use advagg module to simplify advanced aggregation of CSS/JS

7. Use minify js and css for page speed

8. Use syslog instead of database logging for error log

9. Use search engines like (Apache Solr, Elastic Search)
 
10 Optimize your database

a. Scale-up database server hardware, increase the number of CPU cores, and use RAM and disk storage array technology to maximize I/O on disk reads and minimize latency
b. Reduce the volume of queries by modifying your application or increasing their performance using standard database optimization techniques such as building appropriate indexes of the field. 
c. Use AutoSlave module for master and slave database

$databases['default']['default'] = array (
  'driver' => 'autoslave',
);

$databases['default']['master'] = array (
  'database' => 'mydb',
  'username' => 'username',
  'password' => 'password',
  'host' => 'master.example.com',
  'port' => '',
  'driver' => 'mysql',
  'prefix' => '',
);

$databases['default']['autoslave'] = array (
  'database' => 'mydb',
  'username' => 'username',
  'password' => 'password',
  'host' => 'slave.example.com',
  'port' => '',
  'driver' => 'mysql',
  'prefix' => '',
);

// Use locking that supports force master

$conf['lock_inc'] = 'sites/all/modules/autoslave/memcache-lock.inc';

// Use AutoSlave transactional safe cache wrapper with a memcache backend

$conf['cache_backends'][] = 'sites/all/modules/autoslave/autoslave.cache.inc';
$conf['cache_default_class'] = 'AutoslaveCache';
$conf['autoslave_cache_default_class'] = 'MemCacheDrupal';

11. Disable the PHP Filter module

12. Disable theme registry rebuilding

13. Disable unnecessary modules

You can disable modules—Administration Development tools, Devel, Devel node access, Module Filter, Blog, Forum, Taxonomy, Search, Help, Shortcut, Database Logging, Color, Toolbar, Tracker, Statistics (this module writes to your database on every page load. If you are using Google Analytics you probably don’t need this), Update Manager— if you don’t need their functionality for your site.

14. Use modules—blockcache_alter, elysia_cron, entitycache, pathcache, lazy loading images, Cache Warming— to speed-up the performance of your Drupal website

15 Reverse proxy cache

Consider installing and configuring an HTTP accelerator such as Varnish. Varnish is a “reverse proxy cache” that handles a number of static files and anonymous page-views for your site much faster than Apache

16 Increase the amount of RAM available to the server

If you are on a shared hosting environment, move Drupal to a virtual private server (VPS) where you have full control over the amount of RAM, CPU and disk, and network bandwidth.

17 Change RAM size to 128MB or greater in PHP.ini file

18 Tweak the max_execution_time setting in the PHP.ini from 60 to 120 seconds or greater

if necessary. This will prevent long-running processes such as the cron from timing out and hanging.

19 Tune Apache for Apache max clients

20 Ensure Load balancing

Scale-up by setting up a web farm (multiple web servers) and put a load balancer in front of the web servers. Round robin the load balance by handling the web requests between the web servers

Conclusions

With changing requirements and a rising number of users having varying bandwidths and connectivity options, Drupal provides specific functions and modules to scale up performance. This ensures that the Drupal website with dynamic features and rich content loads faster, responds quickly to database queries, and scales up overall performance.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Speed Up Your Drupal Website

Drupal is one the top Content Management Systems used for web designing today. Like every other...

Installing a new Drupal website

This article takes you through how to install or set up a Drupal website on the internet.Step 1:...

Drupal configuration tutorial

To configure basic settings for your Drupal website, you first need to login to your Drupal...

Drupal Website Maintenance tutorial

Managing your Drupal website involves performing a lot of tasks which include securing your...

Drupal Website Security Tutorial

Drupal is increasingly gaining some popularity popularity and at the same time it is also...

Powered by WHMCompleteSolution