Linux SysAdmin & DevOps

Mod_PageSpeed - easy install using easyapache4 cpanel whm linux server.md

mod_pagespeed - Easy install of mod_pagespeed on a cPanel/WHM server with EasyApache4 (please note that with EasyApache3 you could have just added a custom mode to EasyApache and recompile apache with the new mode).

Since EasyApache4 is strictly based on .rpm packages and there is no precompiled .rpm package for mod_pagespeed, you have to create your own .rpm package. After reading and inspecting a few blog posts I decided to write an article in case others might find as usefull this kind of information.

Step 1) Download mod_pagespeed module from the official github.com repo:

wget https://github.com/pagespeed/cpanel/archive/master.zip

Step 2) Unizp the module

unzip master.zip

Step 3) Enter the EA4 mod_pagespeed folder

cd cpanel-master/EA4

Step 4) Create a file that will take care of the RPM build errors (if you already tried to compile that module according to the instructions from github.com you probably know that RPM build process returns some errors and there is no .rpm package built at the end)

cat > /etc/rpm/macros.apache2 <<EOF
%_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
EOF

Step 5) Build the .rpm package

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

Step 6) Install the .rpm package

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

Step 7) Restart the apache web service

/etc/init.d/httpd restart (CentOS 6.x)
systemctl restart httpd (CentOS 7.x)

Step 8) Configure mod_pagespeed parameters

In order to do that, you have to edit the configuration file which is located at:

/etc/apache2/conf.modules.d/456_pagespeed.conf

Have fun using Google Pagespeed module for Apache 2.4.x on a cPanel/WHM server with EasyApache4!

Note: I haven’t created this from scratch so I cannot assume the entire credit for this tutorial. Some steps were taken or inspired from other blog posts!