Proudly Hosting over 100,000 Fast Websites since 2010

How can we help you?

Type your topic or keywords and hit enter to search our knowledgebase.

How to install mod_pagespeed in cPanel?

Created by Google, mod_pagespeed is “an open-source Apache module which automatically applies web performance best practices to pages, and associated assets (CSS, JavaScript, images) without requiring that you modify your existing content or workflow.”

This guide assumes you are using cPanel / WHM with EasyApache 4 and have root access to the server.

Create a file called ‘/etc/rpm/macros.apache2’

nano /etc/rpm/macros.apache2

Now, paste the below contents into that file and save it.

%_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

Once the file is saved, login to your WHM and go to EasyApache4, click on ‘Customize’ button present on the selected ‘Currently Installed Packages’.

There select the second option Apache Modules, you have to install two modules viz mod_http2 and mod_version after that click on next until you reach to the ‘Review’ option and click on ‘Provision’ button. It will install both the selected modules.

After that run the below commands to complete the installation:

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

yum install rpm-build

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

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

This will install the mod_pagespeed module in easyapache4.

Once the mod_pagespeed is installed again login to WHM>>EasyApache4>>Customize>>Apache Modules and search for mod_pagespeed and install it then go to review option and provision it.

Then restart the apache service

/etc/init.d/httpd restart

That is it, mod_pagespeed should now be working on your server. You can check using the following command:

curl -I localhost

HTTP/1.1 200 OK
Date: Thu, 28 Jun 2018 13:20:14 GMT
Server: Apache
Upgrade: h2,h2c
Connection: Upgrade
Accept-Ranges: bytes
X-Mod-Pagespeed: 1.13.35.2-0
Vary: Accept-Encoding
Cache-Control: max-age=0, no-cache
Content-Length: 111
Content-Type: text/html

If you have a managed hosting service with us you can request us to install mod_pagespeed on your server.

Updated on February 10, 2024