I bumped into Kristian Markroft from Simplyroot in New Orleans last week, and he told me about an interesting speed-up module for the Apache Webserver.
mod_pagespeed is an open source project which speeds up page loads without having to change the code of the actual page. mod_pagespeed does this by adding filters before pages are served. For example it will resize images and minify CSS/JS files, which can speed up page load considerably. The project is hosted on Google Code:
Let’s see how we can install it on CentOS, test to see if it works and how to manage it in Plesk.
The easiest way to install the module is by pulling the pre-built packages via yum from Google. For this we need to add a new source for yum to access. This source only contains the mod_pagespeed module, none of your other packages will be affected (even when you casually yum update your server).
Let’s add it by creating the following file:
Add the following code block to it:
[google-mod-pagespeed] name=google-mod-pagespeed baseurl=http://dl.google.com/linux/mod-pagespeed/rpm/stable/$basearch enabled=1 gpgcheck=0
In case you’re not familiar with vi: hit a to enter edit mode, paste your code, hit escape followed by shift-Z-Z to save and exit.
Now we can install the module:
yum install mod-pagespeed ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mod-pagespeed-beta x86_64 18.104.22.168-3721 google-mod-pagespeed 5.0 M Installing for dependencies: at x86_64 3.1.10-43.el6_2.1 base 60 k Transaction Summary ================================================================================ Install 2 Package(s) Total download size: 5.0 M Installed size: 13 M Is this ok [y/N]: y Downloading Packages: (1/2): at-3.1.10-43.el6_2.1.x86_64.rpm | 60 kB 00:00 (2/2): mod-pagespeed-beta-22.214.171.124-3721.x86_64.rpm | 5.0 MB 00:01 -------------------------------------------------------------------------------- Total 2.4 MB/s | 5.0 MB 00:02 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : at-3.1.10-43.el6_2.1.x86_64 1/2 Installing : mod-pagespeed-beta-126.96.36.199-3721.x86_64 2/2 Starting atd: [ OK ] job 1 at 2014-03-04 10:16 Verifying : at-3.1.10-43.el6_2.1.x86_64 1/2 Verifying : mod-pagespeed-beta-188.8.131.52-3721.x86_64 2/2 Installed: mod-pagespeed-beta.x86_64 0:184.108.40.206-3721 Dependency Installed: at.x86_64 0:3.1.10-43.el6_2.1 Complete!
Nice. Now restart Apache for the changes to take effect:
service httpd restart
Thanks to Rahul Kumar for explaining this procedure here: http://tecadmin.net/installing-mod_pagespeed-module-apache/
Verify that mod_pagewrite is working
The easiest way to do this is not from a web browser but from the command line. We’ll load a website and inspect the header information:
curl -D- http://example.com | head -10 TP/1.1 200 OK Server: nginx Date: Tue, 04 Mar 2014 14:20:41 GMT Content-Type: text/html; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Vary: Cookie,Accept-Encoding X-Pingback: http://example.com/xmlrpc.php X-Mod-Pagespeed: 220.127.116.11-3721
The last line tells us that mod_pagespeed was indeed involved and is working fine. Needless to say, please replace example.com with the website you’d like to test.
If yo’d like to turn the module off or on again, and you’re using Plesk, it’s as simple as (un-)ticking a box: head over to Tools and Settings (or Server if you’re using Power User View), click Apache Modules and find two new modules in the large list:
- pagespeed (ticked after installation)
The latter is for Apache 2.4 which will only start if you actually have Apache 2.4 installed. If you’re running Apache 2.2 then the first module is for you and you’ll receive an error message should you try to start the other one.
If you are not using Plesk, or you prefer a more “bare bones command line” approach you can tweak the mod_pagespeed configuration file which lives in /etc/httpd/conf.d/pagespeed.conf:
vi /etc/httpd/conf.d/pagespeed.conf <IfModule pagespeed_module> # Turn on mod_pagespeed. To completely disable mod_pagespeed, you # can set this to "off". ModPagespeed on ...
Simply change that line to ModPagespeed off, save the file and restart Apache.
To remove the module completely, erase the package and remove the extra yum source:
yum erase mod-pagespeed rm /etc/yum.repos.d/google-mode-pagespeed.repo
It’s like it never happened