Run the Drush command from a PHP script

I am trying to create a site where you can install Drupal via web gui.

<?php

`drush site-install --yes --db-url=mysql://USER:PASSWORD@localhost:3306/DATABASE --account-name=DRUPAL_USER --account-pass=DRUPAL_PASSWORD --account-mail=contact@email.com --site-name=SiteName`;

?>

The above snippet is from a script. If I ran the script in a browser, it did nothing, but if I try to run it as www data with:

php install_script.php

Everything works perfectly! I get drush output in terminal just fine.

Can someone tell me how to run Drush to install / install Drupal with a PHP script? I am completely lost and I do not see what I am doing wrong.

I would be grateful for any help with this! Thank.

+5
source share
4 answers

I seem to have fixed this 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 --account-mail=contact@email.com --site-name=SiteName');
?>

I basically uninstalled the Drush pear package and manually installed Drush 5.0 in / var / www / drush.

+3
source

php exec?. :.

<?php
  exec('drush site-install --yes --db-url=mysql://USER:PASSWORD@localhost:3306/DATABASE --account-name=DRUPAL_USER --account-pass=DRUPAL_PASSWORD --account-mail=contact@email.com --site-name=SiteName');
?>
+2

. , - (, apache www), .

  • Rereading this, I see that you ran it from the command line as www data, but your environment might be different from web servers. Running as www data by running su-www data is a better test than su www-data.
+2
source

I found (running Acquia Dev Desktop on OSX) that almost everything we took for granted in the shell was not available. This is how I got the result - when launched in the context of rules.module php eval ().

# When running from web, drush doesn't have any environment set up,
# has no search paths for site-aliases, and maybe can't even find PHP.
$php = "/Applications/acquia-drupal/php5_4/bin/php";
$drush_php = "/Users/dan/.composer/vendor/bin/drush.php";
$drush_options = " --config=/Users/dan/.drushrc.php ";
$command = "$php $drush_php $drush_options $site_alias status";
$result = exec($command, $output, $return);
drupal_set_message(print_r(array($command, $result, $output, $return), 1));

Obviously, adjust your paths if necessary. The full team ended as follows:

/Applications/acquia-drupal/php5_4/bin/php /Users/dan/.composer/vendor/bin/drush.php --config=/Users/dan/.drushrc.php @example.org.nz status
+1
source

All Articles