Sometimes, a Moodle site may fail to load properly due to corrupted or stuck cache files. A quick way to restore the system is to manually clear the Moodle cache folders from the server.
This approach is especially useful when the Moodle interface is not accessible and you cannot purge caches from the site administration dashboard.
Step 1: Stop Apache
Before clearing the cache folders, stop the Apache web server:
sudo systemctl stop apache2
Step 2: Clear Moodle Cache Folders
Run the following commands to delete the contents of Moodle’s cache-related folders:
sudo rm -rf /var/moodledata/cache/*
sudo rm -rf /var/moodledata/localcache/*
sudo rm -rf /var/moodledata/temp/*
sudo rm -rf /var/moodledata/muc/*
These commands remove temporary and cached files only. Moodle will automatically recreate the necessary cache files when the site starts running again.
Step 3: Restart Apache
Once the cache folders have been cleared, start Apache again:
sudo systemctl start apache2
Alternatively, you can restart Apache using:
sudo systemctl restart apache2
Step 4: Refresh the Moodle Site
Open your Moodle site in the browser and refresh the page. The system should now be back up and running.
Optional Step: Reapply Moodledata Permissions
You may also reapply the correct permissions to the Moodle data directory:
sudo chown -R www-data:www-data /var/moodledata
sudo find /var/moodledata -type d -exec chmod 2770 {} \;
sudo find /var/moodledata -type f -exec chmod 660 {} \;
These permissions ensure that the Apache web server user can properly read from and write to the Moodle data directory.
Important Note
Before running these commands, confirm that your Moodle data directory is actually located at:
/var/moodledata
If your Moodle data directory uses a different path, replace /var/moodledata with the correct location from your Moodle config.php file.
A typical Moodle data path is defined in config.php as:
$CFG->dataroot = '/var/moodledata';
Manually clearing Moodle cache folders is a simple and effective first step when troubleshooting a Moodle site that fails to load due to cache-related issues. After clearing the cache and restarting Apache, Moodle will rebuild the required cache files automatically.