duangan9251 2014-10-31 02:33
浏览 308
已采纳

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.

  • 写回答

1条回答 默认 最新

  • douyu1990 2014-10-31 06:41
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题