Mod expires configuration and or installation

Posted February 20, 2020 3.4k views
LAMP Stack


I performed a pagespeed test it appears that I do not have Mod expires or it is not configured. I moved this site from a shared host and had this configured in my .htaccess file. However, I now have just realized that this probably isn’t installed or configured on my Ubuntu Lamp stack.

How would I go about this


1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hi @albertramsbottom,

I believe mod_expires comes automatically when you install Apache however you can check it like so

apachectl -M 

If you can’t find it in the presented list, try using the following command to enable it

a2enmod headers
a2enmod expires
systemctl restart apache2

That’s it, you now have mod_expires enabled.


  • Yes thanks I have done that but when i go to and stick in my sites it says

    Leverage browser caching for the following cache-able resources: (expiration not specified) (expiration not specified) (5 minutes) (5 minutes) (12 minutes 30 seconds) (2 hours) (2 hours) (4 hours)

    Does this mean I need to addreass each file type?

    My cache header part of my .htaccess is


    <IfModule mod_expires.c>
        ExpiresActive on
        #ExpiresDefault                                      "access plus 1 month"
      # CSS
        ExpiresByType text/css                              "access plus 1 year"
      # Data interchange
        ExpiresByType application/json                      "access plus 0 seconds"
        ExpiresByType application/xml                       "access plus 0 seconds"
        ExpiresByType text/xml                              "access plus 0 seconds"
      # Favicon (cannot be renamed!)
        ExpiresByType image/x-icon                          "access plus 1 week"
      # HTML components (HTCs)
        ExpiresByType text/x-component                      "access plus 1 month"
      # HTML
        ExpiresByType text/html                             "access plus 0 seconds"
      # JavaScript
        ExpiresByType application/javascript                "access plus 1 year"
      # Manifest files
        ExpiresByType application/x-web-app-manifest+json   "access plus 0 seconds"
        ExpiresByType text/cache-manifest                   "access plus 0 seconds"
      # Media
        ExpiresByType audio/ogg                             "access plus 1 month"
        ExpiresByType image/gif                             "access plus 1 month"
        ExpiresByType image/jpeg                            "access plus 1 month"
        ExpiresByType image/png                             "access plus 1 month"
        ExpiresByType video/mp4                             "access plus 1 month"
        ExpiresByType video/ogg                             "access plus 1 month"
        ExpiresByType video/webm                            "access plus 1 month"
      # Web feeds
        ExpiresByType application/atom+xml                  "access plus 1 hour"
        ExpiresByType application/rss+xml                   "access plus 1 hour"
      # Web fonts
        ExpiresByType application/font-woff                 "access plus 1 month"
        ExpiresByType application/         "access plus 1 month"
        ExpiresByType application/x-font-ttf                "access plus 1 month"
        ExpiresByType font/opentype                         "access plus 1 month"
        ExpiresByType image/svg+xml                         "access plus 1 month"
    • Hi @albertramsbottom,

      According to GTMetrix, you should be able to use the following

      <IfModule mod_expires.c>
        ExpiresActive On
        # Images
        ExpiresByType image/jpeg "access plus 1 year"
        ExpiresByType image/gif "access plus 1 year"
        ExpiresByType image/png "access plus 1 year"
        ExpiresByType image/webp "access plus 1 year"
        ExpiresByType image/svg+xml "access plus 1 year"
        ExpiresByType image/x-icon "access plus 1 year"
        # Video
        ExpiresByType video/mp4 "access plus 1 year"
        ExpiresByType video/mpeg "access plus 1 year"
        # CSS, JavaScript
        ExpiresByType text/css "access plus 1 month"
        ExpiresByType text/javascript "access plus 1 month"
        ExpiresByType application/javascript "access plus 1 month"
        # Others
        ExpiresByType application/pdf "access plus 1 month"
        ExpiresByType application/x-shockwave-flash "access plus 1 month"

      I can see you have most if not all applied but please make sure you do and test it with GTMerix one more time. Please be aware there can be cache on GTMetrix as well.