Heroku - View Not Found - FileFinderView InvalidArgumentException - php

This is consuming the last 2 days of my life. Locally everything is working fine but when my code is deployed to Heroku, Laravel can't find the index view. It's my understanding this is some caching issue, so I have tried most of Artisan's commands to clean the cache:
php artisan config:cache
php artisan route:cache
php artisan view:clear
php artisan clear-compiled
This is my route, I'm serving a SPA:
Route::get('/{any}', 'HomeController#main')->where('any', '.*');
And this is the stack trace on my view:
I have cleaned the bootstrap/cache folder and honestly I'm out of ideas. Does someone have a light on this one? Thanks

Please use the all around cache clearing command :
php artisan optimize:clear

I've found the solution to the same issue:
The issue itself seems to be caused by the official php buildpack, which does php artisan optimize at the end of the build process inside the build environment (aside from other things it clears and recreates the configuration cache). This causes the build directory /tmp/build_xxxxxxxx/ to be saved into the configuration cache.
The solution is to run php artisan config:clear, but it won't take effect on the already built and running app because of how heroku works: when you access their shell you perform operations on the filesystem that's generated from a project build and is destroyed as soon as you exit the shell. The operations you perform on files in that shell don't effect the running app instances. php artisan config:clear must be ran at the end of the build process.
One way to do this is the gerardbalaoro/laravel buildpack which allows adding custom hooks after the build process. Keep in mind that it also does php artisan views:clear after the build while the official php buildpack doesn't. Using it and adding LARAVEL_COMMANDS='php artisan config:clear' to heroku config solved the issue for me.
tl;dr:
heroku buildpacks:set gerardbalaoro/laravel
heroku config:set LARAVEL_COMMANDS='php artisan config:clear'
git commit --allow-empty -m 'force rebuild'
git push heroku master

Related

Laravel 8 UI issue

I have installed Laravel 8 as a new project. When I run the project I get the "In order to use the Auth::routes() method, please install the laravel/ui package." But Laravel installation doc says that laravel ui is depreciated and that we should use Jetstream. So I installed Jetstream with the Livewire stack. Back to test the project and I get the same error msg.
I have run a composer dump-autoload.
What do I have to do to get a Laravel 8 project to run?
You will need to clear and recreate cache. Run the following php artisan commands:
php artisan cache:clear
php artisan config:cache
php artisan route:cache
I had this problem as well on many 'upgrades' from earlier versions of Laravel. I don't want to change the entire auth mechanism, as it works, so I will keep the code I have.
#Elisha Senoo's answer is correct, and solved it most of the time. However, if you find yourself unable to clear the cache (because it has the same error message on the artisan command), the solution is to manually clear the .php files within the bootstrap/cache folder and then php artisan config:cache.

Laravel with App Engine Standard Class 'Facade\Ignition\IgnitionServiceProvider' not found

This is driving me crazy second day. I'm new to Laravel and trying to get Laravel 6 work on Google App Engine Standard.
Tried: This tutorial and other ones, but it still fails to load Laravel index page
What I have done:
Created new Laravel project
Checked that Laravel is working on local host with php artisan serve
Generated new key with php artisan key:generate --show
Created app.yaml file with:
runtime: php72
env_variables:
APP_KEY: iktbUa2quYPV2av3zDx0XAuEVjwzVQY/oMfyI2PQNKk=
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
SESSION_DRIVER: cookie
Modified bootstrap/app.php by adding $app->useStoragePath(env('APP_STORAGE', base_path() . '/storage'));
Rancomposer remove --dev beyondcode/laravel-dump-server
Also ran:
php artisan cache:clear,
php artisan route:cache,
php artisan config:clear,
php artisan view:clear (as other tutorials suggested)
And gcloud app deploy
And I get error: "Class 'Facade\Ignition\IgnitionServiceProvider' not found"
If you're facing this issue after upgrading composer 1.0 to 2.0. Then you can follow this step:
Go to the project directory
Run composer install
Run composer dump-autoload
Try to run php artisan serve
It solved for me
Please Try
composer dump-autoload
It solved for me
App engine install dependency with "--no-dev" flag. If your application is debug mode and there is an error application is try to render error page by "facade/ignition" packages.
Solve-1: You can move "facade/ignition" dependency from "require-dev" to "dev" in composer.json file
Solve-2: You can run as production environment and with false APP_DEBUG flag
I have experienced other errors as well, most of them gave me Error 500 and
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /tmp/google-config/nginx.conf:3 in Stackdriver Logger
Also I was not aware that App Engine was executing composer.json on build (see Specifying Dependencies). And it seems the issue was that it cached that.
Everything was resolved by replacing command in step 7. :
gcloud app deploy with gcloud beta app deploy --no-cache
It seems that if I would have done all steps as in tutorial from the start I would not have any issues.
Try
php artisan route:clear
and you're good to go.
I try
composer update
and its working fine
Try running
composer update
or
composer dump-autoload
Go to your project terminal and run :
composer install
composer dump-autoload
php artisan serve
And your problem will go away.
I am also new to Laravel and I have experienced with this issue, and I searched solution which was
first run this command on your terminal
composer update
second run the command on below
composer dump-autoload
and then see the result :)
just uncomment soduim line from your ini file
before
;extension=sodium
after
extension=sodium
If you are facing this issue while running phpUnit tests then try to clear cache of bootstrap folder.

Laravel clear package auto-discovery cache of composer packages

I wanted to remove a package from laravel. I did composer remove vendor/package
It was all good on my dev, but when I deploy on production something went wrong and I cannot do anything now.
when I run
php artisan package:discover
I'm geting
In ProviderRepository.php line 208:
Class 'Laracasts\Flash\FlashServiceProvider' not found
I'm guessing I it is something to do with some kind of cache or maby config
but I cannot run this command,
php artisan config:clear
because I'm getting the same error message as above.
PS. I'm using Laravel 5.6
You may need clear the autoloader files if they get jammed up as it is looking at those cached files when php artisan config:clear runs, thus creating the jam.
Remove the following files and they will rebuild:
/bootstrap/cache/packages.php
/bootstrap/cache/services.php
I fixed my problem deleting a config file like so:
$rm bootstrap/cache/config.php
This file is basically a cache for config, if you want to have this file built for you just run a following artisan command:
$php artisan config:cache

Laravel unable to modify queued job code

When I send a job that fails due to an exception such as 'ErrorException' with message 'Undefined variable: sender' and I fix the code and re-fire the event, the previous code runs again and I get the same error.
I have no idea why Laravel re-runs my old code over and over. I'd obviously like to be able to fix the mistakes that are breaking my job execution.
I've tried both composer dump-autoload and php artisan queue:flush and those have no effect. Any help?
My Laravel 5.1 config/compile.php file is empty but this helped me:
sudo service beanstalkd restart
and
php artisan queue:restart
Laravel often lacks of good and accurate documentation.
You need to run php artisan clear-compiled to clear compiled files.
If you look at config/compile.php you will see some extra providers (or other classes) are cached by default by Laravel.
If you made any changes for example in EventServiceProvider and it was earlier cached, Laravel won't see those changes in case php artisan optimize command was earlier launched (and looking at https://github.com/laravel/laravel/blob/master/composer.json you will see it is launched after running composer install or composer update).
This feature has nothing in common with composer itself but with Laravel that's why running composer dump-autoload won't help.
In my case, supervisor was the issue.
This is the only process that works consistently for me:
run 'service supervisor stop'
run 'service supervisor start'
quit your browser, restart it, clear the cache and try again
Note: running 'service supervisor restart' had no effect.
I'm using Lumen and ran into the same issue. I tried php artisan queue:restart, which did nothing. I then found this thread and tried php artisan clear-compiled, as per the winning answer, but got the error:
Command "clear-compiled" is not defined.
I then saw that Artisan had the option php artisan cache:clear, which did the trick! When I fire that command followed by php artisan queue:work, my new job code is used.

Laravel artisan optimize Best Practices

I'm trying to fully understand the Laravel (5.1) artisan optimize command and best practices, but the documentation seems lacking. I don't have Composer installed on the production server so, specifically, I want to know what files are modified or created when running artisan optimize --force on development that must get pushed to production. The goal being not to blow up the app in production! After running the command, I see the following files have been modified:
\bootstrap\cache\compiled.php
\vendor\composer\ - the entire directory
\vendor\autoload.php
Am I overthinking this, or do I just push these files to production and I'm good to go? Also, what is the best practice regarding when to run artisan optimize? Each time a new model is created? What about controllers, routes and helper classes?
Lastly, I see the \bootstrap\cache\compiled.php file is a whopping 548KB and almost 17K lines! Is that really considered optimal?
[edit - As #crishoj says, as of Laravel 5.5, php artisan optimize is no longer needed]
Normal Laravel practice is to have composer installed on your production server.
These are the steps Envoyer (made by Laravel's creator) takes to deploy an app on production -- I've annotated them below:
# Install application dependencies, such as the Laravel framework itself.
#
# If you run composer update in development and commit the `composer.lock`
# file to your repository, then `composer install` will install the exact
# same versions in production.
composer install --no-interaction
# Clear the old boostrap/cache/compiled.php
php artisan clear-compiled
# Recreate boostrap/cache/compiled.php
php artisan optimize
# Migrate any database changes
php artisan migrate
As of Laravel 5.5, php artisan optimize is not longer required.
You can also take benefit of laravel packages to easily optimize your application by caching page partials
https://github.com/imanghafoori1/laravel-widgetize

Categories