Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

duanyespindola's avatar

Sail project with wrong permission... am I missing something?

I am trying to create a brand new Laravel App using sail.

I´m on a Windows11 machine with WSL2 and a Ubuntu 220.04 Distro The user is "root"

Step 1

curl -s https://laravel.build/example-app | bash

no problem at all!

Step 2

cd example-app
sail up

no error message

Step 3 (the first permission problem)

In the browser, acessing localhost :

The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied ...

So I use chmod 775 -R ./storage/ and move ahead.

Step 4

sail composer require laravel/breeze --dev and receive the error ./composer.json is not writable.

So...

Than I stoped and came here, ´cause I don´t think I should be changing the chmod of all files all the time.

Am I missing something ??

0 likes
8 replies
DavidSpooner's avatar

If you have composer installed on your host machine, I think you can just do composer require from the root of the project without the "sail" keyword.

duanyespindola's avatar

@DavidSpooner You are probaly right, but I´m trying not install anything on this distro and use everthing on containers... that is the goal ! Thanks for you time and thoughts

1 like
duanyespindola's avatar

@MohamedTammam It really did the trick! Thanks!

  • In WSL2 jump into the docker container as root by running this command vendor/bin/sail root-shell.
  • Move up one directory cd...
  • Recursively change the owner and group of the html folder to sail chown -R sail:sail html .
  • Confirm the change ls -la. You should see the group and user sail on all the files and folders.
  • Exit the container exit.
10 likes
duanyespindola's avatar

Let me add a litle note here, because when I was looking for a solution I found a lot of comments about the root user.

So I decided to test, again, but now using a nonroot user.

That is what I found:

  • Remember: I was using the WSL2 "root" user, so: adduser myNonRootUser to create the user.

I was getting "Docker is not running" message because this user was not on the "docker" group.

  • sudo usermod -aG docker myNonRootUser to put the user into the "docker" group.

  • Then su MyNonRootUser to change for the new user.

  • Then I did the steps 1 and 2 again and ... same step 3 error.. but this time only chmod 777 did the trick

  • To finish, the sail composer require did not worked as well ... './composer.json is not writable'

Conclusion: its has nothing to do with root / nonroot. Just use the @mohamedtammam pointed solution and move on

vural2123's avatar

It sounds like there may be a permissions issue with the files and directories in your Laravel app.

One possible cause of this issue is that the user running the sail command does not have the necessary permissions to write to the directories and files in the app.

In the case you are running the command as root user, it's not the best practice. You should use a non-root user with proper permissions to run the command.

You can try to change the ownership of the files and directories to the user running the sail command, and then set the appropriate permissions using chmod.

You can also try to run the sail command using sudo to temporarily elevate your user's permissions, but this is not recommended as it can lead to security issues.

Alternatively, you can try to use a tool like acl to set permissions on the files and directories in a more fine-grained way.

It's also worth checking the documentation for the sail package, to see if there are any recommendations for resolving permission issues.

Please let me know if this helps or if you have any additional questions.

warpig's avatar

I still cannot install filament, so far i got these permission set to the sail user:

drwxr-xr-x  3 root root 4096 Jun  1 14:41 .
drwxr-xr-x  1 root root 4096 Jun  1 14:41 ..
drwxr-xr-x 12 sail sail 4096 Jun  1 16:40 html
In RequireCommand.php line 142:
                                                                                
  file_put_contents(./composer.json): Failed to open stream: Permission denied

Thanks

mgolshan's avatar

Try this:

./vendor/bin/sail up -d
sudo adduser sail --disabled-password
sudo usermod -aG sail sail
sudo usermod -aG sail ${USER}
./vendor/bin/sail root-shell
cd ../
chown -R sail:sail html
2 likes

Please or to participate in this conversation.