How to install Google PageSpeed in Parallels & CentOS

This quick tutorial will show you how to install Google PageSpeed module on your Parallels + CentOS + Apache installation. For those of you who don’t know what this is, it’s basically a module that will supercharge your site that’s developed by Google. If you are trying to increase your Page Speed score then this might be the secret that you need.

PageSpeed uses “filters” that contain latest optimization techniques like caching, asset optimization, minification etc to optimize the load of your site. The best part is once you have it installed on your server all of your sites will benefit from it. If a site doesn’t work for some reason you can use .htaccess to disable specific filters that cause issues.

You will need SSH access to your server in order to install this. If you are on shared hosting or don’t have access ask your hosting if they can enable it for you (or maybe they can even install PageSpeed 🙂 

Features of mod_pagespeed

By default PageSpeed module will activate:

  • Image Optimization (compress & resize),
  • Caching
  • CSS+JavaScript Minification & Concatenation. 

There are of course other filters that you can enable like removal of HTML comments or Analytics injection etc. Which i will briefly cover as well

Installation on Parallels & CentOS

First things first you will have to ssh to your host. Once you are there do the following and it should work if you already have it in the repo:

if you don’t have it in the repo and you get an error then we will add it ourselves by creating a file and adding the path.

so first creating a new blank file:

then press the letter “i” and paste this in:

then press escape, followed by typing “:wq” and then press enter (wq will save and quit back to terminal). Now let’s try our initial command again

All done! Now let’s restart Apache for things to take effect:

How to test if it’s working

There are multiple ways. The basic one is just to go to your site, click view source code and search for “pagespeed” there should be a few instances of it. The next step is to go to Google Page Speed score and run it again. Your grade should be much higher now. You can further increase it by tweaking the filters.

A few tweaks:

  • /etc/httpd/conf.d/pagespeed.conf : This is going to be your main config file for Apache.

You can open it up with vim (vim /etc/httpd/conf.d/pagespeed.conf), go to the end of the file using “:999” press “i” again and then paste:

Then do escape, followed by “wq” then enter. These above filter tweaks are a good further optimizations that are pretty safe. Google of course has a big list and a summary for what all this does here: https://developers.google.com/speed/pagespeed/module/config_filters

Uninstalling / Disabling

If you want to just disable pagespeed (for example for development since it changes the path of all the css files) then you can do it in the file above. Just change at the top of the file ModPagespeed on to ModPagespeed off and restart the apache. To uninstall just do 

if you want to disable Pagespeed on a specific site you can just add “ModPagespeed off” to your site’s .htaccess

To clear the Page speed cache just do: 

That’s it, let us know how it worked out for you!