Setup PHP Development Web Server Quickly inside of Windows

GeekThis remains completely ad-free with zero trackers for your convenience and privacy. If you would like to support the site, please consider giving a small contribution at Buy Me a Coffee.

Since PHP 5.4.0, the developers included one of the most amazing features to ever exist. A built in development web server. In the below steps or if you choose to, in the video, you will learn to setup and run your own development web server using only the PHP client. You don’t have to worry about setting up and configuration Nginx, Apache, IIS or various other server software to quickly test your website before publishing it.

Please keep in mind that this is only for development servers and should never be used as a production web server. With that said, follow the few steps below to setup your PHP server. The PHP client can also run a server on linux operating systems also. All you have to do is install PHP 5.4+ through the terminal and run the commands in the windows setup below.

Installing PHP in Windows

  1. Download the PHP Client to your specific OS’s architecture. If you are unsure what architecture (32/64bit) you are using, download the x86 version. Navigate to Windows PHP and download the zip file for the most recent version. Thread safe is the preferred version.
  2. Extract the downloaded ZIP file into an easy to access location. I have mine at E:\svr\php but you can place this folder anywhere. In the video I show it setup on the user’s Desktop.
  3. Set the PATH variable for your user or system if you want everyone to have access to it. If you set the system PATH variable, the PHP directory has to be accessible by everyone and not just one user.
  4. Open Command Prompt. The quickest method is to open the Run window (Windows Key + R) and then run the program “cmd”.
  5. Enter the command php -v to check that the path variable is setup properly. If you get an error of the command or program not found, the PATH variable is incorrect.

Setting System / User PATH Variables

  1. Inside of Windows 8 Start Search you can enter “Edit the system environment variables” and get to the settings that way. If you want another way to access these settings, open the Run window (Windows Key + R) and enter the program name “systempropertiesadvanced”
  2. On the bottom right of the System Properties window click on the button for “Environment Variables”
  3. If you only want the current user to have access to the PHP Path set the PATH variable under “User variables for Username” or if you want all users to have access to the PHP Path, set the PATH variable under “System variables”
  4. Modify the PATH variable to the location of the PHP Directory. If the directory is in your User’s Profile folder or subfolder (C:\Users\Username) you can use the “%USERPROFILE%” variable instead. If there is text before the PATH you are inserting, make sure you add a semicolon ( ; ) after the existing text before you enter your new path location.
PATH         C:\Users\David\Desktop\php
PATH         %USERPROFILE%\Desktop\php
PATH         C:\Windows\system32;C:\Windows;%USERPROFILE%\Desktop\php

Starting the PHP Web Server

  1. Open Command Prompt or Terminal.
  2. Enter the command php -S 127.0.0.1:80 to start a server listening on port 80 for the current directory as the root. Whatever directory you are currently in will be the folder PHP looks for the index file.
  3. To start a PHP server in a different folder, after the above command, add the argument of -t /path/to/folder. This way you can spawn PHP from any directory and have the document root the same. php -S 127.0.0.1:80 -t /path/to/folder.

For more information on the PHP web server, you can check out the offical documentation over at PHP.net Webserver

Related Posts

Process Incoming Mail with PHP Script with Exim

Learn how to process incoming e-mails to your server with a PHP or other script.

PHP - Check if Production or Sandbox

Use PHP to check of your site is on your development server or uploaded to the production server.

PHP Dynamic Subdomains

How to setup dynamic subdomains with PHP to give users a custom domain for their profile page.

Parsing AWStats with PHP

Parse Awstat files using PHP including information about the awstats file format.