Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage folder write permissions fail on newly installed Sail #81

Closed
cyrrill opened this issue Mar 25, 2021 · 100 comments
Closed

Storage folder write permissions fail on newly installed Sail #81

cyrrill opened this issue Mar 25, 2021 · 100 comments

Comments

@cyrrill
Copy link

cyrrill commented Mar 25, 2021

  • Sail Version: 1.4.9
  • Laravel Version: 8.33.1
  • PHP Version: 8.0
  • Database Driver & Version: MySQL 8.0.23-1debian10

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()

(...)
@cyrrill
Copy link
Author

cyrrill commented Mar 25, 2021

I've rebuilt the images to the PHP 7.4 version, used sail build --no-cache and the same permissions issue persists.

@driesvints
Copy link
Member

Hi there,

Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

@cyrrill
Copy link
Author

cyrrill commented Mar 25, 2021

@driesvints,
"Please only use this issue tracker for reporting bugs with the library itself."

I installed Sail exactly step by step as instructed in the official guide, and it reports a malfunction upon first use, I would classify this as a bug.

@driesvints
Copy link
Member

@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.

@cyrrill
Copy link
Author

cyrrill commented Mar 26, 2021

Currently on the host the storage folder is at 775, and when I chmod 777 -R storage, Sail works, but that carries the obvious security issues.

The issue appears possibly to be with the WWWGROUP & WWWUSER env vars.

WWWUSER is set to 1000 and WWWGROUP shows undefined.

Don't really have time to delve into making this work at the moment, was hoping it would work out of the box. (and it likely does for freshly installed L8 apps)

Thanks for getting back to me though, will try this another time or check on Laracasts as you suggest 👍

@cyrrill
Copy link
Author

cyrrill commented Mar 29, 2021

@MaybeThisIsRu
Copy link

@cyrrill Are you running Docker in rootless mode?

@cyrrill
Copy link
Author

cyrrill commented Apr 3, 2021

Hi @hirusi, thanks for following up on this. On first attempt I was running it as default which requires root, given that the Dockerfile requires access to port 80 which is privileged on Linux. After seeing the issue with the permissions, I installed rootless mode and allowed port 80 via net.ipv4.ip_unprivileged_port_start=0 in sysctl. The issue persists: a storage folder with 775 permissions on the host appears non-writable to the sail user inside the container. So far, the only way to allow writes to storage is by setting it to 777 on the host.

@MaybeThisIsRu
Copy link

MaybeThisIsRu commented Apr 4, 2021

I'm writing down my discoveries and attempts to make 775 work over here, but unfortunately, like you, I haven't had a breakthrough on a clean solution yet.

I'm not sure how far I'll push my attempts, but I have subscribed to the thread here and would love to keep up with what anyone else is attempting.

Edit: I saw you mentioned somewhere up that "it probably works fine on a fresh L8 app." That's not the case for me.

@Martijn-Bos
Copy link

This bug is also present here. I can't write to the laravel.log in the storage folder after going through the Laravel installation guide. I'm using WIN10,docker desktop+ ubuntu20.04 WSL2.

This is not an isolated incident

@NicolasPereira
Copy link

I have this problem whenever I use laravel sail, both in new and old applications!

I use Linux Ubuntu 20.04

I fix this problem these problems using inside the project repository:

$ sudo chmod -R 777 storage

I tried to write this command using sail bash and was unsuccessful!

This is not an isolated incident

@peterbabic
Copy link

peterbabic commented Sep 7, 2021

I also have many many issues with permissions with:

  • storage
  • bootstrap/cache
  • vendor/composer/autoload_namespaces.php (possibly the whole composer folder)

Not sure which user or group are these files/folders meant to belong to. No issues on a machine running Arch however.

@cyrrill
Copy link
Author

cyrrill commented Sep 23, 2021

Hi @driesvints,

There have been 4 other people having this issue. Any chance you could consider having a look again? Or at the very least update the documentation to explain how this is supposed to work?

@cyrrill
Copy link
Author

cyrrill commented Sep 23, 2021

Is chmod 777 really the only option we have?

@tomheadifen
Copy link

tomheadifen commented Oct 1, 2021

I've had this issue with WSL2.

The Problem

Laravel Sail executes all commands using the 'sail' user and you can see this in the vendor/laravel/sail/bin/sail file. The sail user is setup by default when the container is created. The issue is that the html folder has the group and user set to 'root' so whenever you try and run a sail command that needs permissions you run into an error.

The solution I did was to change the owners and groups of the html folder to their respective group so that the sail command will work.

Temp fix

  • 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.

You should now stop running into permission errors on any sail command you run such as when you install jetstream.

Potential Permanent Solution

My guess is that on mac this problem doesn't happen because the user groups are set up correctly however on WSL2 they are set as root. Perhaps someone on a mac can let me know what the users and groups are set to for the html folder in the docker container. If they aren't set to root by default that could be the bug.

Edit: This ended out being related to me running WSL2 as a root user instead of my regular user.

@joveice
Copy link

joveice commented Oct 5, 2021

I have installed docker the recommended way from docker docs.
Followed https://laravel.com/docs/8.x/installation#getting-started-on-linux
Sail Version: 1.11.0
Laravel Version: 8.63.0
PHP Version: 7.4.24
OS: Fedora 34

After the install was done I did sail up and headed to localhost and was presented with the same message.

Tmp fix from @tomheadifen by changing the owner of the project worked for me

@klipitkas
Copy link

This happens to me (Ubuntu 20.04 - docker Server Version: 20.10.1) as well when using sail, there is definitely something wrong with permissions here.

@tomheadifen
Copy link

Ok I've figured out my issue. I was running as wls2 as a root user and sail is not built to be running as the root user.

Solutions

  1. Change back to your regular user instead of root.
  2. Do the above steps in my previous post to continue running as root.

@NicolasPereira
Copy link

NicolasPereira commented Nov 26, 2021

Hi guys, how are you?

I believe I have figured out the problem to solve the problems, at least on linux!

For MacOS and Windows it should have similar configuration but I didn't perform the tests.

When we are running something with docker, we need to inform that our user "external" to the service container has permission to create, change files inside the service container.

To do this, just run this comand in your terminal before run sail up

$ export WWWUSER=${WWWUSER:-$UID}
$ export WWWGROUP=${WWWGROUP:-$(id -g)}

I found this solution in this question on StackOverflow

If you don't want to export these variables, you can use the following configuration within the service that runs the application in your docker-compose.yml

        environment:
            WWWUSER: '1000'

A point of attention, the value 1000 is my user's UID, follow the article to understand about UID and how to find your user's UID

If I knew how Sail works I would create a PR with these updates, it would be interesting if Laravel's team look my solution

ps: Sorry for my English, I'm learning and I used google translate to help me

Regards,

Nicolas

@LiamKarlMitchell
Copy link

Solves it, and if your user id is not 1000 just set it in .env file.

    environment:
      WWWUSER: '${WWWUSER:-1000}'

@maritaria
Copy link

For me the problem in the end was that I was using WSL2 with root as default user.
The runtime avoids updating the sail user id if it is zero (code).
So if you are hell-bound on using root user, then you'll have to publish the sail files and patch the start-container script of the php runtime you are using.

I'm just going back to a regular user account instead of keeping on using root.

@LoneWolf1227
Copy link

I also have this problem with permissions in sail(

@Kane-R-G
Copy link

using one of the artisan commands works for m

php artisan optimize <--- this did not work
php artisan optimise:clear <-- this one does work.

@xpharsh
Copy link

xpharsh commented Mar 2, 2022

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.

@aldesrahim
Copy link

Hi, I have been struggling with this issue recently, I am using windows 10 and WSL2 and start/run sail container from Docker Desktop, turns out it was a mistake, I should have run it from WSL by running sail up -d command since when you look at script file it contains what @NicolasPereira mentions, and it's been running fine.

@techinfocomp
Copy link

Hi, I have been struggling with this issue recently, I am using windows 10 and WSL2 and start/run sail container from Docker Desktop, turns out it was a mistake, I should have run it from WSL by running sail up -d command since when you look at script file it contains what @NicolasPereira mentions, and it's been running fine.

Have you tried this ?
sail artisan storage:link

@aldesrahim
Copy link

aldesrahim commented Mar 24, 2022 via email

@xpharsh
Copy link

xpharsh commented Mar 24, 2022

Yes, and it worked !

On Thu, Mar 24, 2022, 2:30 PM Techinfocomp @.> wrote: Hi, I have been struggling with this issue recently, I am using windows 10 and WSL2 and start/run sail container from Docker Desktop, turns out it was a mistake, I should have run it from WSL by running sail up -d command since when you look at script file it contains what @NicolasPereira https://github.com/NicolasPereira mentions, and it's been running fine. Have you tried this ? sail artisan storage:link — Reply to this email directly, view it on GitHub <#81 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI3BT3BAMLIZ5GFYFY53FXTVBQK2PANCNFSM4ZYXY44Q . You are receiving this because you commented.Message ID: @.>

That's Nice. Have a good day.

@aldesrahim
Copy link

aldesrahim commented Mar 24, 2022 via email

@p-bogachev
Copy link

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
Copy link

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
Copy link

@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
Copy link

matthiascw commented May 27, 2023

@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
Copy link

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

@erictourigny23
Copy link

erictourigny23 commented Jun 10, 2023

@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
Copy link

@basvdhoeven Glad to hear this!

@cyrrill
Copy link
Author

cyrrill commented Jun 11, 2023

@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
Copy link

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

@cyrrill
Copy link
Author

cyrrill commented Jun 11, 2023

@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
Copy link

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

@nikspyratos
Copy link

nikspyratos commented Jun 21, 2023

@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
Copy link
Member

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
Copy link
Author

cyrrill commented Jul 8, 2023

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

@basvdhoeven
Copy link

@driesvints I've made a PR which adds a warning about this issue to the docs (laravel/docs#8898).

@basvdhoeven
Copy link

The docs have been updated: laravel/docs#8901.

@Shelob9
Copy link

Shelob9 commented Aug 7, 2023

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
Copy link

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
Copy link

simtrax commented Aug 23, 2023

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
Copy link

Dasher83 commented Aug 28, 2023

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
Copy link

@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
Copy link

@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
Copy link

For me the solution was running:

sail artisan route:clear
sail artisan config:clear
sail artisan cache:clear

@mahlenko
Copy link

mahlenko commented Nov 2, 2023

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
Copy link

jimhlad commented Nov 16, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests