-
-
Save sagar290/e7d48aa04a1d34253a56d305ec017448 to your computer and use it in GitHub Desktop.
Execute Shell Script using PHP (Git Pull Example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
//make sure to make the shell file executeable first before running the shell_exec function | |
$output = shell_exec('./shell-script.sh'); | |
chdir($old_path); | |
echo $output; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cd /path/to/git/folder && git pull origin branch_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment