Skip to content

Instantly share code, notes, and snippets.

@codeZoner
Last active April 12, 2022 19:48
Show Gist options
  • Save codeZoner/6545d76cc0b5b80d9d8e76fb3a60cd1d to your computer and use it in GitHub Desktop.
Save codeZoner/6545d76cc0b5b80d9d8e76fb3a60cd1d to your computer and use it in GitHub Desktop.

Revisions

  1. Fahim Hossain revised this gist Jul 29, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions run-command.php
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@
    //Ref: https://stackoverflow.com/questions/11052162/run-bash-command-from-php#answer-11052453
    $old_path = getcwd();
    chdir('/path/to/file');
    //make sure to make the shell file executeable first before running the shell_exec function
    $output = shell_exec('./shell-script.sh');
    chdir($old_path);

  2. Fahim Hossain revised this gist Jul 29, 2017. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion run-command.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    <?php

    // chdir to the correct directory before calling the script
    //Ref: https://stackoverflow.com/questions/11052162/run-bash-command-from-php#answer-11052453
    $old_path = getcwd();
    chdir('/path/to/file');
    $output = shell_exec('./shell-script.sh');
  3. Fahim Hossain created this gist Jul 29, 2017.
    10 changes: 10 additions & 0 deletions run-command.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    <?php

    $old_path = getcwd();
    chdir('/path/to/file');
    $output = shell_exec('./shell-script.sh');
    chdir($old_path);

    echo $output;

    ?>
    2 changes: 2 additions & 0 deletions shell-script.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    #!/bin/bash
    cd /path/to/git/folder && git pull origin branch_name