Laravel 5 – Clear Cache in Shared Hosting Server

5 Aug

In laravel application if you want to clear cache on shared hosting server or you want execute composer dump-autoload command. Below is the simple trick to do so.

You can create below routes in your routes/web.php file and execute in browser.

This route can be used to clear all cache in laravel application in shared hosting server.
Route::get(‘/clear-cache’, function() {
$exitCode = Artisan::call(‘cache:clear’);
// return what you want
});

below two routes can be used to execute composer dump-autoload command on shared hosting.
Route::get(‘/updateapp’, function()
{
\Artisan::call(‘dump-autoload’);
echo ‘dump-autoload complete’;
});

Or

Route::get(‘/updateapp’, function()
{
$process = new \Symfony\Component\Process\Process(‘php composer.phar autoload-dump’);
$process->setWorkingDirectory(base_path());
$process->run();
echo ‘dump-autoload complete’;
});

Leave a Reply

Your email address will not be published. Required fields are marked *

eighteen + five =