Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Router script for PHP built in server

Project layout:

$ /t/project> tree .
├── public
│   ├── cliserver.php
│   └── index.php
├── src
└── test

Start dev server:

cd public && php -S cliserver.php

For some more details about routing with the PHP built in development server, see my article

// public/cliserver.php (router script)
if (php_sapi_name() !== 'cli-server') {
die('this is only for the php development server');
if (is_file($_SERVER['DOCUMENT_ROOT'].'/'.$_SERVER['SCRIPT_NAME'])) {
// probably a static file...
return false;
$_SERVER['SCRIPT_NAME'] = '/index.php';
// if needed, fix also 'PATH_INFO' and 'PHP_SELF' variables here...
// require the entry point
require 'index.php';
// public/index.php (the normal entry point for your web app)
//$app = new App();

This comment has been minimized.

Copy link

commented Aug 11, 2017

Thanks for this gist! It saved me big time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.