2

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.

2
  • 1
    Note that the system() return value is the last line of output; the exit code would be in $this->output. Commented Oct 31, 2014 at 6:13
  • 1
    What are the contents of $this->command_exec? Commented Oct 31, 2014 at 6:20

1 Answer 1

4

I solved this problem..

First, I couldn't get contents when run command, because of some php bug(?). https://www.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

Sign up to request clarification or add additional context in comments.

2 Comments

Not a "PHP bug". stderr !== stdout, they're separate output streams.
@deceze thanks, I'm adding the url about '2>&1'. gnu.org/software/bash/manual/bash.html#Redirections

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.