Serving Drupal 7 with built-in PHP 5.4 server
The task is basically to encode Drupal's .htaccess in PHP for your router.php
file.
Here's a start:
<?phpif (preg_match("/\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)/", $_SERVER["REQUEST_URI"])) { print "Error\n"; // File type is not allowed} elseif (preg_match("/(^|\/)\./", $_SERVER["REQUEST_URI"])) { return false; // Serve the request as-is} elseif (file_exists($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) { return false;} else { // Feed everything else to Drupal via the "q" GET variable. $_GET["q"]=$_SERVER["REQUEST_URI"]; include("index.php");}
This should be considered alpha quality. It represents a 3 minute walk through Drupal 7.14's .htaccess file, skipping anything that needed more than 10 seconds of thought. :)
It does, however, allow me to launch Drupal's install script, with stylesheets, JS and images loaded as expected, and hit Drupal's pages using Clean URLs. Note that to install Drupal in this environment, I needed a patch that may not become part of Drupal 7.
I was looking for a solution myself and I found one in in the Drupal 8 issues:
This works great for me now in my existing Drupal 7 install(s):
Save this as .htrouter.php (or whatever you wish) and run in your Drupal root dir with:
php -S localhost:8080 .htrouter.php
<?php/** * @file * The router.php for clean-urls when use PHP 5.4.0 built in webserver. * * Usage: * * php -S localhost:8888 .htrouter.php * */$url = parse_url($_SERVER["REQUEST_URI"]);if (file_exists('.' . $url['path'])) { // Serve the requested resource as-is. return FALSE;}// Remove opener slash.$_GET['q'] = substr($url['path'], 1);include 'index.php';
(snippet built from https://drupal.org/files/router-1543858-3.patch)