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

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

Closed
princerafid01 opened this issue Jun 3, 2021 · 14 comments

Comments

@princerafid01
Copy link

princerafid01 commented Jun 3, 2021

  • Sail Version: 1.4.10
  • Laravel Version: 8.44.0
  • PHP Version: 8.0.0
  • OS: Linux Ubuntu 20.04

Description:

After Installing Sail my app runs on http://localhost but it shows "The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied ". And my localhost user and docker user is also different. I am running docker in rootless mode. How to prevent this error?

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

@princerafid01
Copy link
Author

Can you give me any hint why this error shows? "The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied "

@Kladislav
Copy link

@princerafid01 have the same issue, ./vendor/bin/sail artisan optimize:clear helps me

@princerafid01
Copy link
Author

@Kladislav Thank you. It didn't work for me though.

@HosseyNJF
Copy link

This actually looks like a bug, not a misusage. When running docker in root-less mode, the root user in the container maps to your personal user, and the volume will map with root permissions and ownerships also. But sail creates its own user in the container and runs Laravel with that specific user, resulting in not having access to the project folders.

I tried to fix that by publishing Dockerfiles and editing them so that Laravel gets runned as root, but it still cripples the sail binary file, which uses the -u sail parameter when running docker-compose commands.

@zaimazhar
Copy link

Ran to this problem today. Some notable remarks:

  • "laravel/framework": "^8.40"
  • "laravel/sail": "^1.0.1"
  • "php": "^7.3|^8.0"
  • WSL Ubuntu-20.04
  1. I've updated my WSL and Docker since the last time Sail is working fine.
  2. I tried the solutions stated here and when I typed php -v, error shown;
Command 'php' not found, but can be installed with:
sudo apt install php7.4-cli
  1. I checked on Docker Desktop and found laravelsail/php80-composer is not running (I assumed this the PHP version that Sail should run)
    image

@HosseyNJF
Copy link

Maybe this should get reopened?

@finagin
Copy link
Contributor

finagin commented Aug 22, 2021

laravelsail/php80-composer is not running (I assumed this the PHP version that Sail should run)

@zaimazhar97, this container uses once only for install composer requirements with vendor/laravel/sail/runtimes/(7.4/8.0)/Docker

@chapus
Copy link

chapus commented Aug 26, 2021

Go to container shell
sail root-shell
then
chown -R root:sail /var/www/html/storage

I saw in vendor/laravel/sail/runtimes/8.0/Dockerfile the user is sail

@zaimazhar
Copy link

Hi,

I've been struggling with the same problem again for the past few days too and I would like to share some possible solutions;

  1. I installed both WSL2 (Ubuntu 20.04) and Docker images inside a drive where Windows is not installed using move-wsl. I do not know if this matters but try bringing back WSL2 to where your Windows installed but let Docker images stay in your other drive to save space. In my case still working fine until today.
  2. Try both sudo apt update and sudo apt-get update on where you wanted to install your Laravel application. In my case, I installed it at //wsl$/Ubuntu-20.04/home/<your-created-username-during-wsl2-installation>/<your-laravel-app>
  3. Adding WWWGROUP=1000 and WWWUSER=1000 in your .env file then ./vendor/bin/sail build --no-cache to rebuild the images then sudo ./vendor/bin/sail up -d. I tried without sudo but Docker couldn't expose the port to my local machine.
  4. Never start your Laravel application from the Docker Desktop dashboard, I started it once then I have to sudo ./vendor/bin/sail stop and rebuild them again.

I don't know which step solved the problem for me but this is what I did, in sequence. It might not be the ideal or conventional solution for everyone but it is worth a try.

@ydwis40
Copy link

ydwis40 commented Dec 10, 2021

I've problem with this too. I think supervisord [program:php] should change into variable like this

[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid

[program:php]
command=/usr/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80
user=%(ENV_WWWUSER)s
environment=LARAVEL_SAIL="1"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

@Tweetdezweet
Copy link

Tweetdezweet commented Dec 19, 2021

Could someone tell me which project provides the docker-compose.yml and Dockerfile for this?
Because at the end of the day someone has to have created it, or made a script that generates it.

I just tried to set up my first Laraval project to learn it... so I have no clue on where this configuration comes from if it isn't from this project.
So yeah, any help would be greatly appreciated at this point since I am completely at a loss.

@mxaGianluca
Copy link

I'm not sure if this applies to you, but for me this was a permission issue. Meaning that the owner of the files in your sail folder and the owner inside your docker container don't align.

Easiest way to confirm is to echo $UID and see the files/folders inside your container have the same user:group.
sail shell and once inside ls -al and compare.

If not, you should update your .env file and make sure the WWWUSER and WWWGROUP match your user.

@duemti
Copy link

duemti commented Feb 7, 2023

Just had this same problem because i started the app using docker desktop.

I then stopped it and started it using sail and the permission problem went away!
./vendor/bin/sail up -d
Hope this helps others.

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