ioanandrei's avatar

Failed to open stream: Permission denied

Hello,guys

I'm new to laravel and macOs. I just installed a laravel project and when i try to access the public directory, i get this error:

The stream or file "/opt/lampp/htdocs/msi/storage/logs/laravel.log" could not be opened: failed to open stream: Permission denied

I saw other discussions, but not even one command in terminal is working for me(the commands from the other discussions based on this subject).

I tried the commands from this disscusion https://laracasts.com/discuss/channels/general-discussion/laravel-framework-file-permission-security , but i get only errors like:

chmod: /storage/logs/laravel.log: No such file or directory or chgrp: www-data: illegal group name

I know i'm doing something wrong, but i don't know what. When i run the commands from the link above, should i target the project directory or another directory?

Edit: i'm using XAMPP.

0 likes
9 replies
Yapiyo's avatar

This is always a though one. should only need these two command

sudo chgrp -R www-data storage bootstrap/cache
sudo chmod -R ug+rwx storage bootstrap/cache

www-data must be the group of the process. if you are using Xamp you can open the apache conf file and search for: "User" or "Group"

looking on the first message:

 "chmod: /storage/logs/laravel.log:"

make sure you are in your project root and only execute the commands op the two directories: "storage" and "bootstrap/cache" (the storage is the most important one)

The second message:

" directory or chgrp: www-data: illegal group name"

tells you www-data is a non-existent group name (see the conf part)

hope it helps

1 like
ioanandrei's avatar

Just to see if i understand...insteed of www-data should i put something else?

update: I made it using R -777, but i understand that this is not the good way to do it.If i succeed doing this way, the 777 will be overwrite?

Yapiyo's avatar

I am not a 100% sure. i think it is only overwrite the group given in the command. if its good or bad is more a environment thing. On my public server it is a no go. But on my laptop i run my Apache as the logged in user for convenience because it it is non public and i only run my own code. The files and directories are always owned by the correct user (and i am to lazy).

Reading that you are using Xamp i think you are not running a public server so it is fine but do keep it in mind if you want to go public

ioanandrei's avatar

ok

and what should i put instead of www-data? beacuse if i copy+paste and run the first command from you, it will give me an error like this: chgrp: www-data: illegal group name

Yapiyo's avatar

Sorry, I did not really put that clear in the message. When you open Xamp you should search for a button to open the Apache configuration file and search for: "Group".

I think on default it is: Group daemon. But i am not sure

So the command should become:

sudo chgrp -R daemon storage bootstrap/cache

ioanandrei's avatar

This is what i get

chgrp: storage: Operation not permitted chgrp: bootstrap/cache/services.php: Operation not permitted chgrp: bootstrap/cache/.gitignore: Operation not permitted chgrp: bootstrap/cache: Operation not permitted

ioanandrei's avatar

I tried to create a new project and after i run the su chgrp -R daemon storage bootstrap/cache, i get this:

chgrp: storage/framework/testing/.gitignore: Operation not permitted chgrp: storage/framework/testing: Operation not permitted chgrp: storage/framework/cache/.gitignore: Operation not permitted chgrp: storage/framework/cache: Operation not permitted chgrp: storage/framework/views/.gitignore: Operation not permitted chgrp: storage/framework/views: Operation not permitted chgrp: storage/framework/.gitignore: Operation not permitted chgrp: storage/framework/sessions/.gitignore: Operation not permitted chgrp: storage/framework/sessions: Operation not permitted chgrp: storage/framework: Operation not permitted chgrp: storage/logs/.gitignore: Operation not permitted chgrp: storage/logs: Operation not permitted chgrp: storage/app/.gitignore: Operation not permitted chgrp: storage/app/public/.gitignore: Operation not permitted chgrp: storage/app/public: Operation not permitted chgrp: storage/app: Operation not permitted chgrp: storage: Operation not permitted chgrp: bootstrap/cache/services.php: Operation not permitted chgrp: bootstrap/cache/.gitignore: Operation not permitted chgrp: bootstrap/cache: Operation not permitted

Yapiyo's avatar

This is not going to be an easy one. I hope you forgot to use sudo.

What is possible your webfiles are on a disk location that falls under the OSX oh no you didn't protection. These location are protected against these kind of commands.

Try setting the Xamp webfolder to a folder under your user like /(osxpath)/(yourusername)/document/web. And then move the files.

ioanandrei's avatar

I don't know how to do that...I think i will try to do it on another computer just to see if there it's working.

Please or to participate in this conversation.