The Many Faces Of PHP
![]()
Given PHP’s origins, most people run PHP with the help of a web server. The latter serves static HTML files which your browser renders for viewing.
If the file contains PHP, the web server (assuming its PHP functionality is enabled) will do some magic, i.e. parse the PHP and send the resulting HTML back to the browser.
On your machine, creating an index.php file in the document root with the contents
echo php_sapi_name();then navigating to
localhostproduces something like
apache2handler in the browser.
However, as of PHP 5, one can do the same thing using PHP’s built-in server
php -S localhost:8000 turns the current working directory into the document root and navigating to
localhost:8000returns something like
cli-serverThe third way is to run PHP without any server at all. Assuming you have the PHP interpreter installed and its path in the ‘path’ variable,
php --interactiveopens the PHP interactive shell. Then typing
echo php_sapi_name();returns
cli