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, 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 built-in web server:

php -S localhost:0

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

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

Leave a Comment

Your email address will not be published. Required fields are marked *