How to Clear the Cache of a Laravel App on Shared Hosting Servers

Clearing the cache is a process that is used to remove any old files or data that are no longer needed. This can be done on a localhost server by using the artisan command.

Clear Cache with Routes

The following steps will show you how to clear the cache of a Laravel app that is hosted on a shared server:

Open web.php and create routes as following:

Route::get('/clear-cache', function() {
    $exitCode = Artisan::call('cache:clear');
    echo 'Cache emptied';
});
Route::get('/clear-view', function() {
    $exitCode = Artisan::call('view:clear');
    echo 'View cache emptied';
});

Then you can access that route’s URL on a web browser to empty caches.

Alternate Method

Renaming the config.php file then reloading the web app can do wonders.

  • Open laravel_root_folder/bootstrap/cache.
  • Rename the config.php file to any name.
  • Reload your website.

A Method for Servers with SSH Access

If you are on a hosting which support SSH access, you can execute commands directly via the terminal. Use SSH access to connect to the server then run the artisan commands to clear the cache!

php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan clear-compiled
php artisan config:cache

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close