Did You Know?
Got a tip? Let us know

LFCS - Linux Foundation Certified SysAdmin - Exam Preparation Guide

Install mod_pagespeed (Website Optimizer) for Apache in RHEL, CentOS and Fedora

Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators

This is our new series on Apache optimization, here we are introducing a new Google‘s product called mod_pagespeed module for Apache that makes the web site load much faster than ever. I have personally tested this module on our Live (tecmint.com) server and results are amazing, now the site loads much faster then before. I recommend you all to install it and see the results.

In this article we will show you how to install and configure Google‘s mod_pagespeed module for Apache in RHEL 6.3/6.2/6.1/6/5.8, CentOS 6.3/6.2/6.1/6/5.8 and Fedora 12,13,14,15,16,17 systems using Google’s repository so that your system will gets regular updates automatically and stays up to date.

What Is Mod_PageSpeed

mod_pagespeed is an open source module for Apache web server that automatically optimize Web Pages to improve better performance while serving web pages using Apache HTTP Server. It has several filters that automatically optimize files like HTML, CSS, JavaScript, JPEG, PNG and other resources.

Currently mod_pagespeed module supported Linux platforms are RHEL/CentOS/Fedora and Debian/Ubuntu for 32 bit and 64 bit distributions.

Install mod_pagespeed for Apache in RHEL 6.3/6.2/6.1/6/5.8, CentOS 6.3/6.2/6.1/6/5.8 and Fedora 17,16,15,14,13,12

Installing mod_pagespeed Module for Apache in RHEL, CentOS and Fedora

As I discussed above that we are using Google‘s repository to install it for future updates, so let’s add the repository to your systems based on your OS architecture.

Step 1: Enabling Google’s mod_pagespeed Repository

Create a file called /etc/yum.repos.d/mod-pagespeed.repo with the help of your favourite editor and add the following lines of code to it based on your OS bit.

RHEL/CentOS/Fedora 32-Bit

[mod-pagespeed]
name=mod-pagespeed
baseurl=http://dl.google.com/linux/mod-pagespeed/rpm/stable/i386
enabled=1
gpgcheck=0

RHEL/CentOS/Fedora 64-Bit

[mod-pagespeed]
name=mod-pagespeed
baseurl=http://dl.google.com/linux/mod-pagespeed/rpm/stable/x86_64
enabled=1
gpgcheck=0

Step 2: Installing mod_pagespeed Module for Apache

We use Yum to install the mod_pagespeed on systems, issue below command.

# yum --enablerepo=mod-pagespeed install mod-pagespeed

Step 3: Configuring mod_pagespeed Module for Apache

Above command creates following directories and files.

  1. /etc/cron.daily/mod-pagespeed : mod_pagespeed cron script for checking and installing latest updates.
  2. /etc/httpd/conf.d/pagespeed.conf : The main configuration file for Apache.
  3. /usr/lib/httpd/modules/mod_pagespeed.so : mod_pagespeed module for Apache.
  4. /var/www/mod_pagespeed/cache : File caching direcotry for web sites.
  5. /var/www/mod_pagespeed/files : File generate prefix for web sites.

Note : No need of additional configuration because mod_pagespeed automatically Turn On.

Step 4: Verifying mod_pagespeed Module for Apache

To verify mod_pagespeed module, first you need to creat a file called phpinfo.php under root directory of Apache and add the following lines of code to it. For example (/var/www/html/phpinfo.php).

<?php
    phpinfo ();
?>

Once you created the above file, then restart the Apache service to take new changes. Now access the file phpinfo.php by navigating to your web browser like http://localhost/phpinfo.php. You will see “X-Mod-Pagespeed” section in the HTTP header, similar to below.

Verifying mod_pagespeed Module

Verifying mod_pagespeed Module

Step 5: Turning the Module On and Off

If you don’t want to use mod_pagespeed completely, you can Turn Off by inserting the following line to pagespeed.conf file at the top.

ModPagespeed off

Similarly, to Turn On module, insert the following line to pagespeed.conf file at the top.

ModPagespeed on

As I said above after installing mod_pagespeed our website loads 40%-50% faster. We would really like to know about your website speed after installing it on your systems via comments.

Ravi Saive

Owner at TecMint.com
Simple Word a Computer Geek and Linux Guru who loves to share tricks and tips on Internet. Most Of My Servers runs on Open Source Platform called Linux.
Download Free eBooks
Advanced Bash-Scripting Guide
Linux Bible
A Newbie's Getting Started Guide to Linux
Ubuntu Linux Toolbox: 1000+ Commands

32 Responses

  1. hi,
    I use Apache 2.4.3 and get the error:
    httpd >= 2.2 is needed by mod-pagespeed-beta-1.0.22.7-2003.x86_64
    How to solve it?
    many thanks

    • Ravi Saive says:

      Dear Bien Quang,

      Can you please post me the whole output of the command. so we could rectify it and give you proper steps to install it.

  2. ura soul says:

    this increased the speed of the loads on my site too. :)

    using – http://tools.pingdom.com/fpt/ – the loadtime moved the site from comparitive ranking 33% to 49% in terms of speed of pageload of all those measured by the tool.
    thanks for sharing

  3. Ketam says:

    I have follow this step by step, but here the result:

    http://img525.imageshack.us/img525/8108/failit.png

  4. Omkar says:

    I wasted whole day following Google mod_pagespeed site. It was giving error after error. But within few minutes following your steps now I have enabled mod-pagespeed.

    Thank you very much.

    • jamie says:

      I agree with Omkar, i use Red Hat and on googles page didn’t even tell me i could run pagespeed. Your page was fast and easy a little out dated since I just installed pagespeed 1.6.29.4-3289. But it worked and was easy to set up.

  5. copernic says:

    already install no problem
    check at httpd -M pagespeed_module loaded
    but…
    i can’t see HTTP Header Information
    how i can see this Information ?

  6. AcidRaZor says:

    I installed Varnish (port 80) and Apache (port 8080) with PageSpeed.

    However when my sites render, it renders: websitename.com:8080/js/jsentity.js etc

    I have my own custom code written (WordPress like situation) and each time it sees “websitename.com:8080″ it assumes its a different website and refuses to load the dynamic code.

    How can I get pagespeed to just go with port 80 all the time since varnish is listening on port 80 and apache doing the gruntwork in the background?

  7. raj says:

    How do i flush the cache, I have tried a number of commands but the old images are still being display. also the css old

  8. Paulo Silva says:

    I have installed this module but you have forget to say that we need to restart the apache server to see it work.
    For my bad luck this don’t work with my Linode Vps, with apache, php with suphp and Kloxo .
    It break down all my sites.

    • Ravi Saive says:

      Please read carefully, I have mentioned in the article about Apache restart. Sorry, to heard, but i don’t think it will break down any sites, if it’s not working for you, simple remove it. or you can post output of phpinfo here. let me check…

      • Paulo Silva says:

        Sorry it was very late and i was tired and you say that we have to restart ;)

        The Http Header section don’t show up in my phpinfo, neither the apache section.

        I have uninstall the module page speed and install it again, but the result is the same, all my online stores break down.

        I edit the pagespeed.conf and turn module to off and everything work fine, but if turn on again my sites break down with erros.

        In Google Chrome:
        THIS PAGE CONTAINS THE FOLLOWING ERRORS:
        error on line 103 at column 9: Opening and ending tag mismatch: img line 0 and div
        BELOW IS A RENDERING OF THE PAGE UP TO THE FIRST ERROR.

        In Firefox
        XML Parsing Error: mismatched tag. Expected: .
        Location: http://houseofireland.exadra37.com/en/
        Line Number 99, Column 5:
        —-^

        Opera
        Works like a charm

        How can it be possible ???

  9. Rajesh S says:

    Very nice article. Thanks..worked perfectly for me

  10. Shahil says:

    Sir ,

    i am able to found mod_pagespeed in phpinfo page, But while I am unable to find its configuration file (pagespeed.conf) for ON and off .

  11. Shahil says:

    @ Ravi Sir,

    Sorry I got it .

  12. Tierno Bah says:

    Yum installed mod_pagespeed correctly in the first two locations:

    – /etc/cron.daily/mod-pagespeed
    – /etc/httpd/conf.d/pagespeed.conf

    But if failed to do so in the other three locations:

    – /usr/lib/httpd/modules/mod_pagespeed.so
    – /var/www/mod_pagespeed/cache
    – /var/www/mod_pagespeed/files

    Also my info.php doesn’t display mod_pagespeed under HTTP Response Headers.
    It just shows: X-Powered-By PHP/5.5.4

    I did restart Apache after installing the module.

    TIA

  13. devendra says:

    Hi,

    Please share How to compile mod_pagespeed + Apache with source.

    Devendra

  14. subrata says:

    Hello Sir,

    This installed mod-pagespeed-beta-1.8.31.2-3973.x86_64 ,but in your repo its written stable ,no way to install Stable?

  15. sanjay n says:

    I have installed mod page speed Customized module from the bellow reference link on whm centos 5 ,32 bit with Apache 2.2.67.

    http://forums.cpanel.net/f402/install-mod_pagespeed-cpanel-using-easyapache-302431.html

    But now page speed module giving a warning ” ModPagespeed Generated File Prefix is deprecated please remove configuration”

    so i want to remove that configuration of custom module.

    if any body have any idea how to remove it let me know.

    i was try bellow command but it is not working for me

    sudo yum remove mod-pagespeed-stable

    when i open file using command nano /etc/httpd/conf.d/pagespeed.conf to add the mad page speed filters its show this error

    [ Error writing /etc/httpd/conf.d/pagespeed.conf: No such file or directory ]

    so that i want remove this custom page speed module.

    last out put through command on putty

    httpd -t -D DUMP_MODULES | grep pagespeed
    [Thu Aug 21 04:04:51 2014] [warn] ModPagespeedGeneratedFilePrefix is deprecated. Please remove it from your configuration.
    Syntax OK
    pagespeed_module (shared)

  16. Shyamal says:

    Hello Sir, your steps are 100% working and improved our website’s page loading time impressively. Thank you so much…

  17. snh says:

    We cannot install – because dependency error (I have read somewhere because httpd is in a custom location) – but how can we fix this?

    (I also see this exact question was one of the first in 2012 – but without an answer)

    yum –enablerepo=mod-pagespeed install mod-pagespeed
    Loaded plugins: downloadonly, fastestmirror
    Loading mirror speeds from cached hostfile
    * base: http://ftp.nluug.nl
    * epel: http://ftp.nluug.nl
    * extras: http://ftp.nluug.nl
    * updates: http://ftp.nluug.nl
    Setting up Install Process
    Resolving Dependencies
    –> Running transaction check
    —> Package mod-pagespeed-beta.x86_64 0:1.8.31.4-4009 will be installed
    –> Processing Dependency: httpd >= 2.2 for package: mod-pagespeed-beta-1.8.31.4-4009.x86_64
    –> Finished Dependency Resolution
    Error: Package: mod-pagespeed-beta-1.8.31.4-4009.x86_64 (mod-pagespeed)
    Requires: httpd >= 2.2
    You could try using –skip-broken to work around the problem
    You could try running: rpm -Va –nofiles –nodigest

    • Ravi Saive says:

      Sorry for troble, but the fact is, article is little outdated and we haven’t updated yet. After seeing the error, I suggest you to upgrade your httpd version to latest and then give a try. I hope it will work for you this way.. or else wait for the updated article, we are in the process to publish updated one soon..

  18. Sarovar says:

    I have installed it – and it installed without errors using yum.

    Running this:
    httpd -t -D DUMP_MODULES | grep pagespeed

    Outputs:
    pagespeed_module (shared)

    But pagespeed doesn’t show up in phpinfo();

    I am running Apache 2.4 and PHP 5.5. What could be the problem?

  19. Thanks for the help.But yesterday i have spent an hour to install mod_pagespeed using article at https://developers.google.com/speed/pagespeed/module/build_mod_pagespeed_from_source.
    But what is the difference between your’s article and googles article

    • Ravi Saive says:

      The difference is the article at tecmint is little older and haven’t we updated yet…and the link you followed at Google has latest instructions..

  20. i have done all the things you said but when i go to localhost.com/phpinfo.php it is showing a 404 error not found.Instead i used full php configuration in zpanel but i didn’t found X-Mod-Pagespeed what to do?

Leave a Reply

This work is licensed under a (cc) BY-NC | TecMint uses cookies. By using our services, you comply to use of our cookies. More info: Privacy Policy.
© 2012-2014 All Rights Reserved.