How to enable mod_deflate in apache

The mod_deflate is a very useful apache component which increase the running speed of your sites. You can allow this component basically by restoring your apache via easyapache if you have server with cpanel WHM/cPanel.

Server with cPanel:

Enable mod_deflate via easyapache.
You can rebuild your apache by running the command below.

# /scripts/easyapache

Before performing easyapache make sure that you have taken a back-up of both Apache and Php conf file and also check the present version of your apache and php. That will be of helpful in your easyapache actions. execute following command to find the php configuration file.

# php --ini

Command to find Apache and php version.

# httpd -v  (Apache)

# php -v  (PHP)

Once done execute the easyapache carefully.

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

Leave a Reply

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