Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

simonjolsen89's avatar

Server permissions

Basically I have a GCP VM instance that I access from GCPs browser SSH.

I've uploaded the servers ssh public key to my github account, and I want to run

git clone [email protected]:myuser/myproject.git in the /var/www/ folder.

But I don't have the correct permissions to do that.

I could solve this by running

sudo chown -R $USER:www-data /var/www However, now Laravel doesn't have the correct permissions ( /storage/logs/laravel.log could not be opened in append mode: Failed to open stream: Permission denied)

If I do sudo chown -R www-data:www-data /var/www/myproject I don't get this error anymore, but can no longer run git commands.

Basically, what permissions would be the correct ones to set the project folder? I still want to be able to run git and composer without sudo, but laravel also need the correct permissions to run correctly.

0 likes
9 replies
sr57's avatar
sr57
Best Answer
Level 39

You have to setup group permission

For instance, if your app is owned by www-data:www-data

  • add user to www-data group

  • allow write to group : chmod -R g+w /var/www

or vice-versa

simonjolsen89's avatar

@sr57 So when I run sudo adduser $USER www-data I get a message that the user is already a member of www-data.

So I tried sude chmod -R +g+w /var/www/myproject

But when I run git pull, I get error: cannot open .git/FETCH_HEAD: Permission denied

sr57's avatar

@simonjolsen

  • (1) Use these cde : sudo usermod -a -G groupname username ( usermod -a -G www-data $USER)

and share the resuly of : cat /etc/group | grep www-data

  • (2) Personally I use the reverse setup (app owned by user), if you still have the error after (1) , test also this way
simonjolsen89's avatar

@sr57 result of the cat is

www-data:x:33:ubuntu,s_j_olsen89

s_j_olsen89 would be my user. How would I go about doing the reverse setup?

sr57's avatar

@simonjolsen

(1) First check the permission, the command to run was : chmod -R g+w that's different from chmod -R +g+w You should have

-rw-rw-r--    for files
drwxrwxr-x    for directories

(2) For the reverse setup

sudo chown -R ,s_j_olsen89:,s_j_olsen89  /var/www/myproject
sudo usermod -a -G s_j_olsen89 www-data

always check that your commands did want your want

simonjolsen89's avatar

@sr57 So my browser SSH connection timed-out, and when I reconnected it randomly worked. Not sure why.

simonjolsen89's avatar

@sr57 Well, I tried all the suggestions, (last one was the (1) Use these cde : sudo usermod -a -G groupname username ( usermod -a -G www-data $USER)) but still had issues with git permissions. Then I had lunch, and when I came back, the SSH connection had timed out, so I had to reconnect, and after reconnecting it worked.

sr57's avatar

@simonjolsen

Should be normal, ssh needs to reconnect to reread the config, I forgot this.

Please or to participate in this conversation.