I am using Drush 9 and Drupal 8. When I execute drush site:install I find that it also modifies the permission of the web/site/default directory to r-xr-x--x, which troubles me delete that directory later. I want that directory to be 740 in my case. So two methods came to my mind. One is to run a custom shell script as post drush si or to override the default dush si command. I tried to go through some blogs but I couldn't understand them. Please explain stepwise.

How can I invoke a custom shell script to drush site:install which will be run just after that command is executed.

How can I override the default site:install command?

Note: I am using Drupal composer project. So I have a drush folder outside the webroot but I don't know if I can edit some files in that directory and write my custom commands.

  • 1
    Every time the cache is cleared in Drupal and some other similar events, it will lock those folders down. – Kevin Nov 20 '18 at 21:44
  • 1
    So you mean it is not only matter of drush si but any command is executed it will modify the permission. Any way to provide my custom permission ? – SkyRar Nov 20 '18 at 21:47
  • 1
    @Kevin I examined with drush cr and cc. But It doesn't modify the permission. Only drush si does – SkyRar Nov 20 '18 at 21:54

Greg's answer is great. But to more precisely answer this particular question follow the below steps.

1- As you are using Drupal composer project template, Go to the directory your_drupal_project/drush and create a file called SiteInstallCommands.php. You can see there are another similar file PolicyCommands.php.

2- SiteInstallCommands.php should have below code snippets. installTest() is your custom commands that is going to be executed post site:install. So change it according to your needs.


namespace Drush\Commands;

class SiteInstallCommands extends DrushCommands

     * Executing command just after `drush site:install`
     * @hook post-command site-install
    public function installTest() {
        drush_shell_exec('echo test');

See the example file PolicyCommands.php in the Druhs examples directory. Create a directory named "Commands" in your site's "drush" directory, and put your command file there. Its name must end with "Commands.php" or "Hooks.php".

Create a hook similar to one of the ones shown in the example file. You'll want @hook post-command site:install.

  • 1
    Thanks. Do I also need to define drush.yml here github.com/drupal-composer/drupal-project/tree/8.x/drush ? Is there anything I need to define or edit ? Can you please have a look on this link ? – SkyRar Nov 21 '18 at 1:34
  • 1
    For testing purpose, as per the documentation I run drush --include=/var/www/drupal/vendor/drush/drush/examples xkcd , drush cc drush, then drush xkcd, but getting error command is not defined. Am I missing something ? – SkyRar Nov 21 '18 at 3:19
  • If you put your command in /var/www/drupal/drush/Commands, then you do not need --include – greg_1_anderson Nov 22 '18 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.