0

In my Laravel app, I am using Nginx as the server. Ubuntu version is 21.10

I also want to use Laravel's console (Tinker) to log stuff. When I set www-data to be the owner of storage folder, which contains the logs, then I can view my app via localhost, but then I can't use Tinker to log information, for example Log::debug("test");, as I get:

UnexpectedValueException with message 'The stream or file 
"/var/www/laravel-app/storage/logs/laravel.log" could not be       
opened in append mode: Failed to open stream: Permission denied

so I set my user temporarily to own storage when I want to use Tinker:

sudo chown -R $USER:www-data storage

But then I can't view my app, as I get the same error as above when trying to access localhost.

How can I make both users have permissions to stoarge?

1 Answers1

1

You can use groups. Simply add those users to the www-data group

sudo usermod -aG www-data user1
sudo usermod -aG www-data user2

To ensure that the group has right to read and write:

chmod -r ug+rw path_of_folder_containing data

The you could check with ls -la:

-rw-------  1 aUser aGroup         48  2. Apr 20:44  someFile #only user may read/write
-rw-r--r--  1 aUser aGroup         48  2. Apr 20:44  someFile #user r/w, group and others only read
-rw-rw-r--  1 aUser aGroup         48  2. Apr 20:44  someFile #user & group r/w, others only read

You should log out and in again so that the group change takes effect.

kanehekili
  • 7,426