Created by: gwideman, Jan 30, 2012 3:21 am
Revised by: gwideman, Jan 30, 2012 5:10 pm (8 revisions)

Overview

Notes about the steps whereby an http request gets to apache, apache launches drupal, a particular site becomes active, and so on. Knowing how this works is crucial to troubleshooting installations that don't work, or understanding why tools can't find what they expect to find, and so on.

How A finds B

Step
A
B
How A finds B




Component
File
Settings
Description
(Dev envt) Browser requests xyz.com page from local apache
Browser
Domain xyz.com, (mapped to local host)
OS
hosts file
127.0.0.1 xyz.com
Entry mapping xyz.com to local host
http request arrives
OS
Apache
Apache
httpd.conf
Listen domain:port

What to do with URL?
Apache
web root
Apache
httpd.conf,
vhosts.conf
VirtualHost settings.
Translates [Subdomain].[Server]/[path] to file system directory.
For a request to Drupal, this should resolve to a directory containing index.php and the rest of the drupal installation.
Invoke PHP 5.3
Apache
PHP
Apache
httpd.conf
LoadModule php5_module "...\php5_3\php5apache2_2.dll"
PHPINIDir ...\php5_3
Apache is configured to launch a dll through which to talk to php.
Find PHP extensions
PHP
Extensions
PHP 5.3
...\php5_3\php.ini
extension=php_[extnname].dll

Find site config (single)
Drupal
Site settings
Drupal
[Fixed path]
/sites/default/settings.php
Drupal algorithm falls through to default path to settings.php.
Find site config (one of multi)
Drupal
Site settings
Drupal
[Algorithm]
See below.
/sites/[distinctname]/settings.php
Drupal uses algorithm to determine [distinctname] corresponding to which site is requested.
Connect to database
Drupal
MySQL
MySQL

port=33066
user=drupaluser
datadir=[root data dir]




Drupal
settings.php
$databases[][] ... driver, database, username, password (?), host, port.















Additional topics:
  • Need to add PHPStorm, XDebug (or reference the page where I config them).
  • How Acquia Dev Desktop Control Panel knows what's where
  • How Drupal finds modules, themes.

Drupal's algorithm for locating settings.php

The following is from the doc text for function conf_path() in bootstrap.inc. This function looks for a directory under [DRUPAL_ROOT]/$confdir which contains a file named settings.php. ($confdir = 'sites').
Note: I think "multisite" just corresponds to having several folders under /sites/, one per site, and named so that they will be found appropriately by the following algorithm. (Possibly also with the help of a sites.php file.)

function conf_path($require_settings = TRUE, $reset = FALSE) {

Finds the appropriate configuration directory.
Finds a matching configuration directory by stripping the website's hostname from left to right and pathname from right to left. The first configuration file found will be used and the remaining ones will be ignored. If no configuration file is found, return a default value '$confdir/default'.
With a site located at http://www.example.com:8080/mysite/test/, the file, settings.php, is searched for in the following directories:





<-- outer loop

Inner loop -->



$confdir/
.8080
.www
.example
.com
.mysite
.test
$confdir/

.www
.example
.com
.mysite
.test
$confdir/


.example
.com
.mysite
.test
$confdir/



.com
.mysite
.test
$confdir/
.8080
.www
.example
.com
.mysite

$confdir/

.www
.example
.com
.mysite

$confdir/


.example
.com
.mysite

$confdir/



.com
.mysite

$confdir/
.8080
.www
.example
.com


$confdir/

.www
.example
.com


$confdir/


.example
.com


$confdir/



.com









$confdir/
.default





If a file named sites.php is present in the $confdir, it will be loaded prior to scanning for directories. It should define an associative array named $sites, which maps domains to directories. It should be in the form of:
$sites = array(
'The url to alias' => 'A directory within the sites directory'
);
For example:
$sites = array(
'devexample.com' => 'example.com',
'localhost.example' => 'example.com',
);
The above array will cause Drupal to look for a directory named "example.com" in the sites directory whenever a request comes from "example.com", "devexample.com", or "localhost/example". That is useful on development servers, where the domain name may not be the same as the domain of the live server. Since Drupal stores file paths into the database (files, system table, etc.) this will ensure the paths are correct while accessed on development servers.
Parameters:
  • @param bool $require_settings
    • Only configuration directories with an existing settings.php file will be recognized. Defaults to TRUE. During initial installation, this is set to FALSE so that Drupal can detect a matching directory, then create a new settings.php file in it.
  • @param bool $reset
    • Force a full search for matching directories even if one had been found previously. Defaults to FALSE.
  • @return
    • The path of the matching directory.