Announcement

Collapse
No announcement yet.

Checking PHP built-in web server is running or not.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Checking PHP built-in web server is running or not.

    Hello,
    How to check PHP built-in server is already running on the server before attempting to start it?
    When I try to start it and appear for the error message Failed to listen on...

  • #2
    A command like ps aux | grep php will tell if PHP's web server is already up.

    Comment


    • #3
      ps aux | grep php Returns two lines, which one have the complete command used to call the PHP server.

      Comment


      • #4
        ps aux | grep php This command will show the output something like as follows if php is currently running:

        pi 3245 0.0 0.5 21400 2416 pts/0 S Mar17 0:02 php -S localhost:8000 -t /path/to/php/docroot
        pi 3518 0.0 0.3 5220 1712 pts/0 S+ 00:42 0:00 grep --color=auto php
        The second line you can ignore as it's just self-referencing the search command.

        This script will check if the built-in PHP server is running and start it if it's not:

        if ! ps aux | grep -v grep | grep -qs 'php -S localhost:8000';
        then
        php -S localhost:8000 -t /path/to/php/docroot &>/dev/null &
        fi

        Comment

        Working...
        X