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 ( 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
# yum install at   [# if you don't already have 'at' installed]
# rpm -Uvh mod-pagespeed-stable_current_i386.rpm

----------- On 64-bit Systems -----------------
# wget
# 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
$ sudo dpkg -i mod-pagespeed-stable_current_i386.deb
$ sudo apt-get -f install

----------- On 64-bit Systems -----------------
$ wget
$ 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, for Apache 2.2 and 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 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- | less
HTTP/1.1 200 OK
Date: Fri, 04 Mar 2016 07:37:57 GMT
Server: Apache/2.4.6 (CentOS) PHP/5.4.16
HTTP/1.1 200 OK
Date: Fri, 04 Mar 2016 07:37:57 GMT
Server: nginx/1.4.0

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

Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

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

  1. Hi, I have an issue. I am running CentOS Web Panel on CentOS 8 with Apache 2.4.46 installed but whenever I try to install this apache module, I always get this error:

    error: Failed dependencies:
            httpd >= 2.2 is needed by mod-pagespeed-stable-

    I’m pretty sure I have Apache running if not my WordPress website will not work :D

    Here’s my Apache version:

    Server version: Apache/2.4.46 (Unix)

    Any ideas?

  2. Ngx_Pagespeed and Mod_PageSpeed both are same or different? can i configure both module in one nginx webserver? what is the differences between Ngx_Pagespeed and Mod_PageSpeed? can any one explain me?

  3. Hi Ravi, Good article but I have complied apache2.4 and installed at production. In above doc, you only mentioned installation for rpm. How can Mod_Pagespeed be integrated with complied apache? Can you help to understand?

  4. Nginx doesn’t load modules dynamically, they must be compiled in. I can’t believe you have tested this method on nginx.

  5. I am trying to install pagespeed on the server for my domain. Apparently, after speaking with the tech people at Telus WebHosting (Apache server), I can install it in the .htaccess file in the “public” folder.

    I have downloaded the .deb file for pagespeed, but I have NO IDEA how to actually get it installed in the .htaccess file. Can someone tell me, step by step, how I go about getting it installed on the server.

    Thank you.

      • Thank you Ravi.

        Now, my question is this, when I go to my .htaccess file on the remote server, and type in $ sudo dpkg -i mod-pagespeed-stable_current_amd64.deb, is that all I have to do?? Or, is there something else that is needed in order for pagespeed to be installed and work on the server?

        Do I actually have to have the 6.9MB .deb file on the server as well??

        Your comments are much appreciated.


          • Thanks again Ravi.

            What I am trying to get at is this: HOW do I install pagespeed on the remote server?? My websites are located on Telus. Do I simply paste the information below into my (public directory) .htaccess file?

            $ wget
            $ sudo dpkg -i mod-pagespeed-stable_current_amd64.deb
            $ sudo apt-get -f install

            Will this install pagespeed on the Linux server?? I have tried to copy and paste the above information into my .htaccess file, but when I try to open my website in a browser I get a 500 error. Without that information, my websites open up fine.

            What I really need is some ‘detailed’ information on how to get pagespeed installed correctly on the LInux server.
            Thank you for you assistance.

          • @Doug,

            Firstly, .htaccess is a configuration file for managing rewrite rules, this file not used to install software on Linux. To install mod_pagespeed you must have a SSH access to a remote server and execute these commands in the terminal.

  6. Error : httpd >= 2.2 is needed by mod-pagespeed-stable-

    Why would I install Apache when my website is running on Nginx???

  7. @Ravi I am a little confused, why people start talking about this old server plugin again. It’s optimizing a little bit. See we optimized all those pagespeed rules set by Google in our self developed cms. We couldn’t optimize to 100/100 without using a lot of node.js solutions, image compression services, hosting of analytics, maps and youtube js files.

    Do people think it requires just mod_pagespeed to solve all issues? they must be dreaming LOL

    • @Andre,

      This plugin is not at all old and in fact Google suggesting this tool to check and optimize sites according suggestions given by this tool.. This tool is just an example, there are other well known plugins like WP-Cache, WP-Super-Cache, WP-Rocket, etc.. you can use any of them to optimize sites..

    • @Andre,

      What do you mean by unoptimized pagespeed score? could you explain me more? what you exactly looking for? without mod_pagespeed module, site loading will take time as the content (html,css,js.png,jpg etc.) not optimized and will take time to load, but with mod_pagespeed installed, you can call your all content in an optimized form thus increase in speed..


Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.