Search code examples
phpservershutdown

How to shutdown default PHP server "php -S"


I can start the default PHP server with php -S localhost:8000 but how to stop the server? Usually with CTRL + C yes, but if i want to do it from another terminal?


Solution

  • starting:

    nohup php -S localhost:8000 &
    pid=$!
    echo $pid >/var/run/php.pid
    

    stopping

    pid=$(cat /var/run/php.pid)
    kill $pid
    

    That's only an example without proper error handling