Skip to content

Instantly share code, notes, and snippets.

@phamnhungoctuan
phamnhungoctuan / run-command.php
Created September 8, 2018 15:28 — forked from codeZoner/run-command.php
Execute Shell Script using PHP (Git Pull Example)
<?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;