How to enable mod_deflate in apache

The mod_deflate is a very useful apache module which increase the loading speed of your websites. You can enable this module simply by rebuilding your apache by using easyapache if you have server with control panel WHM/cPanel.

Method I (Server with cPanel)
Enable mod_deflate via easyapache.
You can rebuild your apache by running the command below.

# /scripts/easyapache

Before executing easyapache make sure that you have taken a backup of both Apache and Php conf file and also notice the current version of your apache and php. That will be helpful in your easyapache steps. Command to find the php configuration file.

# php --ini

Command to find Apache and php version.

# httpd -v  (Apache)

# php -v  (PHP)

Do execute the easyapache carefully.

Method II (Server without cPanel)
Enable mod_deflate by editing apache conf(httpd.conf) file.

Add the following lines to configure mod_deflate in your apache configuration file.

 <IfModule mod_deflate.c>
  # compress text, html, javascript, css, xml: 
  AddOutputFilterByType DEFLATE text/plain 
  AddOutputFilterByType DEFLATE text/html 
  AddOutputFilterByType DEFLATE text/xml 
  AddOutputFilterByType DEFLATE text/css 
  AddOutputFilterByType DEFLATE application/xml 
  AddOutputFilterByType DEFLATE application/xhtml+xml 
  AddOutputFilterByType DEFLATE application/rss+xml 
  AddOutputFilterByType DEFLATE application/javascript 
  AddOutputFilterByType DEFLATE application/x-javascript 
  AddOutputFilterByType DEFLATE image/x-icon
</IfModule>

If you want to compress only a few types, you can add the following line to the apache conf.

AddOutputFilterByType DEFLATE text/html text/plain text/xml

Restart the apache service to coplete the process,

# /etc/init.d/httpd restart
Or
# service httpd restart

Command to check the modules in httpd

# httpd -M

Command to check the httpd conf syntax.

# httpd -t

That’s it

Similar topics
How to disable ‘Directory listing’ in Apache web server?
How to change the apache port via command line in cpanel

Post navigation

Arunlal Ashok

Linux Systems Architect at Endurance International Group. I know her (Linux) since many years. Linux lover. Like to play on Linux console. I started this blog to share and discuss Linux thoughts.

Always happy for an open discussion! Write to arun (@) crybit (dot) com. Check about me for more details. About this blog and our strong members, check The team CryBit.com

3 thoughts on “How to enable mod_deflate in apache

  1. Hi ,
    is there any way to turn on “mod_deflate” from cpanel for clients?
    i guess my hosting provider don’t want to install this feature for some unknown reason!!!
    my host Apache ver. is 2.2
    please help, thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *