In this episode, we dive into PHP's built-in web server, which has been available since PHP 5.4. It's not made for production sites, but it's a super handy tool for developing and testing PHP projects locally without having to mess with something like Apache or Nginx.
We start off by checking our PHP version in the terminal and exploring the basic options for running the server, specifically the -S
option for specifying the address and port, and the optional -t
option for setting the web root directory. You'll see step-by-step how to launch the server right from your project folder, and how easy it is to serve your PHP files by just browsing to the right URL and port.
Next, we play around with creating a phpinfo.php
file to test things out, and take a look at the kind of output and server logs you get in your terminal as you're developing. Then, we add a little polish by setting up custom color highlighting in the server output, which makes it easier to spot errors and successes at a glance.
Finally, we mention a couple of workflow tips, like how to connect to a MySQL database or use SQLite, which is already built into PHP, all while using this lightweight server. Altogether, it's a nice reminder that PHP has some great tools for quick development—definitely something to keep in mind when you want to spin up a project fast without major server setup!