This is our on going series on Apache optimization and performance tuning, here we are introducing a new Google‘s product called mod_pagespeed module for Apache or Nginx that makes the web site load much faster than ever.
I have personally tested this module on our Live (tecmint.com) server and results are amazing, now the site loads much faster than before. I recommend you all to install it and see the results.
Don’t Miss: 5 Tips to Boost the Performance of Your Apache Web Server
In this article we will show you how to install and configure Google‘s mod_pagespeed module for Apache and Nginx web servers in RHEL/CentOS/Fedora and Debian/Ubuntu systems using official binary packages, so that your system will get regular updates automatically and stays up to date.
What Is Mod_PageSpeed
mod_pagespeed is an open source module for Apache and Nginx web server that automatically optimize Web Pages to improve better performance while serving web pages using HTTP Server.
It has several filters that automatically optimize files like HTML, CSS, JavaScript, JPEG, PNG and other resources.
mod_pagespeed is developed on PageSpeed Optimization Libraries, deployed over 100K+ websites, and provided by most popular CDN and Hosting providers such as GoDaddy, EdgeCast, DreamHost and few to name.
It offers more than 40+ optimization filters, which includes:
- Image optimization, compression, and resizing
- CSS & JavaScript concatenation, minification, and inlining
- Cache extension, domain sharding and rewriting
- Deferred loading of JS and image resources
- and many others…
Currently mod_pagespeed module supported Linux platforms are RHEL/CentOS/Fedora and Debian/Ubuntu for 32 bit and 64 bit distributions.
Installing Mod_Pagespeed Module in Linux
As I discussed above that we are using Google‘s official binary packages to install it for future updates, so let’s go ahead and install it on your systems based on your OS architecture.
On RHEL/CentOS and Fedora
----------- On 32-bit Systems ----------------- # wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.rpm # yum install at [# if you don't already have 'at' installed] # rpm -Uvh mod-pagespeed-stable_current_i386.rpm ----------- On 64-bit Systems ----------------- # wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm # yum install at [# if you don't already have 'at' installed] # rpm -Uvh mod-pagespeed-stable_current_x86_64.rpm
On Debian and Ubuntu
----------- On 32-bit Systems ----------------- $ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.deb $ sudo dpkg -i mod-pagespeed-stable_current_i386.deb $ sudo apt-get -f install ----------- On 64-bit Systems ----------------- $ wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb $ sudo dpkg -i mod-pagespeed-stable_current_amd64.deb $ sudo apt-get -f install
Installing mod_pagespeed from binary packages will add a Google’s official repository to your system, so that you can update the mod_pagespeed automatically using package manager called yum or apt.
What Mode_Pagespeed is Installed
Let’s see what packages mod_pagespeed installed on the system:
- It will install two modules, mod_pagespeed.so for Apache 2.2 and mod_pagespeed_ap24.so for Apache 2.4.
- It will install two main configuration files: pagespeed.conf and pagespeed_libraries.conf (for Debian pagespeed.load). If you change one of these configuration files, you will no longer receive future updates automatically.
- A standalone JavaScript minifier pagespeed_js_minify used to minify JS and create metadata for library canonicalization.
About Mod_Pagespeed Configuration and Directories
The module enables following configuration files and directories itself automatically during installation.
- /etc/cron.daily/mod-pagespeed : mod_pagespeed cron script for checking and installing latest updates.
- /etc/httpd/conf.d/pagespeed.conf : The main configuration file for Apache in RPM based distributions.
- /etc/apache2/mods-enabled/pagespeed.conf : The main configuration file for Apache2 in DEB based distributions.
- pagespeed_libraries.conf : The default set of libraries for Apache, loads at Apache startup.
- /usr/lib{lib64}/httpd/modules/mod_pagespeed.so : mod_pagespeed module for Apache.
- /var/cache/mod_pagespeed : File caching directory for web sites.
Important: In Nginx the configuration files of mod_pagespeed typically found under /usr/local/nginx/conf/ directory.
Configuring Mod_Pagespeed Module
In Apache, mod_pagespeed automatically Turn On when installed, while in Nginx you need to place following lines to your nginx.conf file and in every server block where PageSpeed is enabled:
pagespeed on; # Needs to exist and be writable by nginx. Use tmpfs for best performance. pagespeed FileCachePath /var/ngx_pagespeed_cache; # Ensure requests for pagespeed optimized resources go to the pagespeed handler # and no extraneous headers get set. location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; } location ~ "^/pagespeed_static/" { } location ~ "^/ngx_pagespeed_beacon$" { }
Finally, don’t forget to restart your Apache or Nginx server to start mod_pagespeed working properly.
Step 4: Verifying Mod_Pagespeed Module
To verify mod_pagespeed module, we will use curl command to test in on domain or IP as shown:
# curl -D- http://192.168.0.15/ | less
Apache
HTTP/1.1 200 OK Date: Fri, 04 Mar 2016 07:37:57 GMT Server: Apache/2.4.6 (CentOS) PHP/5.4.16 ... X-Mod-Pagespeed: 1.9.32.13-0 ---
Nginx
HTTP/1.1 200 OK Date: Fri, 04 Mar 2016 07:37:57 GMT Server: nginx/1.4.0 ... X-Page-Speed: 1.5.27.1-2845 ...
If you don’t see an X-Mod-Pagespeed header, that means mod_pagespeed isn’t actually installed.
Step 5: Turning the Module On and Off
If you don’t want to use mod_pagespeed completely, you can Turn Off by inserting the following line to pagespeed.conf file at the top.
ModPagespeed off
Similarly, to Turn On module, insert the following line to pagespeed.conf file at the top.
ModPagespeed on
As I said above after installing mod_pagespeed our website loads 40%-50% faster. We would really like to know about your website speed after installing it on your systems via comments.
For more details about configuration, you can check out the official mod_pagespeed page at https://developers.google.com/speed/pagespeed/module/.
Hi, I have an issue. I am running CentOS Web Panel on CentOS 8 with Apache 2.4.46 installed but whenever I try to install this apache module, I always get this error:
I’m pretty sure I have Apache running if not my WordPress website will not work :D
Here’s my Apache version:
Server version: Apache/2.4.46 (Unix)
Any ideas?
Ngx_Pagespeed and Mod_PageSpeed both are same or different? can i configure both module in one nginx webserver? what is the differences between Ngx_Pagespeed and Mod_PageSpeed? can any one explain me?
@Khushal,
There’s nothing big different between Ngx_Pagespeed and Mod_PageSpeed, both are same, but Ngx_Pagespeed is for Nginx webserver and Mod_PageSpeed user for Apache web server.
But Mod_pageSpeed is also available for Nginx. As i have search out on google
@Khushal,
Yes, but its highly recommended that you should use Ngx_Pagespeed for Nginx web server..
Oky thanks for your advice. Can you just tell how to use proxy pass in nginx or suggest me any URL for nginx to advance performance tuning or configuration
Check this article – The Ultimate Guide to Secure, Harden and Improve Performance of Nginx Web Server
Hi Ravi, Good article but I have complied apache2.4 and installed at production. In above doc, you only mentioned installation for rpm. How can Mod_Pagespeed be integrated with complied apache? Can you help to understand?
Nginx doesn’t load modules dynamically, they must be compiled in. I can’t believe you have tested this method on nginx.
I am trying to install pagespeed on the server for my domain. Apparently, after speaking with the tech people at Telus WebHosting (Apache server), I can install it in the .htaccess file in the “public” folder.
I have downloaded the
.deb
file for pagespeed, but I have NO IDEA how to actually get it installed in the .htaccess file. Can someone tell me, step by step, how I go about getting it installed on the server.Thank you.
@Dougg,
You can install
.deb
pagespeed package using the following command.Thank you Ravi.
Now, my question is this, when I go to my .htaccess file on the remote server, and type in
$ sudo dpkg -i mod-pagespeed-stable_current_amd64.deb
, is that all I have to do?? Or, is there something else that is needed in order for pagespeed to be installed and work on the server?Do I actually have to have the 6.9MB
.deb
file on the server as well??Your comments are much appreciated.
Thanks
Doug
@Doug,
Yes, you just need to install the mod_pagespeed
.deb
package on the Linux machine, thats it.Thanks again Ravi.
What I am trying to get at is this: HOW do I install pagespeed on the remote server?? My websites are located on Telus. Do I simply paste the information below into my (public directory) .htaccess file?
Will this install pagespeed on the Linux server?? I have tried to copy and paste the above information into my .htaccess file, but when I try to open my website in a browser I get a 500 error. Without that information, my websites open up fine.
What I really need is some ‘detailed’ information on how to get pagespeed installed correctly on the LInux server.
Thank you for you assistance.
@Doug,
Firstly, .htaccess is a configuration file for managing rewrite rules, this file not used to install software on Linux. To install mod_pagespeed you must have a SSH access to a remote server and execute these commands in the terminal.
Error : httpd >= 2.2 is needed by mod-pagespeed-stable-1.11.33.4-0.x86_64
Why would I install Apache when my website is running on Nginx???
@Yazir,
Strange problem, I think you’ve not installed Nginx using standard format.
@Ravi I am a little confused, why people start talking about this old server plugin again. It’s optimizing a little bit. See we optimized all those pagespeed rules set by Google in our self developed cms. We couldn’t optimize to 100/100 without using a lot of node.js solutions, image compression services, hosting of analytics, maps and youtube js files.
Do people think it requires just mod_pagespeed to solve all issues? they must be dreaming LOL
@Andre,
This plugin is not at all old and in fact Google suggesting this tool to check and optimize sites according suggestions given by this tool.. This tool is just an example, there are other well known plugins like WP-Cache, WP-Super-Cache, WP-Rocket, etc.. you can use any of them to optimize sites..
we have it already. But I need to know how it effects the unoptimized pagespeed score.
this is our tripple 100 result https://developers.google.com/speed/pagespeed/insights/?url=bluecreator-cms.de
@Andre,
What do you mean by unoptimized pagespeed score? could you explain me more? what you exactly looking for? without mod_pagespeed module, site loading will take time as the content (html,css,js.png,jpg etc.) not optimized and will take time to load, but with mod_pagespeed installed, you can call your all content in an optimized form thus increase in speed..
What this article lacks are…. Proof (statistics, number etc…) something better than ‘google use it as example in some (un-)maintained page’ or ‘yeah it improves x10 timez!’
Install it. You’ll have all the proof you need.
What are the changes in results of pagespeed insights test?
@Andre,
Do a pagespeed test at https://developers.google.com/speed/pagespeed/ and see the difference after and before installing mod_pagespeed..
Hi Ravi,
I am facing some issue mod pagespeed. I have installed nginx via rpm and version is
Name : nginx
Arch : x86_64
Version : 1.0.15
can i install in my server …?
@Inderpal,
There isn’t any problem with nginx version, you can install mod_pagespeed on any nginx or apache version..
When installing packages I almost always use yum install (package name) in this way I get all dependencies also included into the install
Hello Ravi!
Thanks for this but ran into an issue. I get the following error:
# rpm -Uvh mod-pagespeed-stable_current_x86_64.rpm
warning: mod-pagespeed-stable_current_x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 7fac5991: NOKEY
error: Failed dependencies:
httpd >= 2.2 is needed by mod-pagespeed-stable-1.9.32.13-0.x86_64
Centos 6.7
# httpd -v
Server version: Apache/2.4.18
# nginx -v
nginx version: nginx/1.8.0
@Scott,
Have you installed
'at'
package? if yes, then it could be other reason like how did you installed Apache? and mod_pagespeed is asking for httpd >= 2.2, but seems not installed on the system. Could you run the following command and check what it gives output?yum install at
Thank you, Ravi for sharing this info..
Just curious to know what if I’ve latest version of Apache e.g 2.4.18 does this module still supports ?? OS – RHEL 6.0
@Satish,
Thanks for finding my article useful, yes it’s do supports Apache 2.2 and Apache 2.4 as stated in the article..
@Ravi,
Thanks for this valuable post. But seems mod_pagespeed module need to be add nginx while build from source, No dynamic module available for nginx like Apache.
Is your post nginx ?
@Venkat,
Thanks for finding this post valuable, yes you need to add mod_pagespeed module to nginx configuration manually as stated in the article, this article supports both Apache and Nginx, but while installing mod_pagespeed the module auto loaded into Apache, whereas in nginx you need to add manually..
You can follow the guide made by the rtcamp folks to install a version of nginx that already has the module.
Hi, I have installed mod_pagespeed on Centos 7, but if I seek in phpinfo.php not find it. Help me please. Thank you.
@AlbertM,
Have you restarted Apache after installing mod_pagespeed on CentOS 7?
thanks for learning
but i got this error:
# rpm -ivh mod-pagespeed-stable_current_x86_64.rpm
error: Failed dependencies:
httpd >= 2.2 is needed by mod-pagespeed-stable-1.9.32.4-7251.x86_64
my apache version is:
# httpd -v
Server version: Apache/2.2.31 (Unix)
@Reza,
On which version of Linux distribution you’re trying?
Hi Ravi, I got the same. I’ve Centos 6
Thank Ravi Saive so much. I installed in CentOS :)
Hi,
I have installed mod_pagespeed on ubuntu. But could not configure admin console. Please provide me the steps to configure to pagespeed admin console.
Regards,
Krishnaprasad PB
@Krishna,
Surely, will update the article with admin configuration..give a day or two to update the howto…
i have done all the things you said but when i go to localhost.com/phpinfo.php it is showing a 404 error not found.Instead i used full php configuration in zpanel but i didn’t found X-Mod-Pagespeed what to do?
Thanks for the help.But yesterday i have spent an hour to install mod_pagespeed using article at https://developers.google.com/speed/pagespeed/module/build_mod_pagespeed_from_source.
But what is the difference between your’s article and googles article
The difference is the article at tecmint is little older and haven’t we updated yet…and the link you followed at Google has latest instructions..
I have installed it – and it installed without errors using yum.
Running this:
httpd -t -D DUMP_MODULES | grep pagespeed
Outputs:
pagespeed_module (shared)
But pagespeed doesn’t show up in phpinfo();
I am running Apache 2.4 and PHP 5.5. What could be the problem?
We cannot install – because dependency error (I have read somewhere because httpd is in a custom location) – but how can we fix this?
(I also see this exact question was one of the first in 2012 – but without an answer)
yum –enablerepo=mod-pagespeed install mod-pagespeed
Loaded plugins: downloadonly, fastestmirror
Loading mirror speeds from cached hostfile
* base: http://ftp.nluug.nl
* epel: http://ftp.nluug.nl
* extras: http://ftp.nluug.nl
* updates: http://ftp.nluug.nl
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package mod-pagespeed-beta.x86_64 0:1.8.31.4-4009 will be installed
–> Processing Dependency: httpd >= 2.2 for package: mod-pagespeed-beta-1.8.31.4-4009.x86_64
–> Finished Dependency Resolution
Error: Package: mod-pagespeed-beta-1.8.31.4-4009.x86_64 (mod-pagespeed)
Requires: httpd >= 2.2
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest
Sorry for troble, but the fact is, article is little outdated and we haven’t updated yet. After seeing the error, I suggest you to upgrade your httpd version to latest and then give a try. I hope it will work for you this way.. or else wait for the updated article, we are in the process to publish updated one soon..
Hello Sir, your steps are 100% working and improved our website’s page loading time impressively. Thank you so much…
That’s great, your website speed is improved much…
I have installed mod page speed Customized module from the bellow reference link on whm centos 5 ,32 bit with Apache 2.2.67.
http://forums.cpanel.net/f402/install-mod_pagespeed-cpanel-using-easyapache-302431.html
But now page speed module giving a warning ” ModPagespeed Generated File Prefix is deprecated please remove configuration”
so i want to remove that configuration of custom module.
if any body have any idea how to remove it let me know.
i was try bellow command but it is not working for me
sudo yum remove mod-pagespeed-stable
when i open file using command nano /etc/httpd/conf.d/pagespeed.conf to add the mad page speed filters its show this error
[ Error writing /etc/httpd/conf.d/pagespeed.conf: No such file or directory ]
so that i want remove this custom page speed module.
last out put through command on putty
httpd -t -D DUMP_MODULES | grep pagespeed
[Thu Aug 21 04:04:51 2014] [warn] ModPagespeedGeneratedFilePrefix is deprecated. Please remove it from your configuration.
Syntax OK
pagespeed_module (shared)
Hello Sir,
This installed mod-pagespeed-beta-1.8.31.2-3973.x86_64 ,but in your repo its written stable ,no way to install Stable?
Hi,
Please share How to compile mod_pagespeed + Apache with source.
Devendra
Yum installed mod_pagespeed correctly in the first two locations:
– /etc/cron.daily/mod-pagespeed
– /etc/httpd/conf.d/pagespeed.conf
But if failed to do so in the other three locations:
– /usr/lib/httpd/modules/mod_pagespeed.so
– /var/www/mod_pagespeed/cache
– /var/www/mod_pagespeed/files
Also my info.php doesn’t display mod_pagespeed under HTTP Response Headers.
It just shows: X-Powered-By PHP/5.5.4
I did restart Apache after installing the module.
TIA
@ Ravi Sir,
Sorry I got it .
Sir ,
i am able to found mod_pagespeed in phpinfo page, But while I am unable to find its configuration file (pagespeed.conf) for ON and off .
Very nice article. Thanks..worked perfectly for me
I have installed this module but you have forget to say that we need to restart the apache server to see it work.
For my bad luck this don’t work with my Linode Vps, with apache, php with suphp and Kloxo .
It break down all my sites.
Please read carefully, I have mentioned in the article about Apache restart. Sorry, to heard, but i don’t think it will break down any sites, if it’s not working for you, simple remove it. or you can post output of phpinfo here. let me check…
Sorry it was very late and i was tired and you say that we have to restart ;)
The Http Header section don’t show up in my phpinfo, neither the apache section.
I have uninstall the module page speed and install it again, but the result is the same, all my online stores break down.
I edit the pagespeed.conf and turn module to off and everything work fine, but if turn on again my sites break down with erros.
In Google Chrome:
THIS PAGE CONTAINS THE FOLLOWING ERRORS:
error on line 103 at column 9: Opening and ending tag mismatch: img line 0 and div
BELOW IS A RENDERING OF THE PAGE UP TO THE FIRST ERROR.
In Firefox
XML Parsing Error: mismatched tag. Expected: .
Location: http://houseofireland.exadra37.com/en/
Line Number 99, Column 5:
—-^
Opera
Works like a charm
How can it be possible ???
How do i flush the cache, I have tried a number of commands but the old images are still being display. also the css old
I installed Varnish (port 80) and Apache (port 8080) with PageSpeed.
However when my sites render, it renders: websitename.com:8080/js/jsentity.js etc
I have my own custom code written (WordPress like situation) and each time it sees “websitename.com:8080” it assumes its a different website and refuses to load the dynamic code.
How can I get pagespeed to just go with port 80 all the time since varnish is listening on port 80 and apache doing the gruntwork in the background?
already install no problem
check at httpd -M pagespeed_module loaded
but…
i can’t see HTTP Header Information
how i can see this Information ?
You can use online tools to check HTTP headers..
I wasted whole day following Google mod_pagespeed site. It was giving error after error. But within few minutes following your steps now I have enabled mod-pagespeed.
Thank you very much.
I agree with Omkar, i use Red Hat and on googles page didn’t even tell me i could run pagespeed. Your page was fast and easy a little out dated since I just installed pagespeed 1.6.29.4-3289. But it worked and was easy to set up.
I have follow this step by step, but here the result:
http://img525.imageshack.us/img525/8108/failit.png
@Ketam
Please give me the output of the following command.
If you get “pagespeed_module (shared)”, message, it means that modpagespeed is working properly.
Ya, I get the message:
Syntax OK
pagespeed_module (shared)
So no more further setting needed?
Yes! no more settings needed, but if you want to control more settings and configuration see the https://developers.google.com/speed/docs/mod_pagespeed/download.
Thanks so much! :)
this increased the speed of the loads on my site too. :)
using – http://tools.pingdom.com/fpt/ – the loadtime moved the site from comparitive ranking 33% to 49% in terms of speed of pageload of all those measured by the tool.
thanks for sharing
hi,
I use Apache 2.4.3 and get the error:
httpd >= 2.2 is needed by mod-pagespeed-beta-1.0.22.7-2003.x86_64
How to solve it?
many thanks
Dear Bien Quang,
Can you please post me the whole output of the command. so we could rectify it and give you proper steps to install it.