Install Drupal 7 with Drush from Git

OK, couldn’t find a good documentation about it so I had to make some research. And since I’ll do it several times, let me take a note of the procedure and share it with you at the same time.

Parts in red should be changed by you to your specific names and details.

  1. Create an empty database, say “mysitedb“. Instructions are out of the scope of this how-to. Do not use a database that already has something in there because this procedure will drop it all.
  2. Configure your web server or hosting system to serve your new site, say “www.mysite.com“. I use DreamHost, so I’ll use DreamHost directory names in this tutorial. Be smart enough to change this directories to meet your system.
  3. Download and install Drush somewhere outside your site directory and make it globally executable:
    cd ~ ;
    mkdir software;
    cd software;
    wget http://ftp.drupal.org/files/projects/drush-7.x-4.4.tar.gz;
    tar -zxvf drush-7.x-4.4.tar.gz;
    rm drush-7.x-4.4.tar.gz;
    echo 'PATH=$PATH:~/software/drush' >> ~/.bashrc;
    echo 'alias drush="drush --package-handler=git_drupalorg" ' >> ~/.bashrc;
    . ~/.bashrc
  4. Prepare a directory to contain Drupal installation and your site files. Part of this was already done in step 2 above but we’ll have to remove the site directory since Drush will create it for us in the process:
    cd ~ ;
    [[ -d www.mysite.com ]] && rm -rf www.mysite.com;
    drush --drupal-project-rename=www.mysite.com dl drupal-7.0
  5. Create your Drupal site configuration and populate the database created on step 1:
    cd www.mysite.com;
    drush site-install standard --site-name="My Site" --site-mail=youremail@gmail.com \
           --account-name=root --account-pass=drupalpass \
           --db-url=mysql://mysitedbuser:dbpass@db.mysite.com/mysitedb \
           --db-prefix=drupal_
  6. Install obvious modules. Git will be used by default (and not tar.gz) because of the alias set on step 3:
    drush dl views;
    drush dl cck;
    drush dl panels;
    drush dl zen;

Thats it !

Now point your browser to www.mysite.com to see your Drupal site ready to be used. Login into Drupal with the user name and password that you used on parameters --account-name and --account-pass on step 5 above and optionally enable the modules you’ve just installed on step 6.

The benefit of maintaining the installation of a software written in some interpreted language (as Drupal with PHP) is on code upgrades. The upgrade process aided by a versioning system (as Git) will cirurgically add, modify and delete the necessary files without leaving old unused files. In a tar.gz (or zip) scenario, you’ll unpack a new version archive over your previous installation, which will not handle correctly specially deleted files.

10 thoughts on “Install Drupal 7 with Drush from Git”

  1. Great tutorial! Can drush be used to manage a local development environment of the drupal code hosted on the server, or do you just have to use pure git?

  2. Useful and straight forward documentation!

    Just additional info, user may also need to install php-cli, git and other dependencies prior using drush. Also, it is a good practice to check if php-cli has enough memory. Some distro has separate php.ini for php-cli. I think number around 128MB to 160MB is sensible.

    Thanks,
    Lucky I. Ismail

  3. Hi, great work, but i tried it now all night without success, maybe you can help me?

    here is the failure output…

    sh: /tput: Datei oder Verzeichnis nicht gefunden
    The following restricted PHP modes have non-empty values: safe_mode. [error]
    This configuration is incompatible with drush. Please check your
    configuration settings in /etc/php5/cli/php.ini or in your drush.ini
    file; see examples/example.drush.ini for details.
    sh: /tput: Datei oder Verzeichnis nicht gefunden
    Command site-install needs a higher bootstrap level to run – you will need invoke drush from a more functional Drupal environment to run this command. [error]
    Command site-install requires Drupal core version 6 or 7 to run. [error]
    The drush command ‘site-install standard’ could not be executed. [error]
    A Drupal installation directory could not be found

  4. Can any one help me how to set up the very first step “mysitedb”. I am new to this drupal web. I am franrically trying to set up my own Semantic Web. Any comments step by step documentation helps me.

    Thanks in advance.
    -Solomon

  5. Just hi additional info, user may also need to install php-cli and git and other dependencies prior using drush. Also, it is a good practice to check if php-cli has enough memory. Some distro has separate php.ini for php-cli. I think number around 128MB to 160MB is sensible.

  6. It seems you forgot a step…or at least it was necessary for me…before running site-install, you need to download Drupal to the current directory:

    drush dl drupal

  7. I was mistaken…it seems that the issue was that I forgot to do:
    . ~/.bashrc

    But once I did that I got another error:

    “Unknown option: –package-handler. See `drush help help` for available options. To suppress this error, add the option –strict=0”

    Another user said setting –strict=0 solved the problem, but that wasn’t my experience – it still didn’t work, it just suppressed the error message like it said.

    I’m using the latest version of drush (drush 5) which I got from git, rather than using the command:
    wget http://ftp.drupal.org/files/projects/drush-7.x-4.4.tar.gz;

    So maybe that’s the difference…

Leave a Reply

Your email address will not be published. Required fields are marked *