No such file or directory error (Laravel/Homestead) - php

I use laravel on homestead. I tried a lot of different commands in order to clear cache and other stuff and nothing helped.
I keep getting this error:
file_put_contents(/Users/Victor/Sites/pft/pft-back/storage/framework/cache/data/05/9f/059f793d8b638b8c21ead7edbba382b9e9183fac): failed to open stream: No such file or directory
What I've tried is:
Set 777 for storage folder
php artisan cache:clear
php artisan view:clear
php artisan clear-compiled
composer dump-autoload
No idea why it's happening but I'm pretty sure because of homestead since I've just recently started using it.
Also I tried all commands both from homestead user and mac user (I'm running homestead on mac)

The problem is the underlying storage maps, could check if storage/framework, storage/framework/cache and storage/framework/cache/data have r/w permission and otherwise create them?

Related

Getting Error 500 after composer update from ssh

I used to use forge for deploying my laravel application to production. I recently deregisted forge and I wanted to deploy via ssh to ubuntu server on my own.
I did composer update and I pull changes to my server via ssh; but after these my application started to give error 500. I did every thing I searched may be useful such as commands below but nothing worked.
does any one know why am I facing is this error? in local environment every thing works properly and my laravel project worked properly before ssh and composer update.
these are the steps I have go through but nothing worked:
deleting vendor folder and reinstalling composer
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
run 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 view:clear
php artisan config:cache
php artisan cache:clear
php artisan config:clear
I am using laravel 8
my .env file also exists and every thing are set there
when I turn on debug mode the error of the application page is like this:
Target class [hash] does not exist.
please helpme if any one has any experience on this problem.
From russia /ivorycoat
delete vendor
composer update
.env.example copy and create .env
php artisan cache:clear
php artisan config:clear
php artisan key:generate
php artisan serve

file_put_contents error on existing laravel project

I am trying to configure a new laravel project however I always get the following error no matter what:
file_put_contents(C:\Users\bla...\Documents\GitHub\project\storage\framework/sessions/yB2Ji8maEDu0fXZLpZ5VBnDzIhLdaeA7aYdVMjOf): failed to open stream: No such file or directory
I have tried re installing homestead/laravel/vagrant I have also ran the following and more artisan command again and again:
php artisan config:cache
php artisan cache:clear
php artisan optimize
I have also ran chmod privileges on files/folders inside of my vagrant box but still nothing gets me past this error, any ideas? The project itself is created perfectly fine inside of my vm.
Delete all the files in yourProject/storage/framework/sessions, then run php artisan view:clear and php artisan config:clear

Have to keep running view:clear otherwise I get a permission denied error

Each time I edit a blade file I have to run php artisan view:clear in order for the page to load correctly otherwise I get the following error
ErrorException (E_ERROR)
file_put_contents(/home/vagrant/Code/app/storage/framework/views/fsfsawe8bde92c95bad12ddfcfaea1738afsac0.php): failed to open stream: Permission denied (View: /home/vagrant/Code/app/resources/views/header.blade.php)
I am using the following:
Homestead v7.14.2
Vagrant (2.1.2)
I also recently ran sudo apt-get upgrade on my vm.
The Homestead update script did not install php 7.2 so I did that manually.
The permissions on my storage folders are all 777.
How do I setup laravel so that I do not have to keep running php artisan view:clear each time I make a change?
What has worked for me regarding this same issue, is to change apache or nginx to run as your local user or another that you have created and then change the laravel application directory ownership to this user using a chmod user -R. Or conversely you could change the project ownership to the web server user account.

artisan key generate error

I am trying to duplicate a laravel project on my local machine (windows, wamp, laravel 5.4)
I copied all the files and folders beside the vendor folder to a new folder.
I ran composer install, artisan cache:clear and composer dump-autoload
But, when I ran artisan key:generate I get this error:
file_put_contents: failed to open
stream: Permission denied.
Why is that and how do I solve it?
Thank you
You need to run:
chmod -R 777 storage/*
sometimes sudo chmod -R 777 storage/*
then php artisan cache:clear
then php artisan key:generate
This is due to the file permissions not being writeable. Seems to be quite a regular occurrence this happens but the steps above will rectify your problem.
To utilise more of these commands on a windows you can use a program called Git Bash. It's a very neat and handy tool: Git Bash
If you do not wish to use git bash you can take this approach:
Locate the Storage folder within your file explorer. Right click and press permissions and change the security permissions to allow write access.

Laravel 5 show ErrorException file_put_contents failed to open stream: No such file or directory

I have a project on Laravel 5 and I work with it at the office and at home too. It works fine, but recently at home it stopped working. Laravel show me two ErrorException
file_put_contents(G:\project\storage\framework\views/751d8a0fd8a7d4138c09ceb6a34bb377aa2d6265.php):
failed to open stream: No such file or directory
and
file_put_contents(G:\project\storage\framework/sessions/aIXycR4LIAUBVIqZu0T590paOMIpV8vfZGIroEp0):
failed to open stream: No such file or directory
I'm searching problem decision with Google and find information about correct rights. All advice is about Linux, but I'am work in Windows at the office and at home too.
When I try to clear application cache and view cache, artisan talk to me - ...cleared. But cache data and views are present in storage.
How can I fix this problem?
The best way to solve this problem is, go to directory laravel/bootstrap/cache and delete config.php file. or you can rename it as well like config.php.old
And your problem will be fixed.
You should typically run the php artisan config:cache command as part of your production deployment routine. As a solution to your problem, I suggest you recreate the cache file, for faster configuration loading.
To do this, run the following Artisan commands on your command line
php artisan cache:clear
php artisan config:cache
You can programmatically execute the command by adding the following to your routes:
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('cache:clear');
$exitCode = Artisan::call('config:cache');
return 'DONE'; //Return anything
});
And then call the clear-cache route from your browser.
After some research I understand - I have very similar, but different root project locations and its cached in /bootstrap/cache. After cache clearing project started.
Actually I faced this issue when I moved my project from server to local.
in
storage/framework
four basic folders are required cache, sessions, testing, views
In My case sessions was missing might be in gitignore.
So I manually created session folder and refreshed browser and it was working.
So any of the missing folder if we delete this problem can be solved.
I solved this problem via creating storage\framework\sessions folder.
Apache + WSL on windows
This is a silly mistake, and a different answer compared to the others, but I'll add it because it happened to me.
If you use WSL (linux bash on windows) to manage your laravel application, while using your windows apache to run your server, then running any caching commands in the wsl will store the linux path rather than the windows path to the sessions and other folders.
Solution
Simply run the cache clearing commands in the powershell, rather than in WSL.
$ php artisan optimize
Was enough for me.
This type of issue generally occurs while migrating one server to another, one folder to another. Laravel keeps the cache and configuration (file name ) when the folder is different then this problem occurs.
Solution Run Following command:
php artisan config:cache
https://laravel.com/docs/5.6/configuration#configuration-caching
Try with these commands that have been useful with those errors
path\project\storage\framework\views...
php artisan view:clear
path\project\storage\framework/sessions...
php artisan config:cache
I deleted the file /public_html/bootstrap/cache/config.php
Then I ran php artisan config:cache
In case of shared hosting when you do not have command line access simply navigate to laravel/bootstrap/cache folder and delete (or rename) config.php.
This happens when you shift your website from local to live server or vice versa.
Simply go to bootstrap/cache and delete config.php.
The reason is related to cache or permission.
Firstly, go to directory laravel/bootstrap/cache and delete all files from cache.
php artisan cache:clear
php artisan config:clear
php artisan config:cache
If the errors still happen. It may relates to permission
Let's try command below (In my case user&group of laravel is nginx)
sudo chgrp -R nginx storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache
If you are running laravel inside docker then access its filesystem
$ docker exec -it name-of-laravel-container /bin/bash
Next navigate to your laravel projects root directory. Make sure that you have inside storage/framework folder:
cache
sessions
testing
views
And they should be both readable and writable.
If nothing work try the following in the production environment
1-
composer install --optimize-autoloader --no-dev
2-
php artisan cache:clear
3-
php artisan config:clear
4-
php artisan view:clear
5-
php artisan config:cache
6-
php artisan route:cache
Works for me
Changing name of /bootstrap/cache/config.php to config.php.old doesn't work for me
neither clearing cache with the commands artisan
php artisan config:clear
php artisan cache:clear
php artisan config:cache
And for some weird reason I can't change permission for the owner on the directories, so my solution was running my IDE (Visual Studio Code) as admin, and everything works.
My project is in an F:/ path of another disk.
The reason for this problem is the cache files in localhost. According to that I've tried several things as follows to clear the cache on my project, but every time I've failed.
Tried to clear cahe commands by changing web.php file (with artisan codes)
Tried to clear cache by connecting SSH (via PUTTY)
Tried to host my project in Sub domain within create a new Public directory
So I've found a solution for this problem after each and every above steps failed and it worked for me perfectly. I deleted the cache.php file in host_route/bootstrap/cache directory.
Maybe there is an issue with your composer file. You could try:
composer install installs the vendor packages according to
composer.lock (or creates composer.lock if not present),
composer update always regenerates composer.lock and installs the
lastest versions of available packages based on composer.json
composer dump-autoload won’t download a thing. It just regenerates
the list of all classes that need to be included in the project (autoload_classmap.php). Ideal for when you have a new class inside your project. Ideally, you execute composer dump-autoload -o , for a
faster load of your webpages. The only reason it is not default, is because it takes a bit longer to generate (but is only slightly noticeable)
source
In my case it was not anything that could be fixed with php artisan commands. The issue was folder permissions for the /storage folder. The error did not make that clear.
The solution that worked for me is to just serve the app as admin
if you are
On mac or linux use sudo php artisan serve
On Windows try to open CMD as an adminstrator and then go to project directory and run php artisan serve
Clearing the contents of storage/framework/cache did the trick for me.
I had similar problems because of .gitignore for the /storage folder on first machine, then cloned repository on second machine and laravel was revision to write down sessions cache
So, manually creating folder /storage/sessions might be an solution..
This did the magic for me. chmod -Rf 0777 storage
In my case, I set APP_DEBUG=false since it is a production server, I decided to set it back to true and then it showed Missing BC Math or GMP extension
That is how I solved my own issue, setting APP_DEBUG=true might not work for everybody.
I used Laravel 8, This is my solution:
Goto:
storage/framework/cache/data
set permission directory data is 777
I went all the way, but I did not get the answer.
I just rename cache folder in storage/framework/ to cache1 and solved my problem.
I solved it clearing the content of:
/laravel/storage/framework/views
Then all the views were created again in that folder.
In my case these commands didn't fix it:
php artisan view:cache
php artisan route:cache
php artisan config:cache
I'm using Laravel 8 and in my case it seems that it was an issue with the permissions.

Categories