Use PHP’s Built-in Web Server for Quick, Local Development

I recently need to build a simple PHP script but I didn’t feel like spending a lot of time configuring a web server, e.g. Apache. and having it support PHP. It turns out that PHP has its own built-in server and it’s super easy to use. Here are the steps:

  1. Download PHP
    If you’re on Windows, which I was at home, then go to https://windows.php.net/ and download a pre-compiled PHP binary. I chose the latest x64 NTS (non thread safe) zipped version.
  2. Unzip the archive
    e.g. to c:/Program Files/PHP/
  3. Open a terminal window
    We start and stop the server from the command line
  4. Go to your project folder
    e.g. cd c:/Documents/Projects/mysite
  5. Start the server
    If PHP is on your path, then you can just do
    php -S localhost:8000
    otherwise, you’ll need to specify the full path to PHP, e.g.
    c:/Programs/PHP/php -S localhost:8000
  6. View your PHP site
    Go to localhost:8000 in a web browser and see your site, e.g. index.php
  7. Stop the server
    Press Ctrl-C to quit

If you want to start the server in a particular document root directory, e.g. c:/Downloads/foo, you can do
php -S localhost:8000 -t c:/Downloads/foo

View the PHP built-in server documentation

cd C:\Users\abdul\Documents\Projects\zabuun.com
C:\Users\abdul\Documents\Projects\zabuun.com>”C:/Program Files/PHP/php” -S localhost:8001