Install mod_pagespeed (Website Optimizer) for Apache in CentOS

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.

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


RHEL/CentOS/Fedora 64-Bit


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

    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.

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.