简体   繁体   中英

Git POST webhook shell_exec

I have a script running the following shell_exec cmd in PHP.

echo shell_exec('cd /var/www/Library/Laravel/ ; git pull bitbucket master ; 2>&1');

This is being called by a webhook service and all I wanted to do is just cut out having to pull in this dev environment everytime we push.

However, I do not get any output errors or anything when this route is called. Can anyone suggest why this might be?

I get this echoing from the error_log ->

error: cannot open .git/FETCH_HEAD: Permission denied

I added the apache user to git and now I get the following error

Could not create directory '/var/www/.ssh'.
Host key verification failed.
fatal: The remote end hung up unexpectedly

I see a few problems here:

1) your exec line "...; git pull bitbucket master ; 2>&1" should be "... git pull bitbucket master 2>&1" -- the extraneous semicolon is likely preventing you from seeing the standard error output.

2) you found the ownership problem, so...

3) I'm guessing you have an "ssh" based git URL. The first time you run SSH as a user it will try to validate host key (SSH id of the other side). The default behavior of SSH is to fail if the tool is not interactive and you have not yet accepted the key. Alternately, you'd see the same behavior if you've accepted the key but it has since changed. You would solve these two different problems differently.

The "right" way to fix this would be to manually run the command (as that user with the appropriate HOME variable set) and manually accept the key so subsequent commands will "just work".

Another possibility is to override SSH's default behavior -- see the documentation for the "StrictHostKeyChecking" SSH option. You can do some hacking to pass this on the command line or create a ~/.ssh/config file specifying the option. (NOTE: I recommend the first solution, not this one unless you understand the security implications.)

And lastly, I suspect you'll also need to set up your SSH private key to allow you to pull as that user as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM