1

I am running Debian and Apache/2.2.22 I have gzip enabled, and I would like to know, what is my compression level and how to change it. I know this can be achieved editing php.ini, but I would like to configure it in apache. How can it be done?

sysadmin1138
  • 133,124
  • 18
  • 176
  • 300
Firze
  • 355
  • 6
  • 16

4 Answers4

7

You can adjust the compression level by simply adding DeflateCompressionLevel.

DeflateCompressionLevel 9

This line of code can range from 1 to 9, 9 being the best compression method. By default 9 is used and there is rarely any reason to specify a compression level unless your CPU usage is high due to high website usage.

Innovator
  • 507
  • 2
  • 11
3

Believe it or not but the documentation for mod_deflate has this information in it. In particular DeflateCompressionLevel directive is your friend. You can set the level between 1 (low) and 9 (high). It also says in the documentation that the default is zlib's default compression level.

The zlib documentation says that the default compression level is 6.

user9517
  • 115,471
  • 20
  • 215
  • 297
  • Where do I add this DeflateCompressionLevel? I tried to add it to apache.conf and restart apache but didn't change anything. – Firze Jun 25 '14 at 10:42
  • @Firze the documentation tells you all you need to know. I suggest that rather than having me read it for you, you educate yourself in it's usage. – user9517 Jun 25 '14 at 10:48
3

With Iain's help I figured out there is mod_deflate and I have to add deflatecompressionlevel in /etc/apache2/mods-available/deflate.conf

After the change my deflate.conf looked like this:

<IfModule mod_deflate.c>
          # these are known to be safe with MSIE 6
          AddOutputFilterByType DEFLATE text/html text/plain text/xml

          # everything else may cause problems with MSIE 6
          AddOutputFilterByType DEFLATE text/css
          AddOutputFilterByType DEFLATE application/x-javascript application/javascript application$
          AddOutputFilterByType DEFLATE application/rss+xml
          DeflateCompressionLevel 9
</IfModule>
Firze
  • 355
  • 6
  • 16
0

As a complement to accepted answer you could also use apache's filesMatch directive to compress all responses rather than compressing them by type:

<filesMatch "\.*$">
    SetOutputFilter DEFLATE
</filesMatch>
DeflateCompressionLevel 7  # I prefer to use 7 for less CPU consumption on traffics
DeflateMemLevel 9
DeflateWindowSize 15
Mojtaba Rezaeian
  • 451
  • 5
  • 14