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:

sudo yum install mod-pagespeed

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:

 vim /etc/yum.repos.d/google-mode-pagespeed.repo

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

[google-mod-pagespeed]
name=google-mod-pagespeed
baseurl=http://dl.google.com/linux/mod-pagespeed/rpm/stable/$basearch
enabled=1
gpgcheck=0

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

sudo yum install mod-pagespeed

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

service httpd restart

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:

ModPagespeedEnableFilters prioritize_critical_css
ModPagespeedEnableFilters defer_javascript
ModPagespeedEnableFilters sprite_images
ModPagespeedEnableFilters rewrite_images
ModPagespeedEnableFilters recompress_png
ModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webp
ModPagespeedEnableFilters collapse_whitespace,remove_comments

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 

yum erase mod-pagespeed
rm /etc/yum.repos.d/google-mode-pagespeed.repo

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: 

sudo touch /var/cache/mod_pagespeed/cache.flush
service httpd restart

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

4 responses

  1. hi when you say parallels. do you mean plesk? if so does this work with version 12.5 that is now under odin? Also do you have to make sure that your site is setup to not use nginx at all? if so how would you do that in plesk? thanks.

    1. Yes i mean Plesk. This was done on version 12.5 under odin. The site was set up to mainly use apache even though nginx is installed on the server

  2. hi when you say parallels. do you mean plesk? if so does this work with version 12.5 that is now under odin? Also do you have to make sure that your site is setup to not use nginx at all? if so how would you do that in plesk? thanks.

    1. Yes i mean Plesk. This was done on version 12.5 under odin. The site was set up to mainly use apache even though nginx is installed on the server

Leave a Reply