How do I run PHP's built-in web server in the background?
You could do it the same way you would run any application in the background.
nohup php -S localhost:9000 -t foo/ bar.php > phpd.log 2>&1 &
Here, nohup is used to prevent the locking of your terminal. You then need to redirect stdout (>
) and stderr (2>
).
Also here's the way to stop built-in php server running in the background. This is useful when you need to run the tests at some stage of CI:
# Run in background as Devon advised
nohup php -S localhost:9000 -t foo/ bar.php > phpd.log 2>&1 &
# Get last background process PID
PHP_SERVER_PID=$!
# running tests and everything...
protractor ./test/protractor.config.js
# Send SIGQUIT to php built-in server running in background to stop it
kill -3 $PHP_SERVER_PID