Drupal 7 First Look
上QQ阅读APP看书,第一时间看更新

Command-line installation

Administrators who manage lots of sites or who prefer to work from the command line will be thrilled with the change to make Drupal installable from the command line. If you want to run the installation from the command line, you will need to use the following procedure:

  1. Download Drupal from Drupal.org and copy the files to your server.
  2. Create a PHP script to run the Drupal command line using the following procedure:

    i. Create a file called install.site.php where site is the name of your site. This file should be located in the same directory where your install.php file is located (the root directory for your site).

    ii. Open the install.site.php file in your favorite file editor.

    iii. Enter the following script:

    <?php
    include_once 'install.php';
    
    $settings = array(
      'parameters' => array(
        'profile' => 'default',
        'locale' => 'en',
      ),
      'forms' => array(
        'install_settings_form' => array(
          'driver' => 'mysql',
          'database' => 'my_db_name',
          'username' => 'my_db_username',
          'password' => 'my_db_password',
        ),
        'install_configure_form' => array(
          'site_name' => 'My site',
          'site_mail' => 'admin@example.com',
          'account' => array(
            'name' => 'admin',
            'mail' => 'admin@example.com',
            'pass' => array(
              'pass1' => 'my_site_password',
              'pass2' => 'my_site_password',
            ),
          ),
          'update_status_module' => array(1 => TRUE),
          'clean_url' => TRUE,
        ),
      ),
    );
    install_drupal($settings);
    ?>

    This code is used to configure the installation so Drupal knows what values to use during the installation process to properly configure your site as it is created.

    iv. Modify the values in the above code snippet to match the needs of the site you want to install. You will need to pay special attention to the database information including the database name, username, and password. You should also modify the administrator's password, site name, and so on to match the desired values for your site.

    v. Save the file with all of your changes.

  3. Run the install.site.php file from the command line using the syntax:
    php install.site.php 
    
  4. After the installation completes, you can verify your site and begin configuring it as usual.
  5. After completing the installation, you should back up the install file and either remove it from your site completely or remove access to the file for all users since it contains the login information for User 1.

Although this setup is a little more complicated to run initially, it can be a big time saver if you are installing a large number of sites or want to run an unattended installation.