Can any one please tell me how can I execute drush command from devel/php?

I can execute PHP codes from devel/php. But I don't know how can I execute drush command from devel/php. (As we know "devel/php" URL coming from devel module).

I have written some custom drush command for cron purpose. I can able to run those commands from command line.

> drush my-cmd or drush cc all or drush status , etc ... I can run it through command line.

Expecting some function as mentioned below to run from devel/php

some_function("drush cc all");

4 Answers 4


Someone tried to create a module to provide shell access from within a Drupal site, but it was never fully debugged. See the Drupal Terminal project. Perhaps there have been advances in the jQuery terminal that might make it easier to get this working if someone revisited it.

If you want to exec Drush from within php, it is generally better to use drush_invoke_process() rather than exec("drush ...").

$values = drush_invoke_process("@site", "cc", array("all"), array("verbose"));

If you are just running a one-off command and you don't care about the command results, then exec("drush ...") is fine, though.


As kalidasan suggests, you could use the exec() function, to do something like:

exec("drush fra -y", $output); var_dump($output);

Normally, devel will run this command where the settings.php is located, in case you have a custom multi-site architecture and you need to run the drush command from another path, you could chain commands (using ";" semi colon) to access to the right path and run the drush command:

exec("cd {absolute or relative path to your settings.php site}; drush fra -y;", $output); var_dump($output);

Sometimes, running drush commands from devel/php is useful when you need to execute functionalities from drush but you don't have access to the command line shell or permission to run it.

Note: I used "drush fra" only as an example, it could be used with any other drush command.


Finally found solution. shell_exec("drush status") is working fine.

enter image description here


Drush is a command line shell and Unix scripting interface for Drupal.

You must have shell access to execute the drush commands.

  • There is a way to do it from devel/php. I hope you know use of exec(). Similar way we can execute drush command through devel/php. I can't accept your answer.
    – Kalidasan
    Aug 23, 2014 at 12:33
  • ..AND the answer is...... shell_exec()
    – sobi3ch
    Apr 18, 2016 at 12:52
  • @sobi3ch Is it possible to make backup of the site and database using php code in devel? Please share the script. Considering this is the only option available to me. I cannot install backup_migrate module.
    – Umair
    Mar 11, 2018 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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