Pagespeed Module and WordPress on Ubuntu LAMP

Recently I have been tinkering around with SSL and HTTP/2 on my personal portfolio site and have been benefitting from the speed increases it provides. But then I decided to try and take it further and decided a Pagespeed module WordPress installation would be the way to go after a bit of research.

Google’s Pagespeed module, (mod_pagespeed on Apache) offers a lot of on the fly optimisations such as minifying CSS and JavaScript along with resizing and compressing images.

Before I start, I should outline my current setup:

  • Ubuntu 14.04 LTS
  • Apache 2.4.20
  • MariaDB 5.5.49
  • PHP 5.5.34
  • WordPress 4.5

Installing the Pagespeed module for WordPress

Google make installing their Pagespeed module on Ubuntu with Apache very easy, it’s just a case of downloading the .deb installer and running it which also adds their repo to Ubuntu to keep you up to date.

From all the WordPress mod_pagespeed guides I’ve seen online, this is where setup can end if you wish to use the default settings. Unfortunately for me, this was not the case. Though I could see the x-mod-pagespeed header in my network requests, none of my resources were being optimised. But why?

Further investigation led me to a bunch of similar unanswered questions on Stack Overflow, so I fired up the Pagespeed module documentation, cracked open my pagespeed.conf file and began to tinker.

If you open the conf file in your favourite text editor, found at:


and scroll down to towards the bottom you should see a block of text starting with:

Explicitly tell mod_pagespeed to load some resources from disk.

Then uncomment the line that reads:


and add your own domain and path to it, for example:

ModPagespeedLoadFromFile "" "/var/www/html/wp-content/"

and hey presto! The Pagespeed module should now be working its magic on your site, sit back and enjoy your new Pagespeed Insights score.

mod_pagespeed on DigitalOcean

If, like myself, you use the popular cheap VPS hosting service DigitalOcean, it’s likely that you used their one click WordPress droplet. In my experience, DigitalOcean seem to change this droplet quite often, in the past I’ve stumbled across some missing extensions, like PHP_GD which is required for creating thumbnails, or virtual hosts being defined inside the Apache main conf file instead of in sites-available. In my droplet the standard Apache directory structure was a little different, the html directory was not there. If your droplet is the same, your ModPagespeedLoadFromFile line will look more like mine:

ModPagespeedLoadFromFile "" "/var/www/wp-content/"

April 26, 2016