Dynamic Port Selection for Built-in Web Server in PHP 8.0

Dynamic Port Selection for Built-in Web Server in PHP 8.0

PHP has built-in web server that designed to use for testing, development or application demonstration purposes. Since 8.0, the built-in web server allows to bind to port 0. It will use a system-generated port that is currently available.

We can execute the following command to start the built-in web server:

php -S localhost:0

We specified port 0. So, the operating system selects a random unused port. Then the built-in web server will bind to that port and starts to listen for incoming requests.

[Sun Dec  6 15:05:25 2020] PHP 8.0.0 Development Server (http://localhost:63809) started

Leave a Comment

Cancel reply

Your email address will not be published.