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

0

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

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.

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.