Gitlab webhooks not working due to shell script permission

Gitlab webhooks not working due to shell script permission

Using laravel 5.6. I'm trying to set up a webhook on gitlab, to make a git pull on push events. I've created a post route, added controller and method, that launches a shell script:

Using laravel 5.6. I'm trying to set up a webhook on gitlab, to make a git pull on push events. I've created a post route, added controller and method, that launches a shell script:

use Symfony\Component\Process\Process;

class WebhookController extends Controller
{
    public function handle(Request $request) {
        $root_path = base_path();
        $process = Process::fromShellCommandline('cd ' . $root_path . '; ./deploy.sh');
        $process->run(function($type, $buffer) {
            echo $buffer;
        });
    }
}

Shell script itself contains just a one line:

#!/bin/sh

git pull

But in gitlab's request details, i see an error after a push:

error: cannot open .git/FETCH_HEAD: Permission denied

I already chmod 777 deploy.sh, but i guess it tries to launch that script from different user? If i launch the script from my user, it just works (i'm using ssh key without a password).

UPDATE

I did sudo chown -R $USER:www-data . - now it doesn't show an error with permissions, except the one:

Could not create directory '/var/www/.ssh'.
Host key verification failed.
fatal: Could not read from remote repository.

It's trying to make a git pull using www-data user (i checked with whoami), so it doesn't have a right ssh key, how can i switch to my USERNAME?

git

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

7 Best Practices in GIT for Your Code Quality

Git plays a significant role in software development. It allows developers to work on the same code base at the same time. Check out 7 best practices for Git.There is no doubt that Git plays a significant role in software development. It allows developers to work on the same code base at the same time. Still, developers struggle for code quality.

Git Rebase Tutorial and Comparison with Git Merge

In this article, I will explain to you a few differences between git merge, git rebase, and the git interactive rebase.I will tell a bit about what pros...

Basic Git Commands you need to Master

All basic commands you need to know to run git .Basic Git Commands you need to Master

Making a Git Push using Git Bash

Follow us on Twitter and instagram https://twitter.com/startdotng https://twitter.com/hnginternship https://instagram.com/hnginternship

Get More out of Git with Git Aliases

One of my favorite things to do as a developer is share tips. Here are my best custom Git aliases