Six ways to improve Drupal 7 performance on small websites
Drupal is a versatile CMS. The drawback of the versatility is the bad performance out of the box. Especially websites with a lot of functionality or websites with not many visitors (where the cache doesn’t get filled) are suffering from it. Luckily, there are some solutions to have a good performance.
Big companies have tools like Varnish at their disposal. But what if you run a small website for yourself or for a small client and you want to have solid performance? Then read on for some options…
Limit the amount of modules
Installing more modules slows down your website. That’s why I choose to use a barebone Drupal or a base install profile and only install the modules I need. When using Drush, installing or activating modules is easy anyway. Also, having a limited amount of modules is also clever when you want to update, take back-ups or migrate to a newer Drupal version.
Deactivate modules
Some modules are not needed in production:
- Update Manager
- Devel: development only module, really important to deactivate this module on production websites
- All the UI submodules (for example Views UI or Field UI).
Performance page
This is a necessary setting, available in the user interface. This is disabled by default (in Drupal 8 this will be enabled by default because on lots of Drupal 7 websites this setting is not enabled). Enable all the caching options and choose 15 minutes as the minimum cache lifetime and 1 day as the cache expiration. This is a good website for low traffic websites.
Views Cache
Almost every Drupal 7 website uses Views (it’s even in core in Drupal 8). Views is necessary and useful, also for complex queries. The drawback is the overall bad performance of Views. Luckily there is something like Views Caching.
Go to the View you want to speed up, under Advanced, click Caching and choose:
- Time-Based
- Query results: 5 min / Rendered output 5 min
Run cron outside of the website
Cron (maintenance tasks) can be run every day. But you don’t have control over the moment it runs. Ideally, cron runs at night when there are not many visitors. You could use a module like Alysia cron but I prefer the light weight method with the command line.
Log in with SSH on your hosting account and heck if there are crontabs running (with the -l or launch switch):
crontab -l
Check the location of wget:
which wget
Normally this sould output /usr/bin/wget
Next, change the file (with the -e or edit switch):
crontab -e
Add a line with:
i
Paste in a line like this:
0 4 * * * /usr/bin/wget -O - -q -t 1 http://www.example.com/cron.php?cron_key=CRONKEY
The cron key can be found under admin > reports in the Drupal back-end.
Next tap:
Esc
And type the command to save and quit:
:wq
Followed by:
Enter
This rule runs cron at 04:00, every night.
Boost
If you want to go further, you could install Drupal Boost. When the Boost cache is warm, end users receive a flat html-page without the database layer. This is as fast as it gets.
Install Boost as follows:
- Install and enable the module
- Make sure Clean URL’s are enabled
- Boost creates a /cache folder in the root of the Drupal installation. Make sure it has the right permissions: 775
- Disable the core page and block cache. This sounds weird but is perfectly logical. Boost takes over the core caching mechanism.
- Copy the code under .htaccess settings and paste it in the .htaccess file, just under # RewriteBase /.
Boost is recommended on small website with content not changing and with only anonymous traffic.
But it has some side effects out of the box: when the cache isn’t warm, the load time is very slow, because (just like the Drupal cache) the module expects users to warm the cache.
There are ways to prevent this from happening. The Rules module can cache new or changed pages or blocks. Check this interesting article by Vacilando. Or you could use a crawler at night to cache all these pages. The list of URL’s can be provided by the XML Sitemap module. For more information about this method, take a look at a good article by Tom Roelandts.
Comments
You can use caching and web
You can use caching and web server to speed up the performance of Drupal 7 website as well.
I have hosted my website with Cloudways (https://www.cloudways.com/en/drupal-cloud-hosting.php ) and they use Apache, Nginx, Memcached and Varnish stack on their platform. Apart from that, I also use Cloudflare CDN and PHP 7. When all of this is combined, it becomes a powerhouse for high speed Drupal website.
Hi, could you explain the
Hi, could you explain the reasoning for setting the minimum cache lifetime on a low trafficked site to 15 min?
thanks,
Add new comment