Hi!
I'm getting the following runtime exception when I deploy my Laravel app to the server:
Running artisan commands for staging...
INFO Configuration cached successfully.
INFO Events cached successfully.
INFO Routes cached successfully.
In ViewClearCommand.php line 59:
VIEW PATH NOT FOUND.
I don't get this at all when I am working locally on my app. Does anyone have any insight as to why this would be happening and how I can fix this? Looks like the portion of Laravel core code that is throwing it is in vendor/laravel/framework/src/Illuminate/Foundation/Console/ViewClearCommand.php
/**
* Execute the console command.
*
* @return void
*
* @throws \RuntimeException
*/
public function handle()
{
$path = $this->laravel['config']['view.compiled'];
if (! $path) {
throw new RuntimeException('View path not found.');
}
$this->laravel['view.engine.resolver']
->resolve('blade')
->forgetCompiledOrNotExpired();
foreach ($this->files->glob("{$path}/*") as $view) {
$this->files->delete($view);
}
The error message "VIEW PATH NOT FOUND" is thrown when the view path is not found in the Laravel application. This error typically occurs when the compiled view files are missing or the view path is not properly configured.
To fix this issue, you can try the following steps:
Clear the view cache: Run the following command in the terminal to clear the compiled view files:
php artisan view:clear
Check the view path configuration: Open the config/view.php file and make sure the compiled option is properly set. The compiled option should point to a valid directory where the compiled view files are stored. For example:
Ensure proper file permissions: Make sure that the storage directory and its subdirectories have proper write permissions. You can set the permissions using the following command:
chmod -R 755 storage
Recache the configuration: Run the following command to recache the configuration files:
php artisan config:cache
If the issue persists, it's possible that there is a problem with the server environment or the deployment process. In that case, you may need to investigate further or consult with your hosting provider.
Note: It's always a good practice to backup your application before making any changes.
Forgot to mention that I am trying to get the Laravel starter app to work on AWS. I haven't made any code changes. I just used composer to spin up a laravel app and deployed. Has anyone run into this when deploying to AWS?
Tl;Dr; if storage/framework/views doesn't exist and you didn't change the defaults, config('view.compiled') will return false and this error will happen.
This happened to me today because the way I deploy code to servers involves as "shared" folder with the .env file and storage directory structures, which I symlink into fresh git clones. But it was a fresh setup, so "storage" was empty. I was surprised that Laravel didn't just create the directory.