valentinmorice's avatar

Sail: Permission Denied

Hi, I'm setting up a new Laravel project using Sail, on Ubuntu 22.04 and am running in quite a few problems. When visiting http://localhost I am greeted with many error messages, such as:

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

I've managed to solve this error by changing permissions on the storage folder and get to the standard Laravel homepage, but when trying to run a migration, I'm again denied permission.

file_put_contents(/var/www/html/database/migrations/2022_08_20_145015_create_users_table.php): Failed to open stream: Permission denied

I've searched through the web for solutions and found a few similar cases, but the fixes I've tried only solve part of the problem. Thank you for your help!

https://github.com/laravel/sail/issues/81

https://github.com/aschmelyun/docker-compose-laravel/issues/49

I'd like to avoid having to chmod -R 777 my whole project folder.

0 likes
15 replies
Sinnbeck's avatar

Sounds like docker isn't running as the same user as the owner of the folders. What is your os?

Sinnbeck's avatar

@valentinmorice try deleting the containers and recreate them with your user. Sounds like they were started as a wrong user

Sinnbeck's avatar

@valentinmorice really stange. I have been using docker on Ubuntu for the last 3 years on multiple computers and haven't had this problem once. Personally I use lando instead of sail

valentinmorice's avatar

I've solved the issue by running the following commands:

sail root-shell
cd ..
chown -R sail:sail html

Edit: It does not work, as you can run commands using sail, but can't edit the files from the host anymore.

5 likes
Sinnbeck's avatar

@valentinmorice cool. I am still curious why it was necessary. Maybe your user isn't id 1000? Is the files still owned by you on the host OS?

Mark your answer as best to set the thread as solved

valentinmorice's avatar
valentinmorice
OP
Best Answer
Level 10

@Sinnbeck Well, actually I spoke too fast, realized I couldn't edit the files from the host after changing the owner to sail (obviously). I've uninstalled Docker Desktop and now everything do work fine.

2 likes
skinnyvin's avatar

@valentinmorice I'm experiencing this on Ubuntu 23.04.

If I use the shell within the host it is fine. As soon as I try to do anything in my editor outside of the container I get permissions errors - not just for logs, for creating any files in any directories.

However, on my work machine I have never experienced this issue!

lutfiandri's avatar
  • start sail
sail up
  • open in other terminal and start sail shell (from docker container)
sail shell
  • change storage permissions
chmod -R 777 /var/www/html/storage
chown -R www-data:www-data /var/www/html/storage
  • restart sail app
exit
sail down
sail up
8 likes
skinnyvin's avatar

Just an update for anyone struggling with this in mid 2023! I'm on Ubuntu.

To resolve the issue I uninstalled docker completely. Then reinstalled following the instructions on the docker site for the docker engine, cli and composer - I did not reinstall docker-desktop.

I also had to remove the old docker configs from ~/.docker (I chose to mv them initially and deleted after).

After this everything seems to function correctly.

2 likes
uberneu's avatar

@skinnyvin Same here, removed docker-desktop completely and everything works the way it used to. Thanks for the input on this post.

1 like
Davidaprilio's avatar

same here, after run sail up -d i got ownership 1000:sail and if changed to sail:sail it's worked, but got other issue like @valentinmorice. i try reinstaling docker end remove docker-desktop full but this still got same issue used Ubuntu 22.04.4 LTS

Please or to participate in this conversation.