Cannot log into Magento Admin? Magento Admin not loading? Magento Cache Refresh Script

created April 22, 2013, last updated June 18, 2015.

closeThis post was last updated 9 years 8 months ago, some of the information contained here may no longer be actual and any referenced software versions may have been updated!

It is possible to lock yourself out of the Magento back end admin interface simply by disabling a module which affects html rendering and stops you from logging back into the admin interface – which you need to do to re-enable the module – DOH! Its a real catch 22 situation.

If you are locked out of Magento admin, or your admin pages are not rendering correctly due to an admin change this post may just save your bacon.

If you have disabled an extension and need to re-enable it but the admin interface is not working, load up PHPMyAdmin and browse to your Magento database. Find the core_config_data table and then page through all the config options until you find the advanced/modules_disable_output rows. Find your disabled module – it will have a value of 1, and change the value back to 0 to enable it.

Paste the following code into a new .php file and save it to the root folder of your Magento store and run it in your browser. It will refresh the Magento cache, and re-enable the disabled module. Hopefully you should then be able to access admin again.

Depending on what has gone wrong with your configuration this may not always work, but if you have modified an admin config that for whatever reason has locked you out of admin then this method may work for you. It certainly is less painless than a full DB restore which is perhaps your other option.

Here is the cache refresh code.

require_once 'app/Mage.php';
umask( 0 );
Mage :: app( "default" );
$ver = Mage :: getVersion();
$userModel = Mage :: getModel( 'admin/user' );
$userModel -> setUserId( 0 );
Mage :: getSingleton( 'admin/session' ) -> setUser( $userModel );
echo "Refreshing cache...\n";
Mage :: app() -> cleanCache();
$enable = array();
foreach ( Mage :: helper( 'core' ) -> getCacheTypes() as $type => $label ) {
$enable[$type] = 1;
Mage :: app() -> saveUseCache( $enable );
echo "Cache refreshed";


This site uses Akismet to reduce spam. Learn how your comment data is processed.