24

If for some reason I couldn't access my Cache Management page from my Magento Admin, how can I clear cache using SSH?

5 Answers 5

57

I have resolved the issue by myself with the following solution:

Login to your server and run the below command from your magento root directory:

php -r 'require "app/Mage.php"; Mage::app()->getCacheInstance()->flush();'

Above command flush your magento 1 cache. I suggest when change magento project folder then run above command

1
  • The only issue with this method is that if your database connection parameters are stored in the cache and you want to update them, the program will fail as it connects to the cached database before clearing the cache. Sep 14, 2022 at 1:29
6

You may delete it from command line with the below commands

$rm -rf var/cache/*
$rm -rf var/session/*

Find full details here

(or)

Mage::app()->getCacheInstance()->flush();

A shell script is provided here to do the same.

1

The simple solution is to login with SSH and navigate to your Magento cache directory. Remove all files and sub-directories in this cache directory but do not delete the cache directory itself. Here is some sample code.

cd /<magendoDirectory>/var/cache/
ls -l 
rm -r ./*

Make sure you are in the correct directory before running the rm command. We found that this is all that is necessary.

Removing the contents of your /<magendoDirectory>/var/report/ directory has no effect in version 1.9.x

Removing the contents of your /<magendoDirectory>/var/session/ may have the effect of invalidating your user sessions. This is not desirable in a production environment. We do not have this directory in our version 1.9.x instances.

0

Sometimes if the flushing the cache fail, you need to configure your redis server correctly. Please refer to:

https://cloudkul.com/blog/configure-magento-1-9-x-with-redis-as-backend-cache/

1
  • 1
    Please add more details. If Link is expired then answer is invalid.
    – Msquare
    Mar 28, 2020 at 2:45
-1
  1. Remove following directories -

/magentorootdir/var/cache/*

/magentorootdir/var/session/*

/magentorootdir/var/report/*

  1. Then run the command as mentioned above

     php -r 'require "app/Mage.php"; Mage::app()->getCacheInstance()->flush();'
    

Reference

1
  • 3
    Don't remove var/session/* or var/report/* - these are unrelated to caches. Feb 8, 2018 at 0:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.