About this article
Introduction One of the more recently popular modules for Apache is mod_pagespeed. It is an output filter for Apache 2.2+ that can be configured through a variety of options through configuration files or a .htaccess file. An “output filter” is a something that transforms the data before it’s sent to the client. In other words, it’s a layer between your website and what the user’s browser receives when they visit your URL. Speed Up the Web The goal of mod_pagespeed is to speed up your website. It does this by applying filters to a variety of files in order to reduce the number of trips the browser has to make to grab what it needs, to reduce the size of those files and to optimize the length those files are cached. Installation Installation is very simple. It’ll vary depending on the operating system you use. Ubuntu and Debian have packages you can download and install (or any Linux distribution that uses .DEB packages). Other Linux distributions can download the source and build from that.
1 – Download Software
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.debCode language: Bash (bash)
2 – Install pagespeed
sudo dpkg -i mod-pagespeed-*.deb apt-get -f install rm mod-pagespeed-*.debCode language: Bash (bash)
service apache2 restart <strong>or</strong> /etc/init.d/apache2 restartCode language: Bash (bash)
You should now have a working version of mod_pagespeed up and running on your VPS. You can check this by looking at your page’s response headers. There should be a value for “X-Mod-Pagespeed” with the version number you installed. Setup The installation package handles a lot of configuration out-of-the-box. In fact, there are conservative defaults that are automatically enabled on Apache. Depending on the Apache version you’re running, you’ll get a different version of the module installed and enabled. If you’re running Apache 2.2, mod_pagespeed.so will be installed; Apache 2.4 users will use mod_pagespeed_ap24.so. Note: mod_pagespeed only works with Apache 2.2 and greater. There is also a bug with Apache 2.4.1 that prevents it from working with that version. Apache 2.4.2 or greater should be used. Additionally, configuration files have been added to your Apache installation. The primary configuration file is pagespeed.conf. This file is located at: /etc/apache2/mods-available/ How to configure mod_pagespeed You can use whatever text editor you want to edit the configuration file. For this tutorial, we’ll be using nano. To start editing the main configuration file, use the following command:
pico /etc/apache2/mods-available/pagespeed.confCode language: Bash (bash)
If for some reason you want to disable pagespeed you can run this command and restart apache2:
sudo a2dismod pagespeed systemctl restart apache2Code language: Bash (bash)
Here is the output
Module pagespeed disabled.
To activate the new configuration, you need to run:
systemctl restart apache2