How to Install and Configure PageSpeed Module for Apache in Ubuntu Server

There are many factors that can affect the speed of a website, and one of them is the server performance – how fast the server can render the web page and serve it to the browser. While there are many ways to improve the speed of a WordPress site, there are also server tools that can optimize the performance of a server. PageSpeed Module for Apache is one of them.

The PageSpeed module is a module for the Apache web server to optimise web pages, improve performance and apply output filters.


Some of the main features of the PageSpeed module include decreasing load time, the amount of requests and payload size. You can use up to 44 filters to optimize your webpage. Here is what the PageSpeed Module can do:

  • Combine Javascript and CSS. One of the main things that the PageSpeed Module does is combine the Javascript and CSS to fewer files, thus reducing resources requests made to the server.
  • Minify Javascript and CSS. The PageSpeed module removes line breaks, blank spaces and unnecessary comments from Javascript and CSS files.


The above is minified to make this:


The above two files both do the same job, but the second one is smaller in size, hence translates to a fast load time of the site.

  • Javascript Deferred Loading. The loading of Javascript file will be delayed until the web page is loaded. This will make sure that your visitor will see the content first as soon as possible. Do take note that this feature might break your site, depending on the functionality of the Javascript code. When activating this feature, first test your website before making it live.
  • The Pagespeed module comes with a number of rules that it uses to compress and optimize images to reduce the website’s load time. The rules include responsive images, lazyload images and Inline preview which shows a low quality of images.


The following commands install the PageSpeed module in Ubuntu. Do note that this is for Apache, which mean your server need to be running Apache. If you are using Nginx, you have to build from source.

If you are using a 32-bit OS, run this command:


Run this command for a 64-bit OS:



The above commands download the package. These commands unpack and install it.

sudo dpkg -i mod-pagespeed-*.deb
sudo apt-get -f install

Installing PageSpeed adds Google’s repository to the system, so it will auto-update itself on every system update. We can verify the installation by running the command below and you will get the output shown:

curl -D- | head



The configuration file is stored at the “/etc/apache2/mods-available/” directory. When installing PageSpeed, the module is automatically enabled as well as the “mod_deflate” which is a module for gzip compression.


To turn the PageSpeed module on and off, edit the configuration file using your favorite text editor.

sudo nano /etc/apache2/mod-available/pagespeed.conf

Opening the file, you can see that “ModPagespeed” is set to “on” by default. Changing this to “off” will disable the Pagespeed module.


While PageSpeed is optimizing a website, it generates some resources that are stored in a directory called “pagespeed_static”. To change this directory, edit the configuration file and add this line:

ModPagespeedStaticAssetPrefix /custom/static/directory


The PageSpeed module gives a browser interface to view the statistics of its output. To access the browser interface on a public IP, you will need to edit the following lines in the configuration file:


Below the Allow from line, add a similar line with your public address in place of the localhost address, something like:

Allow from 192.xx.xx.xx

Replace “192.xx.xx.xx” with your public IP address.

You can now restart Apache and visit that address. You will see an output that looks similar to this;



The PageSpeed Module provides a good way for a webmaster to optimize the server performance without having to do a lot of tweaking. It can be easily installed and work out of the box. A little note though, when enabling its filters, it is best to test it on a test server and see if it works first before making it live.

Jackson Mwendwa
Jackson Mwendwa

I am an intelligent and presentable individual with a degree in Computer Science and over four years experience in Management, Software Development, Information Technology Support and Tech article/tutorial writing. I possess a fresh, modern approach to the industry, employing creative and enthusiastic methods to problem-solving and would like to realize my full potential through practice, effectiveness, and innovation.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox