disable apache cache

How To Disable Apache Cache

If Apache cache doesn’t work properly for your website, you need to delete Apache cache or clear Apache cache. If it still doesn’t work, then here’s how to completely disable Apache Cache for your website.


How To Disable Apache Cache

Here’s how to disable Apache Cache for your website. After you disable Apache cache, you may want to use a charting tool to monitor the key metrics about your website/application such as signups, traffic, sales, revenue, etc. using dashboards & charts, to ensure everything is working well.


1. Open .htaccess file

There are many ways to disable Apache cache. If you use htaccess file, open it in a text editor.

You will typically find .htaccess file in your site’s root folder (e.g /var/www/html/). You can open it using vi editor

$ sudo vim /var/www/html/.htaccess


2. Disable Apache Cache

Let’s say you want to disable caching html, js, css files only, then add the following lines to your .htaccess file.

#Initialize mod_rewrite
RewriteEngine On
<FilesMatch "\.(html|htm|js|css)$">
  FileETag None
  <IfModule mod_headers.c>
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"

If you want to also stop caching other file types such as pdf, jpg, etc. include them in line #3 above, the part in bold


Bonus Read : How to Enable mod_ssl in Apache


3. Restart Apache Server

Restart Apache Server to apply changes

$ sudo service apache2 restart


If you don’t use htaccess file, then you can open Apache server configuration file and add the lines mentioned in step #2, and restart web server.

sudo vi /etc/apache2/sites-available/000-default.conf

This will stop caching for all your websites, in case you run multiple websites on your server.


If you use virtual hosts, you can open virtual host configuration file for your domain (e.g example.com), scroll to the bottom of the file and add the above lines mentioned in step #2, just before line </VirtualHost>

sudo vi /etc/apache2/sites-available/example.com.conf

This will disable caching only for the specific domain (e.g example.com) and leave others untouched.


Bonus Read : How to Redirect 404 error pages to URL


How to Clear Apache Cache

Instead of disabling Apache cache, if you only want to clear Apache cache, then you can remove the contents in Apache’s cache folder located at /var/cache/apache2/mod_cache_disk/

$ sudo rm -r /var/cache/apache2/mod_cache_disk/*

This will delete Apache cache and start caching content afresh.

By the way, if you want to create charts & dashboards to monitor your business or website, you can try Ubiq. We offer a 14-day free trial.


About Ubiq

Ubiq is a powerful dashboard & reporting platform for small & medium businesses. Build dashboards, charts & reports for your business in minutes. Get insights from data quickly. Try it for free today!