Main navigation

Updating multiple standalone sites on the same server using Drush

At work, the drupal hosting sites were growing and it has become cumbersome and tedious to update them individually on our VPS server. At first we thought it would be great to have a central site to manage all other Drupal sites but we drop this idea pretty quickly as explianed below.

Before we begin, we are not talking about multisite installation. It has it good points and that is running one codebase to power many sites (mostly) sharing the same configurations and modules. But the biggest problem is that if it goes down or hacked, all the site will too.

Aegir was the first thing that came to mind. However, as much as it would have handled the job nicely, it was probably yet another system to maintain taking up more resources and time.

At the end, the best solution as using Drush. Sure you don't get the the nice UI to monitor your sites but it works and it's simple without the need of any heavy maintenance work.

What we did was create a script, called aliases.drushrc.php and copied it into ~/.drush/aliases.drushrc.php and added the following:

This is nice, now all we had to do is run drush command to update the each site without the need to navigate to the site's own directory and execute drush from there. We just target site1 or site2, like this: drush @site1 status

The command will display the status of the site. If you wanted to find out the status for site2, you issue the command: drush @site2 status

--------------------------------------------

Update 25th Oct:
Actually, below code is not required. You can simply use the code above and append sites to the file name, like: sites.aliases.drushrc.php and it will still work the same way

--------------------------------------------

We are almost there, however again this is cumbersome having to issue each command separately. So we needed to expand on what we already have in the script to do it concurrently. So finally, we came up with this:

This will now go thru both site1 and site2 and print out the status for both sites. The command to update all sites drupal code is: drush @sites pm-update projects drupal-7.41

One last annoyance after updating your drupal site with Drush is that is overwrites your .htaccess and robot.txt files. There might be times when you have added custom redirectives in your .htaccess file you want to preserve. Pantheon recommends to set it in your settings.php file and we think that is the best solution, see: https://pantheon.io/docs/articles/sites/code/redirect-incoming-requests/.

As you can see, it's not great having to add each site into the script as we have about 20+ sites. But it works and it does offer a choice of executing either an individual site or all the sites which was important to us since we don't always have to update or install all modules on all sites depending on what updates becomes available or what modules are needed on specific sites. For security update, we can do a security update on all of the sites at once, total time saver.