5

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 --account-mail=contact@email.com --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.

hhorn
  • 101
  • 1
  • 7

4 Answers4

3

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 --account-mail=contact@email.com --site-name=SiteName');
?>

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

hhorn
  • 101
  • 1
  • 7
2

This could easily have been a permissions problem. When you invoke a page from a browser, it's being run by the webserver user (e.g. apache or www), but when you run from the command line you're running it as yourself.

  • Rereading this I see you ran it from the command line as www-data, but your environment might have been different than the webservers. Running as www-data by running su - www-data is a better test than su www-data.
Paul DeWolf
  • 311
  • 3
  • 5
2

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 --account-mail=contact@email.com --site-name=SiteName');
?>
oscarmlage
  • 1,445
  • 2
  • 12
  • 23
  • Unfortunately it doesn't change anything. If I put that in my script instead and run it from the browser I get no result. If I run it as www-data with php install_script.php it works fine. – hhorn Feb 27 '12 at 12:17
  • Maybe php-cli (php install_script.php) and browser execution (http://localhost/whatever/install_script.php) had distinct enviroments, vars and so. Try it out with the full drush path (/usr/local/bin/drush...). – oscarmlage Feb 27 '12 at 12:34
  • Good guess, but it still gives me that same result. – hhorn Feb 27 '12 at 12:44
1

I found (running Acquia Dev Desktop on OSX) that pretty much everything we take for granted in the shell was unavailable. Here's how I got a result - when running in a rules.module php eval() context.

# 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 as appropriate. The full command ended up as:

/Applications/acquia-drupal/php5_4/bin/php /Users/dan/.composer/vendor/bin/drush.php --config=/Users/dan/.drushrc.php @example.org.nz status
dman
  • 1,089
  • 13
  • 9