Using PHP's built-in web server

Josh Sherman
1 min read
Software Development PHP

I recently updated [HolidayAPI][holidayapi] to no longer use my PHP framework because I wanted the system to be easier for new developers to get up and running. Instead of including configuration files for Apache or nginx, I decided that I should just use the web server that’s baked right into PHP!

To start up PHP’s built-in web server, from the root of your project run:

php --server localhost:3333

or more simply:

php -S localhost:3333

That will end up spitting out something like this:

PHP 5.5.22 Development Server started at Sun May 17 11:02:26 2015
Listening on http://localhost:3333
Document root is /Users/josh/Code/joshtronic/
Press Ctrl-C to quit.

If you point your browser to that address you will be greeted by the PHP server! In my case, the directory I started it in didn’t have an index.php (since it’s a jekyll site ;) so I got an error. If you don’t have a project handy, just create index.php in the directory and you should be greeted by that page.

This is awesome for development purposes since it means you don’t have to worry about setting up a web server and distributing conf files. As good as it is, it is not suggested for production use, as per the documentation.

Next week I’ll talk about basic page routing so we can use the built-in web server without needing to include .php at the end of every page!

Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.

Currently Reading

Parasie Eve

Previous Reads

Buy Me a Coffee Become a Sponsor

Related Articles