Hero Image

Pagespeed module setup on debian

Install

wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
sudo dpkg -i mod-pagespeed-*.deb && apt-get -f install
service apache2 restart or /etc/init.d/apache2 restart

The primary configuration file is pagespeed.conf. This file is located at:

/etc/apache2/mods-available/

Recommended additional modules

Add the following to the bottom (but inside the <IfModule /> block) of /etc/apache2/mods-available/pagespeed.conf

ModPagespeedRewriteLevel OptimizeForBandwidth
ModPagespeedDomain http://yourdomainhere.co.uk
ModPagespeedEnableFilters responsive_images,resize_images,lazyload_images,convert_jpeg_to_progressive
ModPagespeedEnableFilters combine_css,prioritize_critical_css,rewrite_css,fallback_rewrite_css_urls
ModPagespeedEnableFilters canonicalize_javascript_libraries,rewrite_javascript,defer_javascript
ModPagespeedEnableFilters collapse_whitespace,extend_cache,trim_urls
ModPagespeedForceCaching on
ModPagespeedEnableCachePurge on

ModPagespeedRewriteLevel sets the general configuration level for the Pagespeed Module. CoreFilters is the default value however, more recently the OptimizeForBandwidth setting has proven as effective with less issues across website. More information can be found here

ModPagespeedDomain sets the domain to authorise file changes against i.e. when minifying or compressing images etc this must match the domain serving this content. Multiple ModPagespeedDomain can be defined for multiple domains if your server runs multiple sites.

ModPagespeedEnableFilters defines and activates addition filters for content types to be passed through in addition to a core set of filters defined here. Please refer to the reference section for details about each of the filters above. (Note, you can comma separate multiple filters and break onto multiple lines, redeclaring ModPagespeedEnableFilters each time, for improved readibility).

ModPagespeedForceCaching enforces cache control for resources, for more information see https://developers.google.com/speed/pagespeed/module/filter-cache-extend

ModPagespeedEnableCachePurge is required (set to on) in order to allow for purge requests from the admin screens (defaults to /pagespeed_admin & /pagespeed_global_admin).

Using with WordPress sites as example

The install instructions and configurations will work out of the box for WordPress sites, however, in order to access the admin pages, an exception must be added to your .htaccess file, see the example below:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !pagespeed
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Note: The line RewriteCond %{REQUEST_URI} !pagespeed - this ensures WordPress doesn't try and looking for a page with a slug containing pagespeed, however this will only be preserved if your .htaccess file is readonly as WordPress will refresh this when updating its permalinks. To prevent this you can set the RewriteEngine to off when attempting to access the admin pages within the pagespeed.conf file:

<Location /pagespeed_admin>
    <IfModule mod_rewrite.c>
        RewriteEngine Off
    </IfModule>
</Location>

It's also worth being aware that by default the pagespeed module will be applied across the whole of your WordPress install, including the admin area which can lead to some issues with internal ajax events. To remedy this, add the following to the buttom of the pagespeed.conf file:

<Location /wp-admin/>
    ModPagespeed Off
</Location>

This is disable the pagespeed module for any and all pages (and files) under the /wp-admin directory. Once this has been edited, ensure you run service apache2 restart for the changes to take affect.

Other Related Posts:

Sensu monitoring software on debian

Install Erlang

sudo wget http://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb
sudo dpkg -i erlang-solutions_1.0_all.deb
sudo apt-get update
sudo apt-get -y install erlang-nox

Install RabittMQ

sudo wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.0/rabbitmq-server_3.6.0-1...

Read more

20th Jan 2019