Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Turn On Compression with mod_deflate

This guide shows how to shrink your web pages before they travel, so your site loads faster.

Web Hosting2 min read13 steps2 screenshots

What is mod_deflate?

Compression makes files smaller, like squeezing clothes into a vacuum bag. Smaller files travel faster over the internet. The Apache web server has a module, or add-on, called mod_deflate. It compresses text files such as HTML, CSS and JavaScript on the fly. The visitor's browser unpacks them again.

It works only on Apache. Ask Hostvento support whether mod_deflate is on for your plan.

Before you start

You will edit a file called .htaccess. It is a settings file for Apache that sits in your site folder, often public_html. A mistake can break your site. Make a backup copy first.

Steps for shared hosting

  1. Open your file manager or an FTP program.
  2. Turn on the option to show hidden files.
    cpanel software
  3. Download a copy of .htaccess as a backup.
  4. Open the file for editing. Create it if it does not exist.
  5. Paste these lines at the end:
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
  AddOutputFilterByType DEFLATE application/javascript application/json
  AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

The first line checks that the module exists. The other lines list which file types to compress. Images such as JPG and PNG are already compressed, so skip them.

  1. Save the file.
  2. Test your site to make sure it still loads.
    cpanel optimize website

Steps for a VPS or dedicated server

You need root access for this. Root is the admin user with full control of a server.

  1. Log in over SSH.
  2. On Ubuntu or Debian, run:
sudo a2enmod deflate
sudo systemctl restart apache2

The first line turns the module on. The second restarts Apache so it takes effect.

  1. On CentOS-style systems, mod_deflate is usually already loaded. Check with httpd -M | grep deflate. Then restart with systemctl restart httpd.

Check that it works

  1. Search for an online "gzip test" tool.
  2. Type your site address.
  3. It tells you whether compression is on.
Tip: If you see a 500 error after editing, remove the new lines or upload your backup. Then open a support ticket.

Quick recap

  • mod_deflate compresses pages to load them faster.
  • Add the rules to .htaccess on shared hosting.
  • VPS owners can enable the module with a2enmod deflate.
  • Back up first and test after.