2

I am using Ubuntu 22.04 with the latest version of Docker Desktop (4.11.1) and Laravel Framework 9.26.1.

I try to create a new Laravel project follwing the steps listed at https://laravel.com/docs/9.x#getting-started-on-linux.

When I run ./vendor/bin/sail up the terminal shows no errors. But when I try to access http://localhost/ Laravel shows this UnexpectedValueException:

The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/html/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: file_put_contents(/var/www/html/storage/framework/views/d21bc1965d8c501e5e18921c4eb8ea6ec1e5686e.php): Failed to open stream: Permission denied Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}} Context: {"exception":{}}

However, running php artisan serve works without problems. Why is Sail not working?

alexciornei22
  • 21
  • 1
  • 3

4 Answers4

2

These are the steps I would take to resolve.

  • Tear down the containers ./vendor/bin/sail down.
  • Make sure you are using the Ubuntu user you intend to use. whoami
  • Add your Ubuntu user to the 'docker' group so you don't have to use sudo for Docker. usermod -a -G docker myusername.
  • Check the owner of the file executing in the terminal ls -la storage/logs. If your Ubuntu user is not the owner, you should make your user the owner. chown UbuntuUserName:UbuntuUserGroup -R /path/to/the/laravel/app/storage/logs. I would more than likely run that on the app directory as the files likely belong to a different user if the log file does as well..

Also check the permissions on the file. See what an authorized group is allowed to perform on that file.

  • Rerun the command ./vendor/bin/sail up
Brandon Orth
  • 313
  • 1
  • 3
  • 10
  • Nice and clear - seems to have worked for me, cheers. – Novocaine Oct 09 '22 at 10:26
  • Note that Sail runs the web server as user id 1000. If your host user is something other than 1000 then you'll need to set `WWWGROUP` and `WWWUSER` in your `.env` to the output of `id -u` and rebuild sail so that it runs as the correct user. – Brian Ortiz Feb 07 '23 at 19:29
2
sail root-shell
cd ..
chown -R sail:sail html

Use the sail command, enter the root-shell, enter the sail as the root user and then change the html folder permission.

Wongjn
  • 8,544
  • 2
  • 8
  • 24
rubygrey
  • 21
  • 2
0

After several hours with this issue. This solution has worked for me.

After executing the command to launch Laravel Sail

./vendor/bin/sail up

I was getting the permissions error in laravel.log

I have added these 2 variables to the .env file on your laravel project (This will add Sail as a user with permissions on the files)

WWWGROUP=1000
WWWUSER=1000

Then I have executed these commands

Stop container in the backgroud

sudo ./vendor/bin/sail down --rmi all

Re-build the image for Laravel Sail.

sudo /vendor/bin/sail up

I have solved the problem.

The problem seems to come from the fact that when starting Sail, the user with permissions on the files and folders is root by default.

By adding WWWGROUP=1000 AND WWWUSER=1000, the user with permission will be "sail".

-1

not nice but working quickly - open the directories world writable

sudo chmod o+w -R database/
sudo chmod o+w -R routes/
sudo chmod o+w -R resources/
sudo chmod o+w -R storage/
p1brunne
  • 444
  • 3
  • 3