How to Install mod_deflate in Ubuntu / Debian

install mod_deflate ubuntu

mod_deflate is a powerful Apache module that compresses all the data sent using gzip compression before sending it to users’ web browsers. This improves page load speed and reduces network bandwidth. In fact, it even improves search rankings. Let us look at how to install mod_deflate in Ubuntu.


How to Install mod_deflate in Ubuntu / Debian

Here are the steps to install mod_deflate in Ubuntu / Debian.


1. Check if mod_deflate is installed

By default, mod_deflate is installed when you install Apache server on your system. To check it,

Open a terminal window and run the command

apachectl -t -D DUMP_MODULES | grep deflate

You should see the output

deflate_module (shared)


If you don’t see the above output, you will need to enable it by modifying the Apache conf file.

Open it in a text editor

$ sudo vim /etc/apache2/mods-enabled/deflate.load


Look for the line

LoadModule deflate_module /usr/lib/apache2/modules/

If there is a ‘#’ sign at the beginning, then remove it, save & close the file.


Restart Apache server to apply changes

$ sudo service apache2 restart


That’s it! You have installed mod_deflate in Ubuntu


3. Configure mod_deflate

To use mod_deflate effectively, you need to specifically instruct Apache which file types to compress.

Typically, webmasters use mod_deflate to compress HTML, CSS and JS files.

Open mod_deflate’s config file in a text editor

$ sudo vim /etc/apache2/mods-enabled/deflate.conf


By default, it is set to compress HTML, CSS, XML, RSS and JS files. However, its compression levels aren’t set.

To get the most out of mod_deflate, it is essential to set the following 3 directives:

  • Compression Level – Compression level of file between 1-9 (1 is lowest amount of compression)
  • Mem Level – How much memory should be used by zlib for compression
  • Window Size – zlib compression window size

By default, these 3 directives are set to their highest values. This might be quite resource intensive and negatively impact your server. So we set them to more reasonable values

To make mod_deflate more efficient, add the following lines

DeflateCompressionLevel 7
​DeflateMemLevel 8
​DeflateWindowSize 10


Save and close the file. Restart Apache to apply changes

$ sudo service apache2 restart


4. Test if mod_deflate is working

You can use online third-party tools to check if mod_deflate is enabled on your website or not. You just have to enter the URL of your website and it will tell you whether your website serves compressed content or not.



About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!