Automatic Drush Aliases
This config automatically scans all sites in /var/www/html
and makes an alias out of the subdomain. Additionally it detects if there is a www folder inside the site folder.
/etc/drush/aliases.drushrc.php
:
<?php
$sites = array_diff(scandir('/var/www/html'), array('..', '.'));
foreach ($sites as $val) {
$tmp = explode('.', $val)[0];
if (file_exists("/var/www/html/${val}/www")) {
$aliases[$tmp]['root'] = "/var/www/html/${val}/www";
} else {
$aliases[$tmp]['root'] = "/var/www/html/${val}";
}
$aliases[$tmp]['uri'] = "http://${val}";
$aliases[$tmp]['path-aliases']['%drush'] = '/usr/bin';
$aliases[$tmp]['path-aliases']['%site'] = 'sites/default/';
}
if we have the following sites:
# ls /var/www/html/
www.example.com stg.example.com
We now see this automatically:
# drush site-alias
@none
@stg
@www