Let’s jump straight into it:
* Update – The script here mod_pagespeed module for cPanel WHM has been updated to work with Apache 2.4.* since I wrote this article. I would recommend recompiling apache using WHM and the script as it would be easier than using this method. *
- Build Apache 2.4.6 using cPanel WHM on CentOS 6.4
- Installing the latest mod_pagespeed on Apache 2.4.6
- Upgrading mod_pagespeed on Apache 2.4.6
*Before you start get excited and start following this guide, you must have root access to your server*
So, here is my first attempt at a walkthrough of any kind. I am new to all this linux stuff, so it took me 2 or 3 days worth of work figuring all of this out. There was no simple guide to achieving all of this in one spot, so I thought I would gather everything I figured out in the process and post it here Hopefully you have stumbled across this and it helps you out!
I originally wanted to install mod_pagespeed on Apache 2.2.25, but you can’t just simply install the prebuilt RPM’s from Google if your Apache was built using cPanel WHM. You get this error:
Missing Dependency: httpd >= 2.2 is needed by package mod-pagespeed…
I then attempted to compile the RPM myself using the instructions on google and when I started running into dependency issues, etc, I realised how “out of my depth” I was.
I finally came across mod_pagespeed module for cPanel WHM. Compiling Apache and including this script worked a treat and I finally had mod_pagespeed working nicely… You think I would be happy there, but I just can’t help but tweak things.
While going down this path, I realised I could actually install Apache 2.4.6 using this same method. I thought I would give it a shot, even though the old adage goes “If it ain’t broke, don’t fix it” rings loudly in my head. I’ll never learn my lesson.
I tried rebuilding Apache to 2.4.6 with the mod_pagespeed script above, to no avail. I got this error:
Syntax error on line 2 of /usr/local/apache/conf/pagespeed.conf: Cannot load modules/mod_pagespeed.so into server: /usr/local/apache/modules/mod_pagespeed.so: undefined symbol: unixd_config
According to bugs submitted with that script, people have been having the same problem.
Now I had to figure out a way to install Apache and mod_pagespeed afterwards. Fortunately I figured out a way and here I am now Usually I can’t be bothered writing guides on what I did, but after the agony I went through with this one, I wouldn’t want you to go through the same!
As is usual for these kinds of things, use this guide at your own risk, I take no responsibility in any way. At a pretty good guess, I reckon this guide would work for x386/32 bit systems, but obviously would recquire some tweaking. Also, I installed the stable mod_pagespeed here, but it would probably work with the beta mod_pagespeed too, albeit with some more tweaking
The guide is quite lengthy, but I think it is the easiest way to install it all. I have tried to cover everything in as much depth as I can. If you were to go down the compiling path, then you would need to install a whole heap of rpm’s and run into dependency issues, etc. and it can get pretty messy.
Build Apache 2.4.6 using cPanel WHM on CentOS 6.4
Please have a quick look over Upgrading to 2.4 from 2.2 at apache.org and Critical changes in Apache 2.4 at the cPanel.net site before upgrading to check for any possible issues that may arise from upgrading. I haven’t run into any issues as yet, but I run pretty standard web applications.
*Before performing any functions like these make sure you have working backups first, you just never know*
Goto WHM > Software > EasyApache
Follow the prompts, configuring the server as you want it. The screens are fairly self explanatory. If you have built Apache in the past using the mod_pagespeed by Prajith, make sure it is unchecked this time round. Go along to the exhaustive options list and check the Deflate and Version options, these are required by mod_pagespeed.
Now, go ahead and rebuild it and go have a breather; It takes awhile. If you have any problems, a google search usually produces good results. EasyApache Known Issues at cPanel.net provides solutions to some common building problems.
Installing mod_deflate and/or mod_version on Apache 2.4.6
If you have already installed Apache 2.4.6, but don’t have mod_deflate or mod_version installed, don’t fret, these are easy to install.
If you followed the last step, don’t worry about this, as you will already have these installed so you can skip this one. Even if you do follow these steps, though, I don’t think it would do any harm
All credits to Aparna Murthy for writing How to Install Mod_Pagespeed on Centos+cPanel ?Without this guide, I wouldn’t have mod_pagespeed installed.
It is as easy as running these commands on the command line on your server as root via SSH or other means. If you don’t understand what this means, then I probably wouldn’t attempt any of this and get someone who does to do it for you. If you are keen to figure out how everything works and want to do it yourself, like myself, there are plenty of resources out there for you to learn.
Install mod_deflate: *One line*
/usr/local/apache/bin/apxs -c -i /home/cpeasyapache/src/httpd-2.4/modules/filters/mod_deflate.c
Install mod_version: *One line*
/usr/local/apache/bin/apxs -c -i /home/cpeasyapache/src/httpd-2.4/modules/metadata/mod_version.c
Installing the latest mod_pagespeed on Apache 2.4.6
Once again, all credits to Aparna Murthy for writing How to Install Mod_Pagespeed on Centos+cPanel ?
I will try and keep this short and sweet.
Using the command line as root, go to our working directory:
Create the directory mod_pagespeed:
Next, we will download the stable .RPM of mod_pagespeed. Thanks to wget we can do this automatically:
Then unpack the .RPM:
rpm2cpio mod-pagespeed-stable_current_x86_64.rpm | cpio -idmv
You should see these files unpack:
./etc/cron.daily/mod-pagespeed - Can't use this under this install
./etc/httpd/conf.d/pagespeed.conf - Can use this as standalone. Refer Google documents
Let’s start copying the files into their correct spots: *One line each*
cp /usr/local/src/mod_pagespeed/usr/lib64/httpd/modules/mod_pagespeed.so /usr/local/apache/modules/
cp /usr/local/src/mod_pagespeed/usr/lib64/httpd/modules/mod_pagespeed_ap24.so /usr/local/apache/modules/
cp /usr/local/src/mod_pagespeed/etc/httpd/conf.d/pagespeed.conf /usr/local/apache/conf/
cp /usr/local/src/mod_pagespeed/etc/httpd/conf.d/pagespeed_libraries.conf /usr/local/apache/conf/
Set permissions on files:
chmod 755 /usr/local/apache/modules/mod_pagespeed.so
chmod 755 /usr/local/apache/modules/mod_pagespeed_ap24.so
Make directories for cache and set ownership:
mkdir /var/mod_pagespeed/ -p
chown nobody:nobody /var/mod_pagespeed/*
We must edit the mod_pagespeed configuration file to reflect the correct paths of the files:
# Attempt to load mod_version if it wasn't loaded or compiled in (eg on Debian)
LoadModule version_module /usr/local/apache/modules/mod_version.so
<IfVersion < 2.4>
LoadModule pagespeed_module /usr/local/apache/modules/mod_pagespeed.so
<IfVersion >= 2.4.2>
LoadModule pagespeed_module /usr/local/apache/modules/mod_pagespeed_ap24.so
# Only attempt to load mod_deflate if it hasn't been loaded already.
LoadModule deflate_module /usr/local/apache/modules/mod_deflate.so
Also modify this line:
* Note: If you built apache using WHM and not manually, the .so files for mod_deflate and mod_version won’t exist. It should work, but if you are concerned, go back and install install mod_deflate and/or mod_version as per my instructions *
Add this line to our /usr/local/apache/conf/httpd.conf file:
To keep the changes permanent after a cPanel update:
Restart apache and voila!:
service httpd restart
If everything goes to plan, apache will startup normally and as your server gets traffic, you will see your cache being written to /var/mod_pagespeed/*. I hope it went smoothly for you. If you run into any problems, leave a comment and I will get back to you. I’m no expert, but I picked a few things along the way Also, if this helped you please let me know, Thanks!
Upgrading mod_pagespeed on Apache 2.4.6
PS. Regarding upgrades; As far as I know it is not possible to upgrade mod_pagespeed automatically using this method, but hey, at least it is installed. I couldn’t even get it installed using other methods. To upgrade, you would just need to run through these instructions again. If you are like me, you will keep an eye on the latest versions of stuff anyway and won’t let a new release slip by un-noticed