Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Web Servers»Apache»How To Enable Gzip Compression Apache on Ubuntu 18.04 & 16.04

    How To Enable Gzip Compression Apache on Ubuntu 18.04 & 16.04

    RahulBy RahulAugust 19, 20132 Mins ReadUpdated:November 22, 2018

    The mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network. Currently mod_deflate is using with newer version of Apache. mod_deflate is the replacement of mod_gzip which was used with older version of Apache.

  • Read: How to enable Gzip Compression on Nginx Server
  • Step 1 – Enable Gzip Module

    Debian based users can enable Gzip module (mod_deflate) using the following command.

    sudo a2enmod deflate
    

    Step 2 – Configure Gzip Compression

    We can define which file types we need to compressed with below identifier in configuration file.

    AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript 
    

    Add following configuration in Apache Virtual Host to enable gzip compression for your website. You can also add this code to websites .htaccess file under the main document root.

    Apache VirtualHost Configuration
    <Directory /var/www/html/>
       <IfModule mod_mime.c>
    	AddType application/x-javascript .js
    	AddType text/css .css
       </IfModule>
       <IfModule mod_deflate.c>
    	AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/plain text/xml application/javascript
    	<IfModule mod_setenvif.c>
    		BrowserMatch ^Mozilla/4 gzip-only-text/html
    		BrowserMatch ^Mozilla/4.0[678] no-gzip
    		BrowserMatch bMSIE !no-gzip !gzip-only-text/html
    	</IfModule>
        </IfModule>
        Header append Vary User-Agent env=!dont-vary
    </Directory>
    

    Step 3 – Testing Compression

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

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

    enable gzip

    apache gzip gzip gzip compression mod_deflate
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Munin (Network Monitoring Tool) in CentOS, Red Hat & Fedora
    Next Article How to Allow Remote Clients to Connect MySQL Server

    Related Posts

    How To Disable HTTP Methods in Apache

    Updated:December 31, 20212 Mins Read

    How To Enable Brotli Compression in Apache

    2 Mins Read

    Create A Custom 404 Error Page on Apache

    Updated:April 19, 20221 Min Read

    Apache 404 Redirect to Homepage

    Updated:August 12, 20201 Min Read

    How to Enable expire headers in Apache

    Updated:May 25, 20201 Min Read

    How to Install Apache with PHP-FPM on Ubuntu 20.04

    Updated:December 3, 20203 Mins Read

    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

    Recent Posts
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    • (Resolved) Please install all available updates for your release before upgrading
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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