Linux, PHP

Install mod_pagespeed with Apache on a CentOS

One of the more recently popular modules for Apache is mod_pagespeed, The goal of mod_pagespeed is to speed up your website. It does this by applying filters to a variety of files in order to reduce the number of trips the browser has to make to grab what it needs, to reduce the size of those files and to optimize the length those files are cached. PageSpeed helps you minify CSS, JavaScript and images, remove whitespaces from HTML, and perform many other tasks.

Set the hostname

Before you install any package, ensure that your hostname is correct by completing the Setting Your Hostname section of the Getting Started guide. Issue the following commands to verify that hostname:

hostname -f

Make sure your system is up to date using apt:

sudo apt-get update && apt-get upgrade

This ensures that all software is up to date and running the latest version.

Installing required packages

Pagespeed requires some extra packages, which you should install for proper operation. Do so by issuing the following command in the terminal:

sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip

If you’re on a 64-bit version (likely)…


If you’re on a 32-bit version (less likely)…


Follow up with:

yum install at

(If you do not already have ‘at’ installed)

rpm -U mod-pagespeed-*.rpm

Remove the downloaded package

rm mod-pagespeed-*.deb

The module enables itself automatically when installed. However, you must restart Apache for it to start working.

systemctl restart httpd

You should now have a working version of mod_pagespeed up and running on your VPS. You can check this by looking at your page’s response headers. There should be a value for “X-Mod-Pagespeed” with the version number you installed.

Turn mod_pagespeed On/Off

First off, you can turn the module on or off with the ModPagespeed setting.

ModPagespeed on


ModPagespeed off

Rewrite Levels

You can specify different “levels” of settings to simplify any configuration. The default is “CoreFilters.”It contains a set of filters the Google team believes is safe for use. The filters are the individual actions that are applied to a file. In general, you won’t need to change this value. It’s easier to use this default and then enable or disable filters using the ModPagespeedEnableFilters and ModPagespeedDisableFiltersdirectives.

The default setting:

ModPagespeedRewriteLevel CoreFilters

To disable CoreFilters use this setting:

ModPagespeedRewriteLevel PassThrough

Note: You’ll have to explicitly enable any filters you want to turn on using the “PassThrough” setting.

Using the default “CoreFilters” rewrite level includes a number of filters by default. As of the time of this writing, it includes:?


New filters will be added in the future. By using CoreFilters, you’ll automatically have these filters enabled if they become part of the default set whenever you update mod_pagespeed. Using PassThrough will require you to explicitly enable the new filters.

Tags :