Our site remains ad-free thanks to our affiliates. This post's featured affiliate is Namecheap. Namecheap offers domains at low prices while providing outstanding customer service.
The post is not sponsored by the above affiliate and the content here is not representative of their company.
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
- 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.
- 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.
- 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.
- Open Command Prompt. The quickest method is to open the Run window (Windows Key + R) and then run the program “cmd”.
- Enter the command
php -vto 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
- 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”
- On the bottom right of the System Properties window click on the button for “Environment Variables”
- 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”
- 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
- Open Command Prompt or Terminal.
- Enter the command
php -S 127.0.0.1:80to 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.
- 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