1

I would like to use the hook to update my code, run in macos success, centos fail :

public function pull() {
      $command = "cd /var/www/laravel && git pull origin master";
      $last_line = system($command, $retval);
       print_r($last_line);
       print_r($retval);
       exit();
}

if the $command = "cd /var/www/laravel && pwd", all success. very confused.

Khazan
  • 53
  • 1
  • 8
  • write permissions? – ljubadr Oct 20 '17 at 08:11
  • I try ``$command = "cd /var/www/ && echo \"passwd\" | sudo echo abc > abc.text";``. Does not work. – Khazan Oct 20 '17 at 08:14
  • What errors do you get? – brombeer Oct 20 '17 at 08:14
  • I am a novice, I do not know how to view the wrong message. I only know that the function return 1, not 0. @kerbholz – Khazan Oct 20 '17 at 08:19
  • Take a look at [What does the linux pipe symbol “|” do?](https://superuser.com/questions/756158/what-does-the-linux-pipe-symbol-do) – ljubadr Oct 20 '17 at 08:22
  • Also, try `$command = "cd /var/www/laravel && git pull origin master 2>&1";`, note `2>&1` at the end. You can read more about [what does “ 2>&1 ” mean?](https://stackoverflow.com/questions/818255/in-the-shell-what-does-21-mean) – ljubadr Oct 20 '17 at 08:35
  • This will give you error messages from terminal – ljubadr Oct 20 '17 at 08:38
  • I use ``$command = "cd /var/www/laravel && git pull origin master 2>&1"``, get the error ``error: cannot open .git/FETCH_HEAD: Permission denied``. @ljubadr – Khazan Oct 20 '17 at 09:06
  • 1
    Look into this blog post - [Git pull from a php script, not so simple.](https://jondavidjohn.com/git-pull-from-a-php-script-not-so-simple/), could guide you into right direction – ljubadr Oct 20 '17 at 09:13
  • Thank you.This article is great.@ljubadr – Khazan Oct 23 '17 at 02:17

0 Answers0