Web development tip: start a simple web server from the command line


While developing even the simplest of websites, I've found it quite useful to be able to test things through a functional web server. Often setting up an Apache or Nginx configuration is unnecessary and my needs can be met by using the built-in web server found in PHP (as of PHP 5.4.0) or Ruby.

Run the command of your choice below to fire up a simple web server in the current directory:

  • ruby -run -e httpd . -p 8000
  • php -S localhost:8000

Assuming you have an index.html or index.php in your present directory, visit localhost:8000 in your browser and you should see your web site.