PHP’s built-in Web Server

PHP’s built-in Web Server designed specifically for development and testing. Since PHP5.4, CLI SAPI comes with a built-in web server. Built-in web server makes it easy to quickly try out some scripts without needing to configure Apache, Nginx or other web servers.

Built-in sever strongly recommended for development, testing and demo purpose. Don’t use as production sever and in public networks.

How to use Built-in Server

You will need to have PHP 5.4 or greater installed to use the built-in server. To verify your version of PHP, issue command php -v in a terminal.

php -v output the version of your current installed PHP.

You can then determine if the server is available in your build by running php -h and looking for the -S and -t options which are specific to the server.

 PHP’s built-in Web Server

Start built-in Server

The server runs when you pass the -S switch to PHP on the command line. You then supply the server name and port number:

This gives initial output, and then provides information about each request –
How to use Built-in Server

Changing the host name

You can easily change host name from localhost to desired name or project name.To use custom host name, you just need to add the new server name into /etc/hosts (or the equivalent for your system) and then start the server with the new name as shown below.

Changing the document root directory

By default when you issue sever start command php -S localhost:8080 it will make current directory as server root. You can change this behavior by specifying directory path with -t option while starting sever.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.