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
Call to action
Did you like this post? You can help me back in several ways: (use the "reply" link on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and repost!
- Follow me on Bluesky 🦋
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win "Announcer" badges 🏅.
Thank you for reading! And see you soon on Strangebuzz! 😉