Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Web Servers»Apache»How To Enable GZIP Compression in Apache on Ubuntu

    How To Enable GZIP Compression in Apache on Ubuntu

    By RahulNovember 3, 20222 Mins Read

    GZIP compression is the process of taking your data and reducing its size by removing unnecessary characters like spaces and punctuation marks. When you use GZIP, the server can compress your data before it sends it to the client. The client then has less work to do when receiving the data, so it can receive it faster.

    Advertisement

    When you send data over a network, there are two main parts: sending and receiving. Sending involves taking your data and sending it from your computer to the server. Receiving involves taking that data and making sure it gets into your computer intact. There are lots of different things that can go wrong along these two lines – from losing power to having bad internet connections. When you compress your data, you reduce both the transmission time and the amount of work that needs to be done on both ends of the line.

  • Read: How to enable Gzip Compression on Nginx Server
  • Enabling Gzip Compression in Apache

    The Ubuntu and Debian system users follow the below steps to enable gzip compression in the Apache server.

    1. First of all, enable the mod_deflate module, which provides gzip compression to the Apache server.
      sudo a2enmod deflate 
      
    2. Once the module is enabled in the Apache server. Create or edit the .htaccess file in your website document root. For example, if the website document root is /var/www/html, then create file as:
      sudo nano /var/www/html/.htaccess 
      

      Append the following snippet to the file.

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      # GZIP compression for text files: HTML, CSS, JS, Text, XML, fonts
      <IfModule mod_deflate.c>
          AddOutputFilterByType DEFLATE text/html
          AddOutputFilterByType DEFLATE text/css
          AddOutputFilterByType DEFLATE text/javascript
          AddOutputFilterByType DEFLATE application/javascript
          AddOutputFilterByType DEFLATE application/xml
          AddOutputFilterByType DEFLATE text/plain
          AddOutputFilterByType DEFLATE text/xml
          AddOutputFilterByType DEFLATE font/opentype
          AddOutputFilterByType DEFLATE font/otf
          AddOutputFilterByType DEFLATE font/ttf
          AddOutputFilterByType DEFLATE image/svg+xml
          AddOutputFilterByType DEFLATE image/x-icon
          AddOutputFilterByType DEFLATE application/rss+xml
          AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
          AddOutputFilterByType DEFLATE application/x-font
          AddOutputFilterByType DEFLATE application/x-font-otf
          AddOutputFilterByType DEFLATE application/x-font-opentype
          AddOutputFilterByType DEFLATE application/x-font-truetype
          AddOutputFilterByType DEFLATE application/x-font-ttf
          AddOutputFilterByType DEFLATE application/x-javascript
          AddOutputFilterByType DEFLATE application/xhtml+xml
      </IfModule>

    3. Use the following command to restart the Apache server.
      sudo systemctl restart apache2 
      

    Verify Gzip Compression

    Now that your site has been enabled with gzip compression, let’s use one of below online tools to verify that Gzip is working correctly.

    • http://checkgzipcompression.com/
    • http://www.whatsmyip.org/http-compression-test/

    enable gzip

    Conclusion

    GZIP compression is a technique that reduces the size of data sent over the network. This can be useful when sending large files over a slow connection, or when there is a lot of data to send. By compressing your data, you may be able to reduce the size of your transfer.

    In this tutorial, you have learned about enabling Gzip compression in the Apache web server.

    apache gzip gzip gzip compression mod_deflate
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Simple Redirects with .htaccess

    Disable HTTP Methods in Apache

    How To Disable HTTP Methods in Apache

    How to Enable Brotli Compression in Apache

    How To Enable Brotli Compression in Apache

    View 8 Comments

    8 Comments

    1. John on November 17, 2017 10:33 am

      Thanks, useful tutorial.

      Reply
    2. John on April 5, 2017 11:16 pm

      This is good, but I highly recommend everyone check the HTML5 Boilerplate example for a bit more detail: https://github.com/h5bp/server-configs-apache

      Go to the /dist folder you’ll find a .htaccess with best practices for many things Apache, including gzip

      Reply
    3. Umesh on February 14, 2017 2:49 pm

      i followed above things but js/css not compressed- > google speed test tool -> http://www.namomithrarealestate.com….

      Reply
    4. Sanjay Raturi on April 14, 2016 6:04 pm

      Hi I am Sanjay Raturi from India.
      I have to enable Gzip compression for my website yogainrishikesh.in

      Please help me. please.

      Reply
      • Sanjay raturi on July 22, 2016 12:36 am

        I have 100/100 page speed on pagespeed insights google tool.
        See http://www.yogainrishikesh.in on Google pagespeed insights.

        Reply
    5. Sam Dawson on April 14, 2016 3:36 pm

      You have a typo! sudo a2enmod defalte should be sudo a2enmod deflate!

      Reply
      • Rahul on April 16, 2016 2:56 am

        Thanks SAM!!!

        Reply
    6. Kostas on October 6, 2015 7:55 pm

      Very useful, thank you.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    • What is a Orphan Process in Unix/Linux
    • How To Display Warning Message to Unauthorized SSH Access
    • How to Set a Custom SSH Login Banner and MOTD
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.