Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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");
share|improve this question

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 & do not care about the command results, then exec("drush ...") is fine, though.

share|improve this answer

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.

share|improve this answer

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

enter image description here

share|improve this answer

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

You must have shell access to execute the drush commands.

share|improve this answer
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 '14 at 12:33
..AND the answer is...... shell_exec() – sobi3ch Apr 18 at 12:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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