DeyaEldeen
DeyaEldeen

Reputation: 11807

webhook php file work from terminal but not from bitbucket

I'm using bitbucket to host my git repository, the repo holds a test website at the moment, I have created a bitbucket webhook, so when I push to the bitbucket repo, the changes show up as live on the digitalOcean VPS, in other words.. when bitbucket receives a push, it calls the webhook php file, and that php file has a shell script that pulls from github..

the hook file

Hook path : /var/www/html/hook.php

the site folder

Site path : /var/www/html/webhooks/

the hook.php file looks like so

<?php 
echo "________PHP_AUTO_PULL________"; 

$output = shell_exec('git -C ./webhooks/ pull https://userName:[email protected]/userName/repo.git master'); 
echo "<pre>$output</pre>"; 

?>

when I do this in terminal

php hook.php

it does the job normally, and it pulls..

but the problem is, webhooks only shows this reply

________PHP_AUTO_PULL________

indicating that it does no pull, yes I have checked, no pull occured, how to make the hook execute the file normally?

permissions and owners are provided in these listings

listing for /var/www/html/

drwxrwxr-x 3 www-data www-data 4096 Mar 28 09:21 ./
drwxrwxr-x 3 www-data www-data 4096 Mar  3 16:49 ../
-rwxrwxrwx 1 www-data root      200 Mar 28 09:05 hook.php*
-rw-rw-r-- 1 www-data www-data   20 Mar  3 16:49 info.php
drwxr-xr-x 3 root     root     4096 Mar 28 09:03 webhooks/

listing for /var/www/html/webhooks/

drwxr-xr-x 3 root     root     4096 Mar 28 09:03 ./
drwxrwxr-x 3 www-data www-data 4096 Mar 28 09:21 ../
-rw-r--r-- 1 root     root      295 Mar 27 15:13 content.html
drwxr-xr-x 8 root     root     4096 Mar 28 09:03 .git/
-rw-r--r-- 1 root     root      444 Mar 27 15:13 index.html
-rw-r--r-- 1 root     root      963 Mar 27 15:13 menu_1.html
-rw-r--r-- 1 root     root       13 Mar 28 09:03 number.txt

my webserver is nginx any idea why it works from terminal, but bitbucket can't have it to work?

Upvotes: 1

Views: 382

Answers (1)

DeyaEldeen
DeyaEldeen

Reputation: 11807

I have managed to solve it, using :

echo shell_exec("/usr/bin/git pull https://userName:[email protected]/userName/repo.git master 2>&1");

the 2>&1 part was helping me to see errors about permissions of folders, I used

chown -R www-data .git/

and it's working fine.

Upvotes: 1

Related Questions