Before I start let me just said that there are probably other ways to do this, but this solution worked for me and I am sharing it so that it can help anyone in a similar situation.

I have a shared hosting account where I, over time, have been creating multiple Drupal installations for different clients or projects of my own. I never did a multi-site installation and I don't share modules between the sites. My share hosting company has Drush installed server wide and the process of updating sites is painless, but it was just taking me forever to login into SSH, then CD into each site folder, and run the drush command to check for update, and to run the updates. I also like removing those text files that come with every Drupal installation like LICENSE.txt

My current site structure:


The solution, in my case, was to create a single PHP that will check every folder and then apply the update and delete the files. Here is the code:


  This file was created by Emil Acosta
  to keep all drupal sites hosted on this
  account upto date with a minimum effort 
  using the Drush tool.

// Base path
$mypath = '/main';

// Drush path
$drush_path = $mypath.'/drush/drush';

// Drupal sites
$mysites = array(

// Unwanted files
$unwanted = array(

//Drush Commands to execute
$commands = array(
					'Clearing site cache' => 'cc all',
					'Running cron' => 'cron',
					'Checking for updates' => 'rf',
					'Applying the updates' => 'up -y',

foreach ($mysites as $site) {
  echo "\n**********************************************************\n";
  echo "       START UPDATING SITE: ".$site;
  echo "\n**********************************************************\n";
  echo 'Start in directory: '.getcwd() . "\n";
  echo 'Working in directory: '.getcwd() . "\n\n";

  // Start Drush Update Process
  foreach ($commands as $steps => $command) {
    echo "   ".$steps."\n";
    echo "------------------------------------------------------\n";
    $output = shell_exec($drush_path.' '.$command);
    echo $output."\n";  
  // Remove unwanted files
  foreach ($unwanted as $filename) {
    if (file_exists($filename)) {
      $output = shell_exec('rm '.$filename);
      echo "File: '$file' was removed.\n";

  echo "\n\n";
  echo 'Back to my base directory: '.getcwd() . "\n";

  echo "\n**********************************************************\n";
  echo "       END UPDATING SITE: ".$site;
  echo "\n**********************************************************\n";



It is a good practice if only the owner can execute the file and place the file outside the web root so that it can not be access from the internet. To run the file in your shell type:

php msu.php

or sudo it

sudo php msu.php

or check a shell shortcut

alias msu-drush="php ~/PATH-TO-MSU-FILE/msu.php"

If you have any comments or suggestions please post them below.

Thank you,

Emil Acosta


XTCHost’s picture

Can you please advise


All my sites are located in /home

So I have



1. Where I would put my php file

2. Would I need to list all my sites in the // Drupal sites
$mysites = array(

I would love to think there was a way round this as I have 70 sites and am adding more

Your script looks like it will save a lot of time and repetitive work

Many thanks for your help and idea

PS I also like removing those text files that come with every Drupal installation like LICENSE.txt

emilorol’s picture


I am glad to know that it will help you. 70 sites and growing, wow that is a lot of drush commands.

Now back to you case:

1. Your base path is going to be:

// Base path
$mypath = '/home';

2. Yes, you will need to list of your sites location in the $mysites array. The posibilities are endless here, you can write an small Drupal module that you can install in all the sites that will register the site directory path in a DB and update the script to call the DB and grab the sites paths from there and build the $mysites array with that data. You can also using the shell go to /home (cd /home) and list all folders there (ls) and copy the output to later add it to the $mysites array. Maybe using PHP you can tell to scan all the folders inside the /home directory and check X file or Y folder exist indicating that the site in that folder is Drupal and then run all the Drush commands.

3. Your sites array is going to look like this:

// Drupal sites
$mysites = array(

You're welcome.

Note: I have not tested the script with so many sites, but keep in mind that it might timeout or you might run out of memory for PHP to execute it, in any case both situations are easily fix.

Emil Orol
"In the computer business you’re either a one or a zero and I am determined never to be zero."