I am looking to develop a Drupal 7 site using PHP's built-in server. I have successfully run Drupal without clean urls (e.g. index.php?q=/about/) but clean urls (e.g. /about/) normally rely on mod_rewrite or its equivalent. In the docs I see you can run the PHP server with a router file like so:
php -S localhost:8000 routing.php
What should I put in the routing.php to simulate mod_rewrite?
Drupal 7 community support is provided until November 2023 In light of the impact of COVID-19 on our community, Drupal 7 is supported until November 1, 2023. This means Drupal 7 will be supported throughout Drupal 9's life.
PHP versions supported Recommended? Drupal 10 requires at least PHP 8.1.
Apache. Apache is the most commonly used web server for Drupal. Drupal will work on Apache 2. x hosted on UNIX/Linux, OS X, or Windows.
PHP: Hypertext Preprocessor (PHP) is an interpreted programming language that is widely used, and especially well suited for web development. Drupal and many other popular web applications are written in PHP. If you wish to develop Drupal modules or be able to do advanced Drupal theming, you will need to learn PHP.
The task is basically to encode Drupal's .htaccess in PHP for your router.php
file.
Here's a start:
<?php
if (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
} else
if (preg_match("/(^|\/)\./", $_SERVER["REQUEST_URI"])) {
return false; // Serve the request as-is
} else
if (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.
You can now more easily launch a server with the command:
drush runserver
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With