Google PageSpeed - Installation on Ubuntu

Since 2011 Google provides an Apache module called Google PageSpeed. This module has some nice features, which can reduce the load time of your website significantly. In this article I want to show you how to install PageSpeed on Ubuntu, give you an example of a configuration and some tips, which may help you get going.

Installation on Ubuntu

First of all we need to have access to the shell of our server. If this isn't possible with your service, you may want to ask your hosting provider to install and enable mod_pagespeed. In this case you might as well just skip this part and continue with the next one. Everyone else should continue as follows.

We will download the most recent version of the module and extract it on our server. You can find more details on the available packages on the official website.

sudo dpkg -i mod-pagespeed-*.deb
apt-get -f install

Afterwards we can just remove the package from our server.

rm mod-pagespeed-*.deb

Finally we need to enable PageSpeed and restart Apache.

a2enmod pagespeed
apache2ctl restart


Google PageSpeed is installed now and hopefully runs flawlessly. The config can be changed within a file called pagespeed.conf (/etc/apache2/mods-available/pagespeed.conf). If for any reason this file is not located at this path, you can search for it with the following command:

locate pagespeed.conf

Personally I like to adjust the settings on a per website basis. This way I can handle things more flexible. In this case we can use the .htaccess file to adjust settings to our needs. You can enable filters of Google PageSpeed one by one. A detailed list of available filters can be found on the following website:


As a little example I would like to show you the configuration of my own website. The statement ModPagespeedRewriteLevel PassThrough deactivates the default (or core) filters of ModPageSpeed. Doing this we are able to just enable the filters that are necessary for us. You can actually just add a comma-separated list of filters behind ModPagespeedEnableFilters. I like the method below better, because this way its easier to determine which filters are enabled at first glance. Also you can disable filters quicker by just removing the line responsible.

<IfModule pagespeed_module> 
  ModPagespeed on
  ModPagespeedRewriteLevel PassThrough
  ModPagespeedEnableFilters extend_cache
  ModPagespeedEnableFilters collapse_whitespace
  ModPagespeedEnableFilters combine_css
  ModPagespeedEnableFilters move_css_to_head
  ModPagespeedEnableFilters flatten_css_imports
  ModPagespeedEnableFilters remove_comments
  ModPagespeedEnableFilters inline_css
  ModPagespeedEnableFilters insert_image_dimensions
  ModPagespeedEnableFilters rewrite_css
  ModPagespeedEnableFilters rewrite_images
  ModPagespeedEnableFilters rewrite_javascript
  ModPagespeedEnableFilters defer_javascript
  ModPagespeedEnableFilters lazyload_images

Testing and Fine Tuning

After we added our settings the big question is, does Google PageSpeed actually run and do its job. We can check this with a simple call from the shell.

curl -D -

If ModPageSpeed is running, it will add a line to the response header of the request. Search for a line that looks something like the line below. It will contain the version number of ModPageSpeed.


After we have verified ModPageSpeed is running, we can use another tool provided by Google: PageSpeed Insights. Its available as an extension for Google Chrome and maybe other browsers. With the help of the tool, you can analyse your website and receive tips for speeding up your page load. To see the difference you can temporarily disable ModPageSpeed for your website, do an analysis and then turn it back on. You might see a big difference in performance.

You should check each project individually, to see which filters are relevant to your website. To do this it might be a good thing to define filters within your .htaccess file. As a final note: PageSpeed Insights is also available as a standalone web tool. Just visit this website to try it out. Have fun.

There are no comments yet.