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?