0

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?

Karich Nikita
  • 21
  • 1
  • 6
  • Does this help? https://stackoverflow.com/questions/6693143/basic-apache-commands-for-a-local-windows-machine ... you can just call Apache itself (httpd) over Windows CLI - if I understand what you're trying to do correctly. – CD001 Sep 10 '20 at 15:54
  • @CD001 No, not my case. In that question was used commands when Apache was installed as Service. I may run and kill httpd.exe directly with cmd/bash but i can't run Apache inside php script when Apache has been killed. – Karich Nikita Sep 10 '20 at 16:48

0 Answers0