Testing raw PHP code with the built-in web server

Published on 2020-07-26 • Modified on 2020-07-26

In this snippet, we will see how to test raw PHP code with the built-in web server. Sometimes, it's useful to use a clean context that doesn't include a framework so you can check things and be sure there no side effect coming from it or another external library. It's also more convenient to use the web mode, as you will be able to use HTML to display information which is more comfortable than using the CLI. Run the following commands then access http://localhost:8000 in your browser, you should see the classic phpinfo() page. If you want to test another file, just add its name in the URL (/test.php).

mkdir php_tests
cd php_tests
echo "<?php phpinfo();" > index.php
php -S localhost:8000

 More on Stackoverflow   Read the doc  Random snippet