How to Install mod_pagespeed on Apache Server (CentOS)

How to install mod_pagespeed on Apache

mod_pagespeed is a useful Apache module that help speed up your website. It does so by applying ‘output filters’ to some of your website’s files, thereby reducing the number of requests required by web browsers to get those files. It also compresses those files and optimizes their cached size. Here’s how to install mod_pagespeed on Apache server.


How to Install mod_pagespeed on Apache Server (CentOS)


1. Install mod_pagespeed

Ubuntu and Debian offer readymade packages for download and installation. For other distributions, you can download the source and build it.

For 64-bit versions


For 32-bit versions



Install it with the command

rpm -U mod-pagespeed-*.rpm


mod_pagespeed is automatically enabled during installation. Restart Apache to apply the changes.

/etc/init.d/httpd restart


You can test the installation by looking at the response headers of your website. It will have a value for ‘X-Mod-Pagespeed’ with version number.


Building mod_pagespeed from source is beyond the scope of this tutorial. We will be covering it in a separate tutorial.


2. Configuration

The default installation takes care of many settings and you can stop here if you want. You will notice that your website speeds up easily. However, if you want to get more performance, you can try the following settings.

Open mod_pagespeed’s config file

$ nano /etc/httpd/conf.d/pagespeed.conf

The file itself is well documented and allows you to toggle various settings. You can also get a list of filter examples from

Here are some common settings


Turn On/Off mod_pagespeed

ModPagespeed on


ModPagespeed off


Rewrite Levels

You can configure the kind of filters applied. The default filter is CoreFilters that includes


You can disable it if you want

ModPagespeedRewriteLevel PassThrough


Enable Filters

You can enable more filters by adding them as a comma-separated list. For example, you can add type attribute to JS, CSS files (pedantic filter) and remove html comments (remove_comments filter)

ModPagespeedEnableFilters pedantic,remove_comments


Disable Filters

You can also specifically disable filters you don’t want. For example, you can disable “convert JPEG to progressive” even though it is a part of Core Filters

ModPagespeedDisableFilters convert_jpeg_to_progressive


Specify which URLs to rewrite

By default, mod_pagespeed will rewrite every URL that it can. If you don’t want to rewrite certain URLs you can do so with ModPagespeedDisallow directive

ModPagespeedDisallow "*/jquery-ui-*.min.js"

This will disable URL rewriting of any URLs that match the above pattern

If you want, you can disable all rewrites by default, and enable only those ones that you want to

ModPagespeedDisallow "*"
ModPagespeedAllow "http://**/styles/*.css"
ModPagespeedAllow "http://**.html"

This will rewrite only css and html files.


3. Restart Apache

Restart Apache to apply the changes

$ /etc/init.d/httpd restart


Congratulations! You know how to install mod_pagespeed on Apache Server.

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!