Google PageSpeed module, now Apache PageSpeed module works from the server side to perform a lot of work easier avoiding WordPress plugins or PHP snippets. The good thing is that it is free and offers a ton of features. The bad thing about the Apache PageSpeed module is that the result is inconsistent and sometimes hurt the page loading speed. It does not hurt to test this module’s support to convert to webp images, particularly if you are using an Apache HTTP server.
All guides on this website on server administration are for the Debian/Ubuntu users and this is not an exception. We assume that you have an Apache web server with WordPress running as a web application. Install the Mod PageSpeed WordPress plugin to have the control over purging the cache of PageSpeed from the WordPress admin.
Steps to Install Apache PageSpeed
It is tricky to install Mod PageSpeed:
---
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | apt update && apt upgrade -y apt install wget apt-transport-https gnupg2 -y ## doc : https://www.modpagespeed.com/doc/download wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb dpkg -i mod-pagespeed-*.deb apt-get -f install ls -al rm mod-pagespeed-stable_current_amd64.deb # touch /etc/default/mod-pagespeed ## install the required modules which matches with your PHP version php -v # apt install imagemagick php7.2-imagick ffmpeg # apt install imagemagick php7.4-imagick ffmpeg # apt install imagemagick php8.0-imagick ffmpeg # apt install imagemagick php8.1-imagick ffmpeg |
Comment out this file:
1 | nano /etc/apt/sources.list.d/mod-pagespeed.list |
You have to manually update the package since there are odd issues with the signature. Enable the module if already not enabled:
1 | a2enmod pagespeed |
Navigate to /etc/apache2/sites-available/ and run an ls -al :
1 2 | cd /etc/apache2/sites-available/ ls -al |
There will be your virtual host config file for the HTTPS site. Within virtual host scope, add :
1 2 | ModPagespeedFetchHttps enable ModPagespeedRespectXForwardedProto on |
Run a config test and gracefully reload:
1 2 | apachectl configtest /etc/init.d/apache2 reload |
These are third-party modules and always restart, reload, start, and stop Apache via /etc/init.d/apache2
command
when you are using them else you may face this ${APACHE_RUN_DIR} is not defined error. Avoid using service apache2 restart
command with these modules.
One of our readers had issues with modsecurity module.
Steps to Configure Apache PageSpeed
Open the settings file:
1 | nano /etc/apache2/mods-available/pagespeed.conf |
Our present discussion is about enabling these filters:
1 2 3 | ... ModPagespeedEnableFilters collapse_whitespace,elide_attributes,convert_jpeg_to_webp,convert_to_webp_lossless,convert_to_webp_animated ... |
You’ll get the documentation here: https://www.modpagespeed.com/doc/reference-image-optimize
.