Housni Housni - 3 months ago 11
PHP Question

How do I run PHP's built-in web server in the background?

I've written a PHP CLI script that executes on a Continuous Integration environment. One of the things it does is it runs Protractor tests.

My plan was to get the built-in PHP 5.4's built-in web server to run in the background:

php -S localhost:9000 -t foo/ bar.php &


And then run protractor tests that will use
localhost:9000
:

protractor ./test/protractor.config.js


However, PHP's built-in web server doesn't run as a background service. I can't seem to find anything that will allow me to do this with PHP.

Can this be done? If so, how?
If this is absolutely impossible, I'm open to alternative solutions.

Answer

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>).

Comments