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
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
-
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
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.
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
- Remove following directories -
/magentorootdir/var/cache/*
/magentorootdir/var/session/*
/magentorootdir/var/report/*
Then run the command as mentioned above
php -r 'require "app/Mage.php"; Mage::app()->getCacheInstance()->flush();'
-
3Don't remove
var/session/*
orvar/report/*
- these are unrelated to caches. Feb 8, 2018 at 0:51