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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘