I needed a programatic way to deploy and install Drupal sites using an installation profile. I  found that I could use an automated installation profile to create new sites with basic customization rather quickly. I wanted to take this one step further to automate the installation process programatically. Drupal 5 makes creating automated install profiles straitforeward. If all the data is filled in, it completes the install, and the admin account is created after the install process. A shell script can configure the database information and then execute the Drupal installs script. The Drupal 6 installation process makes this more dificult. In Drupal 6, the installation process adds an extra step for the user to complete before finishing up the site configuration and finishing the installation. This makes creating an automated installation profile more challenging. I started digging thought the Drupal API and I came up with a method to automate the process. Using hook_form_alter allows the configuration form to be auto populated. From there we can also process the form using drupal_prepare_form and drupal_process_form()

function myprofile_form_alter(&$form, $form_state, $form_id) {

if ($form_id == 'install_configure') {

// Set default for site name field.

$form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME'];

$form['site_information']['site_mail']['#default_value'] = 'example@example.com';

//admin settings

$form['admin_account']['account']['name']['#default_value'] = 'admin';

$form['admin_account']['account']['mail']['#default_value'] = 'example@example.com';

$form['admin_account']['account']['pass']['#value']['pass1'] = $form['admin_account']['account']['pass']['#value']['pass2'] = 'password';

$form['#post'] = $form;

drupal_prepare_form($form_id, $form, $form);

drupal_process_form($form_id, $form, $form);

}

}

Next we can execute the install script with the specified install profile (Eg: http://example.com/install.php?profile=myprofile) to complete the installation. You can then visit the newly installed site that has been configured.

Tags:
  1. Anonymous on Fri, 06/26/2009 - 04:32

    I see that all the fields are auto filled in and you just have to press submit for the install. Smart :) But what I am thinking about is: How to call this install profile form from a shell script. I mean so one does not need to use a browser for any steps of the install?

    Any ideas? Curl maybe, but maybe you know an easier way?

  2. reaneyk on Fri, 06/26/2009 - 21:53

    Yeah, for my senario I was using wget.

    For example:

    wget -q --keep-session-cookies http:/example.com/install.php?profile=default

    If I remember right there were some issues with earlier releases of D 6.x that did not allow the install.php script to fully run and would stop half way though the DB creation, but I believe that issue is resolved now. One thing to make sure is that you keep the session cookies since they are required for the install, but not documented at this point. See the following URL for more info.

    http://drupal.org/node/2946

    Another way that I've been starting to research is bootstrapping Drupal and running the installation script directly through PHP. So far I have some of the update functions figured out, but not the installations. I might blog on this later when I have more complete information.

  3. Anonymous on Thu, 06/25/2009 - 16:56

    Do you know how to automatically submit the form. As i see it it is the only step missing?

  4. reaneyk on Thu, 06/25/2009 - 18:35

    In my experience, the script will automatically submit depending on the server that the site is running on. The drupal_prepare_form and drupal_process_form will automatically submit the form as long as all the fields are filled in. I tested this out on an Ubuntu/Debian based system running Apache and the form will automatically submit, although the same installation profile did not submit on a Redhat Enterprise 5. I checked and both servers seem to have the same Apache configuration but I could have missed something.

  5. Post new comment

    The content of this field is kept private and will not be shown publicly.
    • Web page addresses and e-mail addresses turn into links automatically.
    • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
    • Lines and paragraphs break automatically.

    More information about formatting options