PHP通过system()调用git命令失败,退出代码为128

CentOS 5.9, PHP 5.4.21, Tomcat 7.0.42, Safe mode is off.

I need to commit some code to repository from php. but failed with exit code 128. Codes are below, and command_exec is 'cd /data/project && git add .'

ob_start();
$this->system_call_detail = system($this->command_exec, $this->output);
$logger->debug('ExecuteCMD system call result : '.$this->system_call_detail);
ob_end_clean();

I can run git command as the apache user account from cmd, but programs run from PHP fail with exit code 128.

I guessed this cause from PHP. So, I tried this git command, "php -r 'system("cd /data/project && git add .", $test); echo $test;'" from cmd as apache user account and it success.

I solved this problem..

First, I couldn't get contents when run command, because of some php bug(?). http://kr1.php.net/manual/en/function.system.php#108713

I fixed the command belows:

$this->system_call_detail = system($this->command_exec.' 2>&1', $this->output);

and then, I could get error msgs belows:

fatal: unable to access '/home/{username}/.config/git/config': Permission denied

But, there were no such files or directory. So, I googled with the error msgs. and found some blog.

http://www.jethrocarr.com/2013/08/25/the-apache-that-wanted-to-be-root/

And I edited '/etc/sysconfig/httpd' file with the blogs posted. And Solved. :)

Thank for helping me. deceze and ojrask