Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Drush command from a PHP script

I'm trying to build a site where you can install Drupal through a web gui.

<?php

`drush site-install --yes --db-url=mysql://USER:PASSWORD@localhost:3306/DATABASE --account-name=DRUPAL_USER --account-pass=DRUPAL_PASSWORD [email protected] --site-name=SiteName`;

?>

The above is a snippet from the script. If I run the script from the browser it doesn't do anything, but if I try to run it as www-data with:

php install_script.php

Everything works perfectly! I get Drush's output in the terminal just fine.

Can anyone tell me how to trigger Drush to do the Drupal installation/setup from a PHP script? I'm completely lost and I can't see what I'm doing wrong.

I'll appreciate any help on this! Thanks.

like image 929
hhorn Avatar asked Feb 27 '12 11:02

hhorn


People also ask

How do I run Drush command in Drupal 8?

Drush can be run by typing drush from within your project's root directory -- or anywhere within the Drupal site. You can filter commands according to module by running drush list with the --filter option. To execute any command, type drush {command_name} .

How do you run the Drush command in Pantheon?

Example Usageremote:drush <site>. <env> -- <command> Runs the Drush command <command> remotely on <site>'s <env> environment.


2 Answers

I've seem to have fixed it by doing this from php:

<?php
exec('/usr/bin/php /var/www/drush/drush.php site-install --yes --db-url=mysql://USER:PASSWORD@localhost:3306/DATABASE --account-name=DRUPAL_USER --account-pass=DRUPAL_PASSWORD [email protected] --site-name=SiteName');
?>

I basically removed the Drush pear package and manually installed Drush 5.0 into /var/www/drush.

like image 198
hhorn Avatar answered Sep 18 '22 00:09

hhorn


What about php exec function?. I.e.:

<?php
  exec('drush site-install --yes --db-url=mysql://USER:PASSWORD@localhost:3306/DATABASE --account-name=DRUPAL_USER --account-pass=DRUPAL_PASSWORD [email protected] --site-name=SiteName');
?>
like image 34
oscarmlage Avatar answered Sep 17 '22 00:09

oscarmlage