Search code examples
phpinstallationdrush

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.


Solution

  • 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.