Unable to change storage/framework permissions - php

I honestly don't know what I am doing wrong. I have been trying to work on the business logic of a Laravel application I am working on, but now I want to see my views in a browser, and no matter what I do I get an exception relating to the file permissions of storage/framework. The latest one is
file_put_contents(/home/vagrant/Code/bitpaigow/storage/framework/sessions/VMdtCxzQwaGVremFgwFzj9HnNRkvKuDOMzUsWrXP): failed to open stream: No such file or directory
I have so far tried two different servers: Homestead and Laravel's serve command. What I understand is the problem now is my permissions. Homestead, hoping to allow access to those directories from my Laravel app, however, no matter what I do I always run into an error relating to these folders having the wrong permissions.
I have tried chmod 777 storage/framework but I still get the same error. Any help would be great. Thanks.

Related

"failed to open stream: Permission denied" after 777 my entire app

I'm growing several grey hairs trying to work this one out.
All of a sudden in my Laravel project, I can't upload any files to my symlinked public/storage directly as it's complaining about permissions.
I then 777'ed every single file in the app (I know, I know), and it's still complaining about permissions. I've also run composer dump-autoload, which never seems to do anything but I thought I'd give it a go anyway.
Does anyone know what else I can try? I can verify everything is 777, so I can't see why any permissions would fail...
Gah, sorry guys, this was a bit of a red herring.
777'ing everything wasn't working because the uploaded files were being set to 644 (so my manual 777 was only being applied to files that already existed)
For future reference, if anyone's using Laravel and a queued job can't access a 644 file, set the file to 664 immediately after upload (apache owns the uploaded file, but www-data (or ec2-user) is the one trying to access when queued).
SE Linux might be a possible culprit, because the policies change in some cases, eg. when there are broken modules, it will mess up. that would be setsebool -P httpd_read_user_content 1 (if this should throw an error, manually deleting the broken modules is the only thing that helps).

Symfony 2.8 can't write in /var/lib/php/sessions/

I'm a bit confused here in Symfony functionality terms. I have a website which is supposed to write sessions in /var/lib/php/sessions/. I'm confused right there, because in /var/www/html/myproject/ everything is recursively property of www-data:www-data (yes, I'm using Apache). However the owner of /var/lib/php/sessions/ is root, so when Apache tries to write there, I get a 500 server error regarding writing permissions in that directory.
I have divided opinions here. Some people advice me to modify config.yml to manage sessions inside the project directory, while other people say that is a really bad practice. But, how do I get everything targeting /var/lib/php/sessions/ without that file permission error?
Here's what I get via Apache URL:
Oops! An Error Occurred
The server returned a "500 Internal Server Error".
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.
Here's what I get via php development webserver:
Warning: SessionHandler::read(): open(/var/lib/php/sessions/sess_u3eg1842nlpkbm0rvddrq37dc2, O_RDWR) failed: Permission denied (13)
500 Internal Server Error - ContextErrorException
I really hope you can help me.
In order to create a file the user must have write and execute permission on the directory.
mkdir /tmp/foo
chmod 300 /tmp/foo
touch /tmp/foo/bar
test -e /tmp/foo/bar
In your case setting the 'other' permissions to 3 would allow www-data to write to it. chmod o+wx /var/lib/php/sessions/
In order to remove a file the user must also have write and execute permission on the directory.
In order to list the file names in a directory the user must have read permission on the directory. Note that if you know the filename it's not required to have permissions for listing the directory.
In order to list the properties of a file the user must have execute permission on the directory.
On my computer the permission for /var/lib/php/sessions is drwx-wx-wt. The t indicates execute & sticky bit. Sticky bit for directories means only the owner can delete it.
See Unix File and Directory Permissions and Modes by Wayne Pollock for more info.

Strange error with folder permissions (mkdir)

I am running a nginx server and php5, but I am not able to get mkdir in php working. I always get a permission denied error.
The user, who is running nginx is www in group www, the same applies for php and my folder where I want to create a new one is also hold by www.
It only works when I set the folder permissions to 777, with 775 I can't get it working.
The curious thing is, when I try to create a folder in the terminal as www user it works without any issues.
Any help would be really appreciated, because I have been struggling with this error for 2 days.
That's probably because problem with PHP module configuration. You have to set correct user there, too.
Check this documentation.

laravel 5.1 file_put_contents wrong path

So I am using laravel 5.1 on ubuntu with nginx and php-fpm, I am having a little issue with my sessions. I have done all the permissions (chown to nginx/php user and group and chmod 777 on storage) however I think there is another issue.
The session file is created as I can see it on the server however when laravel is trying to write to it I don't think it can find the file see bellow:
at HandleExceptions->handleError('2', 'file_put_contents(/54dc94489b4c137d744f0427ce2c7e5e): failed to open stream: Permission denied',
Is there an issue with laravel finding the session path ? I am not really sure what to do, I have edited the filtsystem class and hard coded the path to the session directory however that isn't the correct solution.
I had to create 'storage/framework/views'

Laravel Permissions

I did an installation of laravel, and copied the files to a xampp hosted folder on the same machine. When I try to visit my index.php file however, I'm getting the following error:
Error in exception handler: The stream or file "/Applications/XAMPP/xamppfiles/htdocs/TestManagement/app/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/TestManagement/bootstrap/compiled.php:8969
I'm always a bit hesitant about changing permissions, as I've done some pretty bad chmodding before. Was wondering if there was a rule of thumb or expected behavior for this. Should this be 777 or 755?
The Laravel and Monolog documentation appear to contain no reference to the 'right' permissions. You can make it work with restrictive permissions, but be aware of all of the users that need access:
the web server user
cron user (if you run artisan commands via cron)
anyone who manually runs artisan commands.
They will each need read/write permissions to the log files.
Always use 777 on app/storage folder

Categories