Pagespeed or mod_pagespeed is an open source module used in apache & is used to speed up the websites. It applies various layers of filters to all the associated assets like pages, style-sheets, images etc, which than helps in optimizing the assets & this leads to boost in speed of the website. The best part of using pagespeed is that, no changes modifications/changes are required to the current existing content. So changes are done at the server side & users accessing the website are presented with the modified content.
Recommended Read: Create a free Apache SSL certificate with Let’s Encrypt on CentOS & RHEL
Also Read: Block Web traffic in Apache server using .htaccess
Now in this tutorial we will be installing mod_pagespeed module on Ubuntu & CentOS/RHEL. Let's start with the pre-requisites,we will discuss the installation o
Pre-requisites
We need to have Apache web-server installed on our machines. To install apache on CentOS/RHEL, run
$ yum install httpd
Also, we need the package 'at' for CentOS like os, so install that as well if not already installed,
$ yum install at
For Ubuntu, run
$ sudo apt-get install apache2
We now have our web server ready, you can put some files or a complete website. Once you are ready, we can proceed with the page speed setup,
Installing Mod_pageSpeed on CentOS/RHEL/Fedora
Before installing mod_pagespeed module, we will download it's package as per your system architecture,
For 64 Bit OS, use the following command
$ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
For 32 but OS, use
$ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.rpm
Now install the downloaded package with the command, (64 bit in my case)
$ rpm -ivh mod-pagespeed-stable_current_x86_64.rpm
That's it, PageSpeed module has been installed & it will be activated on its own. We just need to restart the webserver to implement the changes.
$ service httpd restart
Installing mod_pagespeed on Ubuntu
Installating mod_pagespeed module on Ubuntu is similar to above mentioned procedure for CentOS, we will download the packages,
For 64 Bit,
$ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
For 32 Bit,
$ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.deb
& install the downloaded package,
$ dpkg -i mod-pagespeed-stable_current_amd64.deb
$ sudo apt-get -f install
Now restart the webserver to implment the changes,
$ sudo service apache2 restart
Configuration
After installing mod_pagespeed module, we will now configure it our servers. Main configuration file is named 'pagespeed.conf' & its location is '/etc/httpd/conf.d/pagespeed.conf' for CentOS/RHEL & '/etc/apache2/mods-available' for Ubuntu.
Open the file & firstly enable the module (its enabled by default),
$ vi pagespeed.conf
ModPagespeed on
To turn-off the module, use 'off' in place on 'on' . You can then also enable core filters to allow pagespeed module to rewrite the files. To enable corefilters create the following entry at the bottom of pagespeed.conf,
ModPagespeedRewriteLevel CoreFilters
ModPagespeedAllow "http://*test-domain.com/*.html"
ModPagespeedAllow "http://*test-domain.com/*.css"
ModPagespeedAllow "http://*test-domain.com/*.js"
ModPagespeedAllow "http://*test-domain.com/*.png"
PageSpeed will now rewrite the files with extensions .html, .css, .js, & .png. You can also disallow filters using “ModPagespeedDisallow” parameter. After making the changes to the file, save file & exit. Then restart your webserver to implement the changes.
This completes the tutorial, please do share your valuable feedbacks or queries, if any using the comment box below.
If you think we have helped you or just want to support us, please consider these :-
Connect to us: Facebook | Twitter | Google Plus
Become a Supporter - Donate us some of you hard earned money: [paypal-donation]
Linux TechLab is thankful for your continued support.