Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 449
Housni Avatar asked May 15 '15 19:05

Housni


People also ask

How do I run a PHP web application locally?

If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.

What is PHP built webserver?

PHP Command Line Interface (CLI) Running built-in web server As from version 5.4, PHP comes with built-in server. It can be used to run application without need to install other http server like nginx or apache. Built-in server is designed only in controller environment for development and testing purposes.

Which of the following Web server are required to run the PHP script?

The preferred way of running PHP files is within a web server like Apache, Nginx, or IIS—this allows you to run PHP scripts from your browser.

How does PHP server work?

Step 1: The client requests the webpage on the browser. Step 2: The server (where PHP software is installed) then checks for the . php file associated with the request. Step 3: If found, it sends the file to the PHP interpreter (since PHP is an interpreted language), which checks for requested data into the database.


2 Answers

You can use &> to redirect both stderr and stdout to /dev/null (noWhere).

nohup php -S 0.0.0.0:9000 -t foo/bar.php &> /dev/null &
like image 196
Amir Fo Avatar answered Oct 31 '22 07:10

Amir Fo


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

like image 45
Devon Avatar answered Oct 31 '22 05:10

Devon