How-to: mod_pagespeed for apache

smtalk

Administrator
Staff member
Joined
Aug 22, 2006
Messages
8,331
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
 

xuseronline

Verified User
Joined
Jul 10, 2019
Messages
25
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?
 

anas_xrt

New member
Joined
Aug 5, 2017
Messages
4
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>
 

Active8

Verified User
Joined
Jul 13, 2013
Messages
231
shame me that i see this tread now, smtalk thank you for this handy guide
 

VMH-Khan

Verified User
Joined
Jul 17, 2019
Messages
31
Bit confuse What if we use it with NGINX + Apache? or do we also need to install ngx_pagespeed with directadmin
 

anas_xrt

New member
Joined
Aug 5, 2017
Messages
4
@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.
 
Top