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


wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm

For 32-bit versions


wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.rpm

 

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 http://www.modpagespeed.com

Here are some common settings

 

Turn On/Off mod_pagespeed


ModPagespeed on

or


ModPagespeed off

 

Rewrite Levels

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


add_head
combine_css
convert_jpeg_to_progressive
convert_meta_tags
extend_cache
flatten_css_imports
inline_css
inline_import_to_link
inline_javascript
rewrite_css
rewrite_images
rewrite_javascript
rewrite_style_attributes_with_url

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://*ubiq.co/*/styles/*.css"
ModPagespeedAllow "http://*ubiq.co/*.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!