2.4. Built-in server

To test the PHP interpreter, we create an index.php script that displays the traditional “Hello, world!” Phrase for programming books. (listing 2.1).

Listing 2.1. Hello World verification script. File index.php

<?php
echo 'Hello, world! ';
?> 

If the current user does not have administrator rights, then in the folder with the script index.php you should run the command:

php -s localhost:4000

The command will launch a Web server on the 4000 port. By contacting the browser at http:/localhost:4000/, you can see the phrase “Hello, world!”. If you are working under a system administrator account (Windows) or using the sudo command (Mac OS X or Linux), you can run the embedded server on the standard 80 port:

php -s localhost:80

In this case, the port in the address can be omitted, the browser will automatically access the 80-port assigned to the HTTP protocol: http://localhost/. By default, the current folder acts as the root directory and the index.php index file will be searched in this folder. However, using the -t option you can specify an arbitrary folder:

php -s localhost:4000 -t buildin

Log records or, as they say, server logs are output directly to the console in which it was launched. You can stop the server by pressing the key combination <Ctrl>+<C>.