Install Mod_Pagespeed to Speed Up Apache and Nginx Performance Upto 10x

This is our on going series on Apache optimization and performance tuning, here we are introducing a new Google‘s product called mod_pagespeed module for Apache or Nginx that makes the web site load much faster than ever.

Install Mod_Pagespeed for Apache and Nginx
Install Mod_Pagespeed for Apache and Nginx

I have personally tested this module on our Live (tecmint.com) server and results are amazing, now the site loads much faster than before. I recommend you all to install it and see the results.

Don’t Miss: 5 Tips to Boost the Performance of Your Apache Web Server

In this article we will show you how to install and configure Google‘s mod_pagespeed module for Apache and Nginx web servers in RHEL/CentOS/Fedora and Debian/Ubuntu systems using official binary packages, so that your system will get regular updates automatically and stays up to date.

What Is Mod_PageSpeed

mod_pagespeed is an open source module for Apache and Nginx web server that automatically optimize Web Pages to improve better performance while serving web pages using HTTP Server.

It has several filters that automatically optimize files like HTML, CSS, JavaScript, JPEG, PNG and other resources.

mod_pagespeed is developed on PageSpeed Optimization Libraries, deployed over 100K+ websites, and provided by most popular CDN and Hosting providers such as GoDaddy, EdgeCast, DreamHost and few to name.

It offers more than 40+ optimization filters, which includes:

  1. Image optimization, compression, and resizing
  2. CSS & JavaScript concatenation, minification, and inlining
  3. Cache extension, domain sharding and rewriting
  4. Deferred loading of JS and image resources
  5. and many others…

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 and Nginx on RHEL/CentOS/Fedora and Debian/Ubuntu

Installing Mod_Pagespeed Module in Linux

As I discussed above that we are using Google‘s official binary packages to install it for future updates, so let’s go ahead and install it on your systems based on your OS architecture.

On RHEL/CentOS and Fedora

----------- On 32-bit Systems -----------------
# wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.rpm
# yum install at   [# if you don't already have 'at' installed]
# rpm -Uvh mod-pagespeed-stable_current_i386.rpm

----------- On 64-bit Systems -----------------
# wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
# yum install at   [# if you don't already have 'at' installed]
# rpm -Uvh mod-pagespeed-stable_current_x86_64.rpm

On Debian and Ubuntu

----------- On 32-bit Systems -----------------
$ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.deb
$ sudo dpkg -i mod-pagespeed-stable_current_i386.deb
$ sudo apt-get -f install

----------- On 64-bit Systems -----------------
$ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
$ sudo dpkg -i mod-pagespeed-stable_current_amd64.deb
$ sudo apt-get -f install

Installing mod_pagespeed from binary packages will add a Google’s official repository to your system, so that you can update the mod_pagespeed automatically using package manager called yum or apt.

What Mode_Pagespeed is Installed

Let’s see what packages mod_pagespeed installed on the system:

  1. It will install two modules, mod_pagespeed.so for Apache 2.2 and mod_pagespeed_ap24.so for Apache 2.4.
  2. It will install two main configuration files: pagespeed.conf and pagespeed_libraries.conf (for Debian pagespeed.load). If you change one of these configuration files, you will no longer receive future updates automatically.
  3. A standalone JavaScript minifier pagespeed_js_minify used to minify JS and create metadata for library canonicalization.

About Mod_Pagespeed Configuration and Directories

The module enables following configuration files and directories itself automatically during installation.

  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 in RPM based distributions.
  3. /etc/apache2/mods-enabled/pagespeed.conf : The main configuration file for Apache2 in DEB based distributions.
  4. pagespeed_libraries.conf : The default set of libraries for Apache, loads at Apache startup.
  5. /usr/lib{lib64}/httpd/modules/mod_pagespeed.so : mod_pagespeed module for Apache.
  6. /var/cache/mod_pagespeed : File caching directory for web sites.

Important: In Nginx the configuration files of mod_pagespeed typically found under /usr/local/nginx/conf/ directory.

Configuring Mod_Pagespeed Module

In Apache, mod_pagespeed automatically Turn On when installed, while in Nginx you need to place following lines to your nginx.conf file and in every server block where PageSpeed is enabled:

pagespeed on;

# Needs to exist and be writable by nginx.  Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;

# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
  add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }

Finally, don’t forget to restart your Apache or Nginx server to start mod_pagespeed working properly.

Step 4: Verifying Mod_Pagespeed Module

To verify mod_pagespeed module, we will use curl command to test in on domain or IP as shown:

# curl -D- http://192.168.0.15/ | less
Apache
HTTP/1.1 200 OK
Date: Fri, 04 Mar 2016 07:37:57 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
...
X-Mod-Pagespeed: 1.9.32.13-0
---
Nginx
HTTP/1.1 200 OK
Date: Fri, 04 Mar 2016 07:37:57 GMT
Server: nginx/1.4.0
...
X-Page-Speed: 1.5.27.1-2845
...

If you don’t see an X-Mod-Pagespeed header, that means mod_pagespeed isn’t actually installed.

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.

For more details about configuration, you can check out the official mod_pagespeed page at https://developers.google.com/speed/pagespeed/module/.

If you liked this article, then do subscribe to email alerts for Linux tutorials. If you have any questions or doubts? do ask for help in the comments section.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

75 thoughts on “Install Mod_Pagespeed to Speed Up Apache and Nginx Performance Upto 10x”

  1. 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?

    Reply
    • 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..

      Reply
  2. 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?

    Reply
  3. 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

    Reply
    • 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..

      Reply
  4. 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)

    Reply
  5. 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?

    Reply
  6. 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

    Reply

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.