Install Google Mod_PageSpeed on cPanel + EasyApache 4

Pagespeed Insights is one of the Google’s projects to make the web faster. Along with that cool tool to measure website speed, they also publish the famous mod_pagespeed, an HTTP module for Apache and Nginx, used to accelerate and optimize any website.

install modpagespeed cpanel easyapache4

ModPagespeed can be installed in cPanel servers also, and fully integrated using EasyApache 4 on WHM.  But before showing the practical part of this tutorial, let’s first find out what are the main benefits of using mod_pagespeed:

  • Automatic website optimization.
  • Combine and minify CSS and Javascript code.
  • Image optimization, compression, and resizing.
  • Lazy load images.
  • Caching, domain sharding, and domain rewriting.
  • Move CSS above the scripts.
  • Move CSS to the document head.

How can I install ModPageSpeed on cPanel + EasyApache 4?

Simply follow the next steps for CentOS based servers:

Create the macros.apache2 file and add this content inside:

nano -w /etc/rpm/macros.apache2

Then paste this inside:

%_httpd_mmn 20120211x8664
%_httpd_apxs /usr/bin/apxs
%_httpd_dir /etc/apache2
%_httpd_bindir %{_httpd_dir}/bin
%_httpd_modconfdir %{_httpd_dir}/conf.modules.d
%_httpd_confdir %{_httpd_dir}/conf.d
%_httpd_contentdir /usr/share/apache2
%_httpd_moddir /usr/lib64/apache2/modules

Save the file and exit.

Install rpm-build package, along with some other modules required for the post EA4 compilation

yum install rpm-build cpio ea-apache24-mod_version

Download the mod_pagespeed latest stable version

wget https://github.com/apache/incubator-pagespeed-cpanel/raw/master/EA4/ea-apache24-mod_pagespeed-latest-stable.src.rpm

Build the mod_pagespeed module

rpmbuild --rebuild ea-apache24-mod_pagespeed-latest-stable.src.rpm

Install Pagespeed module

rpm -ivh /root/rpmbuild/RPMS/x86_64/ea-apache24-mod_pagespeed*.rpm

Restart Apache

/etc/init.d/httpd restart

Move to WHM control panel > Software > EasyApache 4.

Click on mod_pagespeed to enable it as you see below:

WHM EasyApache Mod_Pagespeed

Complete the process to have Mod_Pagespeed installed on your server.

Configure mod_pagespeed

This will have your mod_security installed, but that doesn’t mean it is fully configured to make your websites faster. In fact, there are tons of mod_pagespeed rules that you will need to apply to have the maximum possible performance.

The installation process will create a pagespeed.conf file located at this two possible paths:

  • /usr/local/apache/conf/
  • /etc/apache2/conf.modules.d

Refer to the official mod_pagespeed for further configuration and variables to use.

About the Author: Martin Keler

1 Comment

  1. I’ve followed the procedure but when I customize my EA4 profile, the mod_pagespeed is already enabled. I just can’t find the pagespeed.conf file anywhere.

    Any ideas? How do I know if mod_pagespeed is effective?

    Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *