I have a php script that running on my local Windows machine and i need to restart Apache server from that script. I may stop Apache from that script but can't start it because it is being stopped and php execution after apache-stop
is interrupted.
My php code is
shell_exec('bash -c "source ~/.bashrc && apache-stop && some-command && apache-start"');
//bash.exe is in PATH already
Bash functions ~/.bashrc
function apache-stop {
( tskill httpd )
if [[ $? -eq 0 ]]; then
echo "Apache stopped."
fi
}
function apache-start {
tasklist | grep -a "httpd.exe" > /dev/null
if [[ $? -eq 0 ]]; then
echo "Apache already running."
else
echo "Start Apache."
( /c/xampp/apache/bin/httpd.exe & )
fi
}
I use Apache on Windows 8.1 only as console application and run/kill it from bash console, hence i can't use Apache as a Windows Service. How to run apache-stop
, some-command
and apache-start
from that php script, may be there is a way to run externally all this bash functions?