Installing Drupal 7 non-interactively
I'm currently chasing a wild goose of an idea in Drupal 7, and found myself in a situation where it would be really convenient to run the Drupal install script through a debugger. Normally, this won't work because the installer runs through many stages of redirect plus batch api. However, I knew I had read that there were changes in Drupal 7 to make this possible, and catch pointed out in IRC that Drush can install Drupal now. So I went over to see how Drush does it and half an hour later I had the following script. Drop it into a standalone PHP file and you're set to go.
The key to this is the function install_drupal() and the array of settings which mimcs the values of the forms you would normally submit by hand. When you pass that array to install_drupal(), then Drupal goes into non-interactive mode and installs in one page request.
So here's the code. Make a PHP file in your Drupal root directory (note it must be in a Drupal root directory or else you have to edit the DRUPAL_ROOT define), add this code, edit the details (all are pretty self-explanatory), hit it with something, and you're off to the races. Yes you can use Drush and 99% of the time that will be fine, but maybe someone will find this useful too.
EDIT: It was pointed out to me that the update_status_module settings are not particularly self-explanatory. It is a two-element array. If element 1 is TRUE, then update status is enabled. If 1 and 2 are both TRUE then update status is enabled and email notifications are turned on.
/**
* Global flag to indicate that site is in installation mode.
*/
define('MAINTENANCE_MODE', 'install');
/**
* Root directory of Drupal installation.
*/
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/install.core.inc';
$settings = array(
'parameters' => array(
'profile' => 'standard',
'locale' => 'en',
),
'forms' => array(
'install_settings_form' => array(
'driver' => 'mysql',
'username' => 'myuser',
'host' => 'myhost',
'port' => '',
'password' => 'mypass',
'database' => 'mydbname',
),
'install_configure_form' => array(
'site_name' => 'my site',
'site_mail' => 'me@me.com',
'account' => array(
'name' => 'admin',
'mail' => 'me@me.com',
'pass' => array(
'pass1' => 'adminpass',
'pass2' => 'adminpass',
),
),
'update_status_module' => array(
1 => TRUE,
2 => TRUE,
),
'clean_url' => TRUE,
),
),
);
install_drupal($settings);
topics: drupalplanet drupal