laravel / sail

Docker files for running a basic Laravel application.
https://laravel.com/docs/sail
MIT License
1.65k stars 473 forks source link

Storage folder write permissions fail on newly installed Sail #81

Closed cyrrill closed 3 years ago

cyrrill commented 3 years ago

Description:

Unable to write to storage folder.

image

Steps To Reproduce:

I have installed Sail into an existing Laravel 8 application as per the installation guide. The container and associated services come up and yield no errors.

image

When I attempt to access the application from the browser, the exception mentioned above shows up.

Normally, all you need to do is chmod and/or chown the /storage/ folder in order for Laravel to run.

When I try to publish the Dockerfiles (in order to attempt to set permissions), I get this other exception:

 ./vendor/bin/sail artisan sail:publish -vvv

   League\Flysystem\Exception 

  Impossible to create the root directory "/var/www/html/docker/7.4".

  at vendor/league/flysystem/src/Adapter/Local.php:112
    108▕             clearstatcache(false, $root);
    109▕ 
    110▕             if ( ! is_dir($root)) {
    111▕                 $errorMessage = isset($mkdirError['message']) ? $mkdirError['message'] : '';
  ➜ 112▕                 throw new Exception(sprintf('Impossible to create the root directory "%s". %s', $root, $errorMessage));
    113▕             }
    114▕         }
    115▕     }
    116▕ 

  1   vendor/league/flysystem/src/Adapter/Local.php:133
      League\Flysystem\Adapter\Local::ensureDirectory()

  2   vendor/league/flysystem/src/Filesystem.php:102
      League\Flysystem\Adapter\Local::write()

  3   vendor/league/flysystem/src/MountManager.php:597
      League\Flysystem\Filesystem::put()

  4   vendor/laravel/framework/src/Illuminate/Foundation/Console/VendorPublishCommand.php:254
      League\Flysystem\MountManager::put()

  5   vendor/laravel/framework/src/Illuminate/Foundation/Console/VendorPublishCommand.php:238
      Illuminate\Foundation\Console\VendorPublishCommand::moveManagedFiles()

  6   vendor/laravel/framework/src/Illuminate/Foundation/Console/VendorPublishCommand.php:203
      Illuminate\Foundation\Console\VendorPublishCommand::publishDirectory()

  7   vendor/laravel/framework/src/Illuminate/Foundation/Console/VendorPublishCommand.php:166
      Illuminate\Foundation\Console\VendorPublishCommand::publishItem()

(...)
price-brenden commented 1 year ago

I have my Dockerfile add the sail user to a sail group, copy the source code into the image, and change the group ownership of the project to sail. Group owner permissions are sufficient enough for sail to access the file system. If I change the ownership to sail it overwrites and persists my desktops personal folder since I overwrite the copied project with my modified changes by mounting a volume to the same directory. That caused me to have to change them back to my user as root.

iamcarlos94 commented 1 year ago

This is the worst bug I've ever encountered in my life, I've been completely stuck on it for the past 6 days. I've tried Linux, Windows, and Mac, I've reinstalled the OSs at least 3 times each, I've tried over 50 different proposed solutions. This crap simply doesn't work. Please fix this, I beg you.

warmwhisky commented 1 year ago

@iamcarlos94 I had this issue but for me it was having docker installed twice. I installed docker desktop on top of docker engine for Linux which messed up my permission (i think). I never install the desktop version in Linux anymore and use Portainer if I need to see what is going on.

There was also a part I missed which checks UID where is was 1000 but I cannot seem to find that part. It was hidden away in a paragraph link, but there was this post install link I just found regarding groups etc https://docs.docker.com/engine/install/linux-postinstall/ It also says you should log out and log in to get permissions reevaluated. Not login out and in may have caused me a lot of issues too? I was stuck on this for days. It almost blew my head up! I wish I could be more specific about a fix as after you've been repeatedly trying to install over several days you tend you rush over stuff and can miss things.

iamcarlos94 commented 1 year ago

@warmwhisky I have tried both with and without Docker Desktop and both with root and non-root installation. I feel like I've tried everything at this point. This is supposed to be an easy and simple method of properly running Laravel but it's actually anything but. It's very upsetting seeing so many people having the exact same problem yet this issue is closed.

legendarylion commented 1 year ago

@iamcarlos94 Try stopping in docker desktop if it is running, the via command line in the Ubuntu (or your Linux environment) terminal run the following command while in the root directory of your laravel application:

sail up -d

Please report back if this resolved your issue.

On Thu, Dec 22, 2022, 10:04 AM iamcarlos94 @.***> wrote:

@warmwhisky https://github.com/warmwhisky I have tried both with and without Docker Desktop and both with root and non-root installation. I feel like I've tried everything at this point. This is supposed to be an easy and simple method of properly running Laravel but it's actually anything but. It's very upsetting seeing so many people having the exact same problem yet this issue is closed.

— Reply to this email directly, view it on GitHub https://github.com/laravel/sail/issues/81#issuecomment-1362945502, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFTAHIPFCW5XHSH2Q7FZVZTWORUXHANCNFSM4ZYXY44Q . You are receiving this because you commented.Message ID: @.***>

articleten-andy commented 1 year ago

@iamcarlos94 Absolutely, it's nuts isn't it. I've ditched docker now, and reverted back to using Laragon. It's just frustrating because all the new documentaiotn and how to videos going about at the moment, suggest just creating docker instances, and doing all that process, but it's always being shown on macs, which really isn't that helpful for us windows users.

iamcarlos94 commented 1 year ago

@legendarylion I have tried that too as I've seen a lot of people reporting issues with wrong UID when starting the containers from Docker Desktop instead of using the terminal. No luck.

MeepMeeps commented 1 year ago

@iamcarlos94 I added the group and user to my env to get this to work I think. Any good to you?

WWWGROUP=1000
WWWUSER=1000
iamcarlos94 commented 1 year ago

@MeepMeeps I tried that too, it was the first thing I tried actually.

I've decided to give up and go back to Windows + Laragon, far too much time wasted already.

ObjectAssign commented 1 year ago

If you are using Sail (Docker) then try this command

sail artisan storage:link

It's Solve my storage folder access issue, I am using Laravel 9.

This give me: symlink(): Permission denied error

ObjectAssign commented 1 year ago
  • login to sail as root sail root-shell
  • give permission to user sail as chown sail -R storage/

This pretty much solved mostly everything, after doing this: 'chown sail -R ./' it solved everything

MarvvanPal commented 1 year ago

Solution for Linux / OpenSUSE Leap 15.4

I had also a painful road to figure out how to solve a similar error message.

Error (shown via browser or sail php artisan storage:link)

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

Requirements

Solution steps:

Now the error-message is gone.

molteber commented 1 year ago

Not sure if this is related, but I got some issues myself when using docker desktop on ubuntu 22.04. I found this issue on docker desktop for linux: https://github.com/docker/desktop-linux/issues/31

Which in short tells us that they mount root to the current user, and other users inside the container gets a user and group id based on some range. So even if the sail user has id 1000, and the host machine user has id 1000, it will not be the same id when mounted via docker desktop. In my case i got 100999 as the user id

My workaround (from the tips in the issue) was to create a group with the actual id (100999 in my case) and give that group to my account as well. To get it fully working with sail, i then changed the user and group to id 100999 on all the files, as well as giving group write access.

nikspyratos commented 1 year ago

Not sure if this is related, but I got some issues myself when using docker desktop on ubuntu 22.04. I found this issue on docker desktop for linux: docker/desktop-linux#31

Which in short tells us that they mount root to the current user, and other users inside the container gets a user and group id based on some range. So even if the sail user has id 1000, and the host machine user has id 1000, it will not be the same id when mounted via docker desktop. In my case i got 100999 as the user id

My workaround (from the tips in the issue) was to create a group with the actual id (100999 in my case) and give that group to my account as well. To get it fully working with sail, i then changed the user and group to id 100999 on all the files, as well as giving group write access.

From what I've been noticing from my own issue on this today, it's specifically if you run docker rootless on linux (or at least that sounds like the more common case?).

I tried chown -R sail:sail ./ in a container root shell, which ended up flipping the host ownership to root and container ownership to sail. When I did the reverse from the host, I got the 100999 you mentioned.

For now, I've just gone back to root docker. Rootless generally doesn't seem to be well supported.

nwilging commented 1 year ago

i like how this issue is "closed" yet still very active. classic laravel community.

Also experiencing this problem, Docker Desktop on Ubuntu 22. Don't tell me not to use docker desktop, that's not a solution. Write documentation that will allow your app/package to work where it is supposed to work: in docker. Docker desktop is an extremely common installation these days especially with it's recent debut in Linux.

Do better.

Quirinus commented 1 year ago

For anyone facing this issue with the owner being 1000:sail instead of sail:sail, you have probably started the container using Docker (Desktop) instead of using sail up.

Use sail up and the owner will be set correctly - no need to manually set owners or change the WWWUSER.

This was the solution for me. First time everything was working, as I ran sail up, but the second time I started the container trough Docker Desktop, and got the permissions error when doing composer update. Running the container through sail up fixed the problem.

asanikovich commented 1 year ago

First, just try composer install

Ghostyfied commented 1 year ago

A lot of people are saying to start sail from the command line to fix it. For me, I had to remove the image first, since I had already started the container with docker desktop once. For me, these steps did the trick:

  1. Stop the container, does not matter how.
  2. Prune containers: docker container prune
  3. Delete the image: docker rmi sail-8.2/app (change php version to your own)
  4. Rebuild the image and start the container: ./vendor/bin/sail up or sail up
  5. From here on, only start it via command line, never via docker desktop.

Using docker desktop to enter the container terminal seems to not cause any issues.

erictourigny23 commented 1 year ago

For anyone facing the same issue as the one described in the original posting, have a look at Docker contexts. Like images, containers, volumes, and networks, contexts constitute a fundamental entity in the Docker ecosystem.

Without delving too deeply into the details, I found out that the currently selected context affects the behaviour of Docker in many ways, especially in the way that it handles volumes.

Here's my fix: set Docker's context to "default", as opposed to "desktop-linux", through this command in your terminal...

docker context use default

Sail things up again, and everything should be working just fine.

Hence, the bash script that we curl to get a Sail-ready Laravel installation on a development host is designed to be used under the "default" context, as opposed to the "desktop-linux" context. I don't know if that should be interpeted as a bug, but I wonder what is the logic behind having a "desktop-linux" context that is not working on a Linux desktop!!! Damn!

pista7 commented 1 year ago

Hi everyone, here is my humble opinion (excuse my English).

I'm experiencing this same issue today, Ubuntu 22.04, Docker Desktop 4.17, Laravel 10.6, Sail 1.21, fresh installation of everything, following instructions from official web (curl + sail up from terminal), so I think this is an issue that should be taken care of. It's not only related to storage folder, also to artisan make commands and then editing from host.

I'm building a small tutorial for my students (absolut beginners :zap:) and it is weird to say in it "if it doesn't work change to 777" or "do not use Docker Desktop" (when that is exactly what Docker is recommending) or "create a new group, modify permissions, etc"...

I've got it working with @molteber 's suggestion, but it involves changing things in the system and..... I'd rather not do that. @erictourigny23 I couldn't change context cause when I do that I receive a "Docker is not running" message on "sail up". As @iamcarlos94 said, I've tried almost everything in the thread.... Very frustrating.... It should be working without changing anything :sweat_smile:

I'd like to help here, but my knowledge on the issue is too shallow now. I'll keep getting back here and meanwhile learning about how Docker really works :smiley:

erictourigny23 commented 1 year ago

@pista7 Try this...

1) Launch Docker Desktop (make sure it is running on your machine). 2) Open a terminal, and type... docker context use default 3) Get into your application's root directory and type... docker ./vendor/bin/sail up

Let me know if that works. Oh, and send me a screenshot of the output of the following command... docker context ls

pista7 commented 1 year ago

@erictourigny23 Thanks for the reply!

After point 2. I get a message docker: './vendor/bin/sail' is not a docker command.. This is the output of docker context ls:

contextls

If I type sail upI get the old Docker is not running. Earlier this morning, when I first tried, I was restarting Docker Desktop after changing context, to avoid the Docker is not running, but context was back to desktop-linux after restart. So I tried adding a linux env var (DOCKER_CONTEXT) with the same 'not running' result. :shrug:

erictourigny23 commented 1 year ago

@pista7 Sorry to hear this, I know how these things can get so frustrating. Can you send me a screenshot of systemctl --type=service --state=running?

pista7 commented 1 year ago

Hi @erictourigny23! Thanks again for your attention!

I wouldn't like to focus the discussion on my problem. I really appreciate your help, but I believe this needs a general solution for everyone. Something that works right away, as it says in the Laravel docs. Maybe in support forums we could follow your suggestion and find out what is happening.

Maybe the issue could be reopened? Obviously it is not fixed.

jordihuertas commented 1 year ago

This issue should be reopened. I've had to leave Ubuntu and develop on Windows to get this to work as it should.

p-bogachev commented 1 year ago

Hello @erictourigny23! I can't thank you enough for commenting on the solution to my problem. I installed ubuntu 22.04, laravel sail and tried to create something using sail artisan make: but encountered the Permission denied error. Your comment saying to change the docker context from desktop-linux to default solved my problem. Thank you very much again!

dumitriucristian commented 1 year ago

Very disappointed tried everything no results. I will have to remove sail chmod (directory attributes) error: Operation not permitted fchmod (file attributes) error: Operation not permitted warning: cannot set modif./access times for /var/www/html/vendor/composer/a89fac22/php-fig-cache-aa5030c/CHANGELOG.md Operation not permitted

toramanlis commented 1 year ago

@cyrrill I can write to the storage folder just fine and this is the first report we've gotten on it. Please try a support channel.

this is concerning. does this mean when the issue is indeed a bug by your standards, it means it didn't even work on the dev's machine but you published it anyway?

matthiascw commented 1 year ago

@pista7 @erictourigny23 Following your descriptions of the problem I was able to solve it here on Linux Pop OS. Thanks!

I figured out that installing Docker Desktop adds the context desktop-linux. And as @erictourigny23 already pointed out, the permission error occurs when you run docker with sail inside that context.

The reason for me why Docker is not running appeared was, that Docker Desktop is automatically changing the context to desktop-linux as soon as you start it (see https://docs.docker.com/desktop/faqs/linuxfaqs/#context). I did not find the time to dig deeper why the desktop-linux context is not working with sail though but probably the context is messing with the user.

basvdhoeven commented 1 year ago

Thanks a lot @erictourigny23, changing the docker context also solved the issue for me: docker context use default

erictourigny23 commented 1 year ago

@matthiascw Same here: I did not find the time—nor the motivation—to delve into the reason(s) why that so-called « desktop-linux context » is not working with Sail. Honestly, I'm so busy at work, I can't really get any further than this on that specific topic. But I'm still wondering why @cyrrill, the original author of this thread, has once considered that this issue was closed; I mean, even with my fix, this thread should remain open.

erictourigny23 commented 1 year ago

@basvdhoeven Glad to hear this!

cyrrill commented 1 year ago

@matthiascw Same here: I did not find the time—nor the motivation—to delve into the reason(s) why that so-called « desktop-linux context » is not working with Sail. Honestly, I'm so busy at work, I can't really get any further than this on that specific topic. But I'm still wondering why @cyrrill, the original author of this thread, has once considered that this issue was closed; I mean, even with my fix, this thread should remain open.

On the contrary, 2 years and 80+ comments later, I'm still following this thread hoping it actually gets fixed :)

erictourigny23 commented 1 year ago

@cyrrill Oh! Sorry for my wrong assumption, my bad. Have you tried to escalate this issue elsewhere?

cyrrill commented 1 year ago

@erictourigny23 not really, as this is the place where these bugs ought to get reported and the maintainer decided to close it. If you have luck elsewhere, please let us know. 👍

iamcarlos94 commented 1 year ago

Can't believe this is still happening with a completely fresh and stock install of Linux and Docker.

nikspyratos commented 1 year ago

@driesvints Could there at least be some documentation added on this problem? Since it seems rootless or Desktop Docker seem to be the main culprits here and they aren't uncommon setups.

driesvints commented 1 year ago

Hi all. I'm sorry, I unsubscribed after my original comment and didn't see all the replies here. We'd be more than happy to accept a PR to the docs about some notes around this if anyone is willing to send one in. Sorry I didn't give this ticket the attention it deserved.

cyrrill commented 1 year ago

@driesvints would it be possible to change the status of this issue back to open then?

basvdhoeven commented 1 year ago

@driesvints I've made a PR which adds a warning about this issue to the docs (https://github.com/laravel/docs/pull/8898).

basvdhoeven commented 1 year ago

The docs have been updated: https://github.com/laravel/docs/pull/8901.

Shelob9 commented 1 year ago

I was able to solve this by adding to docker-compose, in laravel.test services

environment:
            WWWUSER: '${WWWUSER:-1000}'
            WWWGROUP: '${WWWGROUP:-$(id -g)}'

Before adding this, sail artisan storage:link did not work, after adding it, dowing and upping sail sail artisan storage:link did work.

iqbalatma commented 1 year ago

for me the problem is because i'm using docker desktop. it cause the owner of container directory became root, but my user is sail. when i change the owner from root to sail my host also change into 100999:100999. now i can generate file using artisan make, but i can edit the file because of the ownership became 100999:100999. then i try to change my context to desktop default, but i get error message docker is not running. then i see the error message on service bar (php storm) it says that permission denied. then i try to change ownership on docker socket to my user and everything works fine

simtrax commented 1 year ago

Yesterday I finally got the time to try out sail. Everything worked great up until this strange issue, and since my application handles a lot of files on disk I'm completely shut down. Switching docker context does not work since then Docker wont be running, as some one else has written in a previous comment. Tried with:

        environment:
            WWWUSER: '${WWWUSER:-1000}'
            WWWGROUP: '${WWWGROUP:-$(id -g)}'

Does not work either.

This should be a pretty big show stopper for a lot of people? Why is there no solution available?

Dasher83 commented 1 year ago

I bumped into this as well and read this issue seeking for help. I'm running an Ubuntu 22.04, fresh install. Like most, I installed Docker through Docker desktop.

The suggestions around changing the docker context lead me to uninstall Docker Desktop and to install Docker Engine the way we used to before Docker desktop, through Docker's apt repo (https://docs.docker.com/engine/install/ubuntu/).

I also made the known configurations to be able to run Docker Engine CLI commands without sudo.

With this, the problem went away for me. I know it's not really a solution but until there is one, maybe this will help other people like me trying to learn Laravel from an Ubuntu machine.

warmwhisky commented 1 year ago

@Dasher83 I am pretty sure this is what happened to me early this year. I was install docker on a lot of systems and early in that process I tried docker decktop for Linux and this is the only time I saw this issue. Using the Docker Engine is the way to go.

enesguler0 commented 1 year ago

@pista7 Try this...

  1. Launch Docker Desktop (make sure it is running on your machine).
  2. Open a terminal, and type... docker context use default
  3. Get into your application's root directory and type... docker ./vendor/bin/sail up

Let me know if that works. Oh, and send me a screenshot of the output of the following command... docker context ls

Thank you so much. Thats worked for me.

jenswaern commented 11 months ago

For me the solution was running:

sail artisan route:clear
sail artisan config:clear
sail artisan cache:clear
mahlenko commented 10 months ago

A similar error could occur if you cleaned the cache, not through the sail artisan config:clear command, bus used php from your system php artisan config:clear. Clear the cache using sail container.

jimhlad commented 10 months ago

A similar error could occur if you cleaned the cache, not through the sail artisan config:clear command, bus used php from your system php artisan config:clear. Clear the cache using sail container.

This turned out to be the issue for me. Re-running as sail artisan config:clear fixed it.