BindingResolutionException Target class [hash] does not exist after deploy - laravel

I wanted to deploy my laravel 8.0 project via ssh pull to production. I did composer update in ssh to my ubuntu server and after that my website is down and showing 500 error.
when I turn on debug mode in production it shows below error:
Target class [hash] does not exist.
my website worked well before pull and composer update and after that this happened.
also there is no problem in local environment and it works properly.
my .env file in production also exists and the details are set.
I have tried lots of ways for resolving the error but none of these works:
changing permisions for bootstrap and also for the whole project :
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
removing and reverting bootstrap folder
composer dump-autoload
php artisan config:cache
composer update and sudo composer update
I also tried these commands but none of them worked:
php artisan route:clear
php artisan view:clear
php artisan config:cache
php artisan cache:clear
php artisan config:clear
I've searched alot and tried many ways but no result.
could any one say what is wrong please? thanks alot.

Related

Laravel on VestaCP throws error 500. What file should I update to solve this problem?

When i try visiting my site I get this error, when I look domain.com.error.log:
PHP Fatal error: require(): Failed opening required '/home/<user/web/<domain>/public_html/../vendor/autoload.php
Files from my laravel project are placed into domain folder, files from public folder are inserted into /public_html folder. I've tried composer update, generate key, and all the other composer commands that people adviced here before.
I've set all my directories permissions to 777, so this error cannot be because of lacking permissions.
If you need any additional information, please ask, trying to solve this problem for 4 days already.
Edit: Solved this problem, it appeared because php didn't have access to files that are not inside public_html. So, this can be solved by either putting all your project into public_html folder, or updating your server rules to allow php access the folder with the project.
You need to install composer from www.getcomposer.org
composer dump-autoload
composer install --no-dev --no-interaction --prefer-dist --optimize-autoloader
php artisan cache:clear
php artisan route:cache
php artisan view:clear
php artisan migrate --force

Laravel showing "Failed to clear cache. Make sure you have the appropriate permissions"

Laravel was displaying to me "Access denied for user 'homestead'#'localhost' (using password: YES)". One solution for this was clearing the cache and the config cache stored, all this with these three commands:
php artisan cache:clear
php artisan config:clear
php artisan config:cache
After php artisan cache:clear, terminal says:
Failed to clear cache. Make sure you have the appropriate permissions. (with red background)
Doing the second and third code (php artisan config:clear and php artisan config:cache) works fine! But it still gives me the error when typing the first line. Can anyone explain why?
If the data directory doesn't exist under (storage/framework/cache/data), then you will have this error.
This data directory doesn't exist by default on a fresh/new installation.
Creating the data directory manually at (storage/framework/cache) should fix this issue.
Try deleting these cached files under bootstrap folder:
/bootstrap/cache/packages.php
/bootstrap/cache/services.php
/bootstrap/cache/config.php
Then run php artisan cache:clear
Calling
php artisan config:cache
before
php artisan cache:clear
fixed the issue.
Just only add folder named data in storage/framework/cache/ and try:
php artisan cache:clear
First try:
Check if there is a "data" folder inside "storage/framework/cache/".
If there is not, then create it manually. (create a new folder with name "data")
Option 2:
If there is a "data" folder inside "storage/framework/cache/".
Remove ALL existing folders inside there.
Then final, running this:
php artisan cache:clear
This should fix this issue: "Failed to clear cache. Make sure you have the appropriate permissions."
Calling the following 4 commands should fix most of the permission issues on laravel.
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
chmod -R 775 storage
chmod -R 775 bootstrap/cache
Basically, chown -R $USER:www-data what this does is it set current user $USER as owner and www-data as group and chmod -R 775 gives 7 to user,7 to group and 5 to other.
#PS: You need to run above command from the laravel project directory, else, you need to provide full path like /var/www/project_name/storage
In Laravel 8 I solved my issue by first running composer dump-autoload and then used php artisan config:cache
Deleting and adding back the ./storage/framework/cache/data folder worked for me.
You should update the permission using the below steps:
Check user using command "whoami" then let output is "ironman"
Run below command if "data" folder exists in the cache directory
sudo chown -R ironman:ironman storage/framework/cache/data/
This will resolve your below issue
Delete all subfolders under:
storage/framework/cache/data/
I ran my project in a docker container, then later tried accessing it via laragon, I had similar issue, this was due to compiled configurations in /bootstrap/cache/config.php.
I fixed fit by running php artisan config:clear, this deletes the /bootstrap/cache/config.php file automatically.
I had the same problem but noticed if you run php artisan config:clear it also by default runs cache:clear right after it so when you run it again there is not cache in it and gives that error. you only need to run php artisan config:clear. I am not sure why cache:clear fails when its ran alone but running the config:clear is a good alternative.
Here is a helpful alias i use to clear everything in the app.
laraclear='php artisan config:cache && php artisan config:clear && php artisan view:clear && php artisan route:clear && php artisan telescope:clear && php artisan debugbar:clear'
Remove any unwanted commands that you do not use in it.
(For MAC Users)
Sometimes, it means current user don't have sufficient permission to the storage/framework/cache/data/ folder. Run
sudo chmod -R ug+rwx storage/framework/cache/data/
then
php artisan cache:clear
Hope sometimes it work for you.
In my case the problem was I had 'CACHE_DRIVER=memcached' in .env but didn't have memcached installed. Switching to the file driver or installing memcached fixed the problem for me.
You may need to clear the autoloader with
composer dump-autoload
If that doesn't work you can manually remove the following non-tracked (usually) files to clear the autoloader and cache if they get jammed up:
/bootstrap/cache/packages.php
/bootstrap/cache/services.php
Can't this solve it?
$php artisan optimize:clear
Compiled views cleared!
Application cache cleared!
Route cache cleared!
Configuration cache cleared!
Compiled services and packages files removed!
For Laravel Homestead on Windows:
In your .env file, change your CACHE_DRIVER from file to memcached.
Run php artisan cache:clear.
Had the same problem on my vagrant/homestead VM. All the other things in this thread didn't help.
The solution was vagrant reload --provision
Giving 775 permission to the storage directory solved this problem for me.
sudo chmod -R 775 storage
I am running my project in Homestead.
My environment :
Ubuntu1~20.04+
Laravel 6.20.26
My output
display real fatal info
Edit src/Illuminate/Filesystem/Filesystem.php 598:14
original code:
if (! $preserve) {
#rmdir($directory);
}
debug code
if (! $preserve) {
rmdir($directory);
}
Then re-execute php artisan cache:clear
The output changed:
Then, I just resolve Text file busy
Ensure APP_URL is properly set on .env file. Changing http to https in the APP_URL variable on .env file solved it for me.
Solution :
update the permission :
get user name by this command : whoami
Run command if "data" folderexists in the cache directory.
sudo chown -R YourUSERName:YourUSERName storage/framework/cache/data/
In my case, there is no cache available that's why the artisan is unable to delete or reset the cache.
First browse the website and allow it to create some cache then try to clear it.
You can check whether the cache is available or not in directory storage/framework/cache/*
got the same error. try giving chmod 777 permission in the concerned folder
My guess is you have a permission/ownership problem. Either set up the permissions correctly or recursively delete the cache folder manually and re-create it:
sudo rm -Rf storage/framework/cache
mkdir storage/framework/cache
maybe you need to chmod 777 -R storage folder.
and i think it can also chown www-data:www-data
Incase non of these works for you, simply run your php artisan cache:clear command with sudo.
e.g. sudo php artisan cache:clear
Thank me later~!

There is no existing directory at /storage/logs and its not buildable: Permission denied

I have a problem with my Laravel deployment on a OVH web server.
After made
composer update
php artisan cache:clear
php artisan route:clear
php artisan dump-autoload
I have this answer:
There is no existing directory at /storage/logs and its not buildable: Permission denied
I put all the files on 777 chmod but I have always this answer.
Please try the following commands
php artisan route:clear
php artisan config:clear
php artisan cache:clear
Note: In case you are a Homestead & VirtualBox user, please be sure that your VirtualBox is up to date.
It helped in this thread at laracasts
Clear the cache and config, then deploy to the live server.
If you've already uploaded to the live server, then you have to follow these steps:
Delete bootstrap/cache/config.php
Delete all log files in storage/logs.
You don't need to add any permission on the storage file.
The main problem here is in the compiled file, and due to which laravel try to show an error.
By default in laravel, storage file not having permission to show in the console (error
shows from the error.log file).
So the thing you need to fix is to fix compile file. which can be done thought this single command
Use this
php artisan optimize:clear
This command will clear all your cache
Compiled views
Application cache
Route cache
Configuration cache
After changing local conf i got the same error over and over,
try this, probably will help.
rm bootstrap/cache/config.php
and then
php artisan cache:clear
depending on your scenario, reloading auto-loader file can solve your issue, for that use :
composer dump-autoload
or sometimes just try :
composer install
this do the two the commands listed above.
go to your vagrant
then run
vagrant ssh
php artisan config:cache
Run the following command if you can access your server terminal
php artisan route:clear && php artisan cache:clear && php artisan config:clear && php artisan config:cache
If you are on shared hosting and cant access the terminal go to your web route file in routes/web.php and make a temporary link such as shown:
Route::get('reset', function (){
Artisan::call('route:clear');
Artisan::call('cache:clear');
Artisan::call('config:clear');
Artisan::call('config:cache');
});
Then go to http://your-domain/reset to execute the commands. there after you can now access your website as normal
If you are using homestead (vagrant) in Laravel then follow the steps #Farid shahidi provided
vagrant ssh
cd /home/vagrant/code <-- your file usually resides here; see your Homestead.yaml configuration
php artisan config:cache
You Have to try artisan command in this way
php artisan cache: clear
php artisan config:cache
php artisan cache: clear
This one-line command solves my issue:
php artisan config:cache
Delete bootstrap/cache/config.php from your laravel deployment on the server.
Please run the below commands:
php artisan route:clear
php artisan config:clear
php artisan cache:clear
This one worked for me in case your project is located within /var/www/html/
sudo chmod -Rf 0777 /var/www/html/{project-name}/bootstrap/cache
sudo chmod -Rf 0777 /var/www/html/{project-name}/storage
You need to run this command from the terminal.
php artisan config:clear
php artisan config:cache
I got the same issue, I change the permissions of the folders inside the the storage folder.
chmod 777 <folder_name>
I'm not sure about this security wise. but this resolve my problem.
I change my file settings to 755 also work for me.
try this
remove your "vendor" folder
Run "composer install" or "composer install --ignore-platform-reqs" on your cmd or terminal
php artisan config:cache
php artisan config:clear
php artisan cache:clear
php artisan route:cache
php artisan view:clear
php artisan config:cache
if you are using linux:
service apache2 restart (just in case)
if you using xammp:
just restart your xammp
For those of you using sail, do:
sail artisan optimize:clear

Laravel - Error page is blank after update from 5.3 to 5.4

I have updated Laravel from 5.3 to 5.4. Error pages are white and do not display an error after update. I am using a local server. The specifications:
OS: Ubuntu 16.04
Nginx/1.9.15
PHP 5.6.11
I read the this question (Laravel blank white screen) and I have tried solutions:
# Group Writable (Group, User Writable)
$ sudo chmod -R gu+w storage
# World-writable (Group, User, Other Writable)
$ sudo chmod -R guo+w storage
And other solutions have been proposed. But the problem persists!
Also, Application debuggin in .env and config/app.php is true.
Who can help?
After update your laravel you may clear all your cache and your compiled page. Try to do this:
php artisan view:clear
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan clear-compiled
php artisan optimize

TokenMismatchException in VerifyCsrfToken.php since I've updated my Box Homestead

So, I simply wanted to install the latest version of PHP GD to fix a problem of pixel.
Since then I've broken a lot of thing including mostly my vagrant/homestead box.
I remember having changed some permission and I think this is the main problem.
So do you have an idea of which folder shall have what kind of permission?
From within your project dir
sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
Laravel framework file permission - Security
https://laracasts.com/discuss/channels/general-discussion/laravel-framework-file-permission-security
If that doesn't work try Destroying / rebuilding the homestead box.
Also, I would run:
artisan view:clear
artisan cache:clear
artisan config:clear
artisan clear-compiled
composer dump-autoload

Resources