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

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
# 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

Arunlal Ashok

Linux Server Administrator. I'm managing Linux servers since 2012. I started this blog to share and discuss my ideas. Check My Profile!! in uPwork (oDesk) and let me know if you need any assistance. Thanks!!

You may also like...

3 Responses

  1. reza says:

    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.

  1. December 28, 2013

    […] The Gzip compression is very helpful to speedup the website loading speed. The ‘mod_deflate’ module is required to enable the gzip compression on an account. Click here for How to enable mod_deflate in apache […]

Leave a Reply

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