I first run a test against my bitbucket server instance to get any error messages output on screen:
echo shell_exec("cd /website/root/htdocs && git status 2>&1");
this threw an error that it could not find git command hence had to provide a full path to git's binary:
'which git'
returned (further called YOU_FULL_GIT_BINARY_PATH_HERE):
/usr/local/git/bin/git
A full path e.g. '/usr/local/git/bin/git status' now runs git commands nicely.
This doesn't overcome git password required to use 'git pull' command for a set in .git/config git user. Running below command in git repo:
git config credential.helper store
[command][1] will prompt for password and let you store it locally unencrypted (protected only by file system e.g. in /root/.git-credentials). This will allow to run 'git pull' without prompting for password. Alternatively (probably better) is to generate ssh keys for your web server such as apached then add them to your bitbucket user dedicated account or repo keys.
All my folders have been set to be owned by apache user (Centos 6.8 other releases might be www-data:www-data etc.):
chown -R apache:apache YOUR_WEB_FODLER
I did not have to use the dirty trick 'chmod o+rw -R' to get all working.