Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DeusArcana's avatar

php artisan call order for config on shared hosting

I have a project on a shared hosting, so I have to compress the project, upload it and decompress; additional to that I have to run a series or artisan commands so the cache and other traces of the previous version get deleted.

For this I have a route:

Route::get('/route-cache', function() {
	function makeList($arr)
	{
		$return = '<ul>';
		foreach ($arr as $item)
		{
			$return .= '<li>' . (is_array($item) ? makeList($item) : $item) . '</li>';
		}
		$return .= '</ul>';
		return $return;
	}

	$arr = array();
    try {
    	Artisan::call('route:clear');
    	array_push($arr, Artisan::output());
    	Artisan::call('cache:clear');
    	array_push($arr, Artisan::output());
    	Artisan::call('view:clear');
    	array_push($arr, Artisan::output());
    	Artisan::call('optimize:clear');
    	array_push($arr, Artisan::output());
    	Artisan::call('view:cache');
    	array_push($arr, Artisan::output());
    	Artisan::call('config:cache');
    	array_push($arr, Artisan::output());
    	shell_exec('composer dumpautoload');
    } catch(Exception $e) {
        print_r($e);
		return;
    }

	return makeList($arr);
});

But I am a little confused on which command comes first config:cache or config:clear. Should I execute route:cache after route:clear? right now I am getting the following error:

exception: "InvalidArgumentException"
file: "/home1/ecosdel1/AdmonRiegos/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php"
line: 166
message: "Database connection [mysql] not configured."

So in which order should I call the those artisan commands? If there is a better way to do this I'm open to suggestions. Thanks beforehand.

0 likes
1 reply
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

The order of the commands should be as follows:

  1. route:clear
  2. config:clear
  3. cache:clear
  4. view:clear
  5. optimize:clear
  6. config:cache
  7. route:cache

This is because config:cache needs to be run after config:clear to ensure that the cached configuration files are up-to-date. Similarly, route:cache needs to be run after route:clear to ensure that the cached route files are up-to-date.

Here's an updated version of the code with the commands in the correct order:

Route::get('/route-cache', function() {
    function makeList($arr)
    {
        $return = '<ul>';
        foreach ($arr as $item)
        {
            $return .= '<li>' . (is_array($item) ? makeList($item) : $item) . '</li>';
        }
        $return .= '</ul>';
        return $return;
    }

    $arr = array();
    try {
        Artisan::call('route:clear');
        array_push($arr, Artisan::output());
        Artisan::call('config:clear');
        array_push($arr, Artisan::output());
        Artisan::call('cache:clear');
        array_push($arr, Artisan::output());
        Artisan::call('view:clear');
        array_push($arr, Artisan::output());
        Artisan::call('optimize:clear');
        array_push($arr, Artisan::output());
        Artisan::call('config:cache');
        array_push($arr, Artisan::output());
        Artisan::call('route:cache');
        array_push($arr, Artisan::output());
        shell_exec('composer dumpautoload');
    } catch(Exception $e) {
        print_r($e);
        return;
    }

    return makeList($arr);
});
1 like

Please or to participate in this conversation.