ScaleScaleScaleScale

Tips / Nginx


How to install mod_pagespeed on cPanel servers

Mod_Pagespeed is an open source web performance module designed to work with Apache and Nginx servers. This excellent tool has been out for a few years now, but it wasn’t until last year that it became stable enough to start using it on cPanel servers.

For anyone who’s interested in web performance, this module is a must. It helps automate the optimization process for HTML, CSS, Javascript, JPG, GIF and PNG files. It can also reduce the weight of static files, compress the code, and enable an aggressive cache to ensure users are served at max speed from your local network.

Main mod_pagespeed optimization filters

  • Image optimization, compression and resizing
  • Deferred loading of JavaScript and images
  • CSS & JavaScript minification, concatenation and inlining
  • Cache extension, domain sharding, and domain rewriting

Before starting this mod_pagespeed tutorial, it’s important to watch the introductory video below. This will show you how mod_pagespeed works. It will also give you a series of best practices and examples you can apply to your websites.

Now that you have an idea of what the module is and how it can help, let’s go over the technical stuff.

Installing mod_pagespeed on cPanel servers

Login to your shell terminal as root, then use git to clone the installation script into your cPanel server.

/usr/local/cpanel/3rdparty/bin/git clone https://github.com/pagespeed/cpanel.git /tmp/pagespeed

Next step: Create the Speed.pm.tar.gz file, necessary for the pagespeed compilation.

Move to your tmp folder, untar and move speed.pm into EasyApache custom modules directory.

cd /tmp/pagespeed/Easy
tar -zcvf Speed.pm.tar.gz pagespeed
mkdir -p /var/cpanel/easy/apache/custom_opt_mods/Cpanel/Easy
mv Speed.pm Speed.pm.tar.gz -t /var/cpanel/easy/apache/custom_opt_mods/Cpanel/Easy/
cd && rm -rf /tmp/pagespeed

Login into your WHM > EasyApache interface and take a look at the mod_pageseed section. You should be able to start running the EasyApache process with mod_pagespeed enabled from WHM panel. Otherwise you can always run /scripts/easyapache from commmand line, which is usually more stable than the browser version. Configure PHP and Apache server as you wish and then restart http server to apply the changes:

/etc/init.d/httpd restart

At this point you should have mod_pagespeed up and running on your cPanel server.

How can I Configure mod_pagespeed for cPanel?

EasyApache installation helps install the mod_pagespeed module with basic configurations. When compiling, you may need to tune up your mod_pagespeed configuration to fit your needs. You can find the default pagespeed.conf file at /usr/local/apache/conf/ on your cPanel server.

/usr/local/apache/conf/pagespeed.conf

Here’s a basic configuration example:

LoadModule pagespeed_module modules/mod_pagespeedi_ap24.so


    ModPagespeed on
ModPagespeedFetchWithGzip on
SetOutputFilter DEFLATE

    AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html

ModPagespeedFileCachePath            "/var/mod_pagespeed/cache/"
ModPagespeedGeneratedFilePrefix      "/var/mod_pagespeed/files/"
                                                                                                                                                                        
ModPagespeedRewriteLevel PassThrough

ModPagespeedFileCacheSizeKb          102400
ModPagespeedFileCacheCleanIntervalMs 3600000
ModPagespeedLRUCacheKbPerProcess     1024
ModPagespeedLRUCacheByteLimit        16384
ModPagespeedCssInlineMaxBytes        2048
ModPagespeedImageInlineMaxBytes      2048
ModPagespeedCssImageInlineMaxBytes   2048
ModPagespeedJsInlineMaxBytes         2048
ModPagespeedCssOutlineMinBytes       3000
ModPagespeedJsOutlineMinBytes        3000

ModPagespeedEnableFilters extend_cache,combine_css,move_css_to_head,rewrite_javascript,rewrite_images,add_head,rewrite_css,collapse_whitespace,remove_comments,remove_quotes,sprite_images,convert_meta_tags
ModPagespeedRespectVary on

    
          SetHandler mod_pagespeed_beacon
    

    
        Order allow,deny
        Allow from localhost
        Allow from 127.0.0.1
        SetHandler mod_pagespeed_statistics
    

    ModPagespeedMessageBufferSize 100000
    
        Allow from localhost
        Allow from 127.0.0.1
        SetHandler mod_pagespeed_message
    
    
        Allow from localhost
        Allow from 127.0.0.1
        SetHandler mod_pagespeed_referer_statistics
    

[Read more about configuring Mod_Pagespeed]

How to test if mod_pagespeed is working

It’s easy! Just run a curl command against your website. For example:

curl -I http://www.yourwebsite.com

Which should show you something like this:

HTTP/1.1 200 OK
Date: Sat, 31 Jan 2014 06:58:03 GMT
Server: Apache
X-Mod-Pagespeed: 1.9.32.2-4321
Cache-Control: max-age=0, no-cache
Vary: Accept-Encoding
Connection: close
Content-Type: text/html

If mod_pagespeed for cPanel is working, you should see the “X-Mod-Pagespeed” version loaded in your web page headers.

As you see, mod_pagespeed is a wonderful addition to the performance toolkits that every developer should have. It can automate a large number of optimization techniques so you can have a better code (css & javascript minification) and have as few http requests as possible. It also adds smart caching to all the static content you have.

As web performance is becoming more and more important every day, you should never forget about this great piece of software from Google.

Want to learn more? Read more about mod_pagespeed in these places:

Have you tried mod_pagespeed? What are your impressions and thoughts? Did it improve your web performance? Let us know in the comments section below.

 

Popular search terms:

  • configure pagespeed cpanel
  • enable gzip compression
  • how to find if pagespeed is installed on my shared server
  • how to install mod_pagespeed in cpanel server
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking

  • Hi,

    Thank you so much for this great tutorial. You are life saver. Your tutorial helped me to install memcached, Varnish and Google Mode PageSpeed.

    Memcached Successfully installed and running.
    Vanish Installed but I was enable to tune up Port
    Google Mode PageSpeed Installed but access to config filed denied. However, the Page speed is running and server speed is double and server response time reduced to half. Currently the Page speed has default setting on my server.