How-to: mod_pagespeed for apache

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
10,628
Location
LT, EU
Due to some requests that people find it difficult to install mod_pagespeed, I'm just writing a guide for now :) As DirectAdmin does not use RPM for Apache, and mod_pagespeed provides 'source installation' packages only for nginx, it creates difficulties for some end-customers. However, it's not as hard to install it.

Guide for CentOS.

We download RPM and extract it:
Code:
mkdir -p /root/mod_pagespeed
cd /root/mod_pagespeed
wget -O mod-pagespeed-stable_current_x86_64.rpm https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
rpm2cpio mod-pagespeed-stable_current_x86_64.rpm| cpio -idmv

Now we just move files to appropriate places:
Code:
mv -f ./etc/httpd/conf.d/pagespeed.conf /etc/httpd/conf/extra/pagespeed.conf
mv -f ./etc/httpd/conf.d/pagespeed_libraries.conf /etc/httpd/conf/extra/pagespeed_libraries.conf
mv -f ./usr/bin/pagespeed_js_minify /usr/bin/pagespeed_js_minify
mv -f ./usr/lib64/httpd/modules/mod_pagespeed_ap24.so /usr/lib/apache/mod_pagespeed_ap24.so
mkdir -p /var/cache/mod_pagespeed
mkdir -p /var/log/pagespeed

Replace '/usr/lib64/httpd/modules/' path to '/usr/lib/apache/' in /etc/httpd/conf/extra/pagespeed.conf:
Code:
perl -pi -e 's|/usr/lib64/httpd/modules/|/usr/lib/apache/|g' /etc/httpd/conf/extra/pagespeed.conf

And include pagespeed.conf and pagespeed_libraries.conf to be loaded, just edit /etc/httpd/conf/extra/httpd-includes.conf, and add these lines:
Code:
Include /etc/httpd/conf/extra/pagespeed.conf
Include /etc/httpd/conf/extra/pagespeed_libraries.conf

Restart apache now:
Code:
service httpd restart
 
f264J

Thanks so much for the tips.
Do we need to make any further settings in Apache/website once this is install on the server? Or it works out of the box?
 
f264J

Thanks so much for the tips.
Do we need to make any further settings in Apache/website once this is install on the server? Or it works out of the box?

It's work out of the box, you just need to edit .htaccess or pagespeed.conf for any of directives and filters you want to optimize your site.

example I did for my website on .htaccess

Code:
<IfModule pagespeed_module>
  ModPagespeed on
  ModPagespeedRewriteLevel CoreFilters
  ModPagespeedEnableFilters add_head,remove_quotes,combine_javascript,rewrite_images,insert_dns_prefetch,defer_javascript
  ModPagespeedEnableFilters rewrite_css,fallback_rewrite_css_urls
  ModPagespeedEnableFilters sprite_images,collapse_whitespace,dedup_inlined_images,inline_preview_images,resize_mobile_images,rewrite_javascript,responsive_images,resize_images,convert_jpeg_to_progressive,prioritize_critical_css,trim_urls
  ModPagespeedEnableFilters convert_gif_to_png,recompress_png,convert_png_to_jpeg,convert_jpeg_to_progressive,recompress_jpeg,convert_jpeg_to_webp,convert_to_webp_lossless,convert_to_webp_animated,recompress_webp

  ModPagespeedEnableFilters lazyload_images
  ModpagespeedLazyloadImagesAfterOnload off
  ModpagespeedCriticalImagesBeaconEnabled false
  ModpagespeedLazyloadImagesBlankUrl "https://www.gstatic.com/psa/static/1.gif"
  ModPagespeedEnableFilters inline_google_font_css
  ModPagespeedGoogleFontCssInlineMaxBytes 1024
  ModPagespeedCssInlineMaxBytes 1024

  ModPagespeedEnableFilters local_storage_cache
</IfModule>
 
shame me that i see this tread now, smtalk thank you for this handy guide
 
Bit confuse What if we use it with NGINX + Apache? or do we also need to install ngx_pagespeed with directadmin
 
@VMH-Khan

No, you don't need it, the apache one is work very well and easy to manage filter via .htaccess. This is I preferred and surly customer is preferred.
 
Hi,
i follow the steps but its not working i can not see pagespeed in phpinfo() page
Due to some requests that people find it difficult to install mod_pagespeed, I'm just writing a guide for now :) As DirectAdmin does not use RPM for Apache, and mod_pagespeed provides 'source installation' packages only for nginx, it creates difficulties for some end-customers. However, it's not as hard to install it.

Guide for CentOS.

We download RPM and extract it:
Code:
mkdir -p /root/mod_pagespeed
cd /root/mod_pagespeed
wget -O mod-pagespeed-stable_current_x86_64.rpm https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
rpm2cpio mod-pagespeed-stable_current_x86_64.rpm| cpio -idmv

Now we just move files to appropriate places:
Code:
mv -f ./etc/httpd/conf.d/pagespeed.conf /etc/httpd/conf/extra/pagespeed.conf
mv -f ./etc/httpd/conf.d/pagespeed_libraries.conf /etc/httpd/conf/extra/pagespeed_libraries.conf
mv -f ./usr/bin/pagespeed_js_minify /usr/bin/pagespeed_js_minify
mv -f ./usr/lib64/httpd/modules/mod_pagespeed_ap24.so /usr/lib/apache/mod_pagespeed_ap24.so
mkdir -p /var/cache/mod_pagespeed
mkdir -p /var/log/pagespeed

Replace '/usr/lib64/httpd/modules/' path to '/usr/lib/apache/' in /etc/httpd/conf/extra/pagespeed.conf:
Code:
perl -pi -e 's|/usr/lib64/httpd/modules/|/usr/lib/apache/|g' /etc/httpd/conf/extra/pagespeed.conf

And include pagespeed.conf and pagespeed_libraries.conf to be loaded, just edit /etc/httpd/conf/extra/httpd-includes.conf, and add these lines:
Code:
Include /etc/httpd/conf/extra/pagespeed.conf
Include /etc/httpd/conf/extra/pagespeed_libraries.conf

Restart apache now:
Code:
service httpd restart
 
Ok does pagespeed work with php-fpm and How would i enable gzip compression
 
@Amit,

You can add this code in your .htaccess file

Apache config:
<IfModule pagespeed_module>
    ModPagespeed off
</IfModule>
 
Hi,
In "SERVER_IP/pagespeed_admin/cache#show_metadata" when i add website URL, it shows this:
cache_ok:false
can_revalidate:false
what can i do to solve this ?
 
My apache error logs is filling with Mod page speed failed to make directory please help.
 
How would I verify if mod_ruid2 is installed or not. And what is advantage of using it. As per my understanding it does not allow php scripts to modify the folder outside of its containing folder?
 
Back
Top