Skip to content

Instantly share code, notes, and snippets.

@endel
Last active March 5, 2016 15:29
Show Gist options
  • Select an option

  • Save endel/d89a7d82e44f534d449e to your computer and use it in GitHub Desktop.

Select an option

Save endel/d89a7d82e44f534d449e to your computer and use it in GitHub Desktop.
Simple development server for running PHP projects without having to configure a web application server (nginx, apache, etc)
<?php
//
// Development server.
//
// Requires PHP 5.4+, with built-in web-server feature:
// http://php.net/manual/en/features.commandline.webserver.php
//
// Run it through console via:
// $ php -S localhost:8000 ./dev_server.php
//
$root_path = getcwd() . '/';
if (file_exists($root_path . $_SERVER['REQUEST_URI'])) {
if (preg_match('/\.php$/', $_SERVER['REQUEST_URI'])) {
require($root_path . $_SERVER['REQUEST_URI']);
} else {
return false;
}
} else {
require('index.php');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment