The seventh version of Drupal has greatly improved the installation process once more. Among other changes, the installer has become more user-friendly, but the best part is under the hood, and somewhat less obvious. It is now much easier than ever to install Drupal using a PHP script that runs in the console, rather than the interactive web installer.
Since I have not yet seen a detailed documentation of this feature, here is a guide.
1. Build an install script
The central function you need to call (after including install.php in your installation script) is, oddly enough, install_drupal()
. The argument you need to pass to this function is less obvious, and here it is, line by line:
2. Set up/clean the environment
Note that this script will not clear or prime the site folder, so your installation will only work if a pristine "settings.php" file is in the site folder you want to install to.
The standard procedure to delete and clear a site is, in pseudocode:
3. Useful modifications in install.php
One disadvantage I've found is the, well, non-interactiveness of the non-interactive installer. If the installer runs through correctly, running the above PHP code will print no output at all. Since installation can take between 30 and 60 seconds on slow PCs, it would be nice to know the installer's progress. To this end, I put the following lines into the install.php file:
@@ -406,6 +406,7 @@ function install_run_task($task, &$insta return; } else { + print "Submitting information to task $function... "; // For non-interactive forms, submit the form programmatically with the // values taken from the installation state. Throw an exception if any // errors were encountered. @@ -415,6 +416,7 @@ function install_run_task($task, &$insta if (!empty($errors)) { throw new Exception(implode("\n", $errors)); } + print "done.\n"; } } @@ -437,6 +439,7 @@ function install_run_task($task, &$insta variable_set('install_current_batch', $function); } else { + print "Running batch process $function... \n"; $batch =& batch_get(); $batch['progressive'] = FALSE; } @@ -469,6 +472,7 @@ function install_run_task($task, &$insta else { // For normal tasks, just return the function result, whatever it is. + if (!$install_state['interactive']) print "Running task $function... \n"; return $function($install_state); }
I'll admit that this is a far cry from an actual installation tool that can be packaged, but it should make setting up test environments or deployment a whole lot easier.