3

I'm using Aegir and want to inject some data into a site's vhost. And I managed to do it thanks to this post.

My problem is I can't find an Aegir function to load a site's dabase configurations from this Aegir functions listing to do it programmatically on each site-verify.

I need to find a function or method that would return a site's data:

  • db_name
  • db_user
  • db_passwd
  • etc

I tried Provision_Config('mysite.com') but I have a template argument missing error.

Does anyone know which function I should use to get the data? I usually use drush sql-connect in ssh, but here I'm not sure it would be a clean way as it should be in a php script.

The goal is to make Drupal work with multi-site / multi-folder (I'm aware of that post and patch, but my solution seems to work for me without having to patch anything):

<VirtualHost *:80>
  DocumentRoot /var/aegir/platforms/myplatform

  ServerName mysite1.com
  SetEnv db_type  mysql
  SetEnv db_name  mydbname_1
  SetEnv db_user  mydbname_1
  SetEnv db_passwd  *********
  SetEnv db_host  localhost
  SetEnv db_port  9854

  # Credentials from other Aegir's site
  # located in a subfolder /blog.
  <Location /blog>
    SetEnv db_type  mysql
    SetEnv db_name  mydbname_2
    SetEnv db_user  mydbname_2
    SetEnv db_passwd  *********
    SetEnv db_host  localhost
    SetEnv db_port  1258
  </Location>

</VirtualHost>
2
  • I'm not 100% certain I understand what you're after, but if I recall correctly, the vhost files are generated by templates, same way as theme output is. So find the template and you can work out how the data gets there. :)
    – Letharion
    Nov 4, 2014 at 20:25
  • Well actually this hook drush_hook_provision_apache_vhost_config let's me alter the output of the vhost file which would let me add the <Location /blog> data as needed. My problem is trying to use the Provision_Config_Apache_Site class to get the other site db information.
    – ErikaW
    Nov 5, 2014 at 10:13

2 Answers 2

14

Installing sites in sub-directories is supported in Aegir 2+ without any such hacking. Just enable the "Site subdirectories" feature, under the 'experimental' group at admin/hosting/features.

That said, to answer your question, DB credentials are available via drush_get_context('site').

0
1

I usually use drush sql-connect in ssh, but here I'm not sure it would be a clean way as it should be in a php script.

If I understand correctly, you are writing a custom PHP script that needs to connect to the database of a Drupal site managed by Aegir?

If yes, you can use:

$ drush php-script your-script.php

This bootstraps Drupal (and connects the database) and will call your script as if you had run $ php your-script.php on the command line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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