Answers.Body: <p>What finally made it work was this:</p>
  
  <p>First I needed to set the <code>CIVICRM_SETTINGS</code> env variable to the civicrm.settings.php file for my subsite </p>
  
  <pre><code> export CIVICRM_SETTINGS=/var/aegir/platforms/example/sites/my.site.org/civicrm.settings.php
  </code></pre>
  
  <p>Only then could I execute the php file export.php, not with src but with php-script</p>
  
  <pre><code>drush php-script  /var/aegir/platforms/example/sites/all/civicrm/bin/csv/export.php -e Contact
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-05T09:18:43.167Z
Answers.LastActivityDate: 2018-10-05T09:18:43.167Z
Answers.UserDisplayName: Marko
Answers.Body: <p>To execute a PHP script in the context of a selected site, use <code>drush php-script</code> or <code>drush scr</code>.</p>
  
  <p>In your question you specified the site using <code>-s example.org</code>, and I suspect you may be looking for <code>-l</code> (<code>--uri</code>) rather than <code>-s</code> (<code>--simulate</code>) to determine which site to load. See the first section of <code>drush help</code> output for these flags.</p>
  
  <p>If <code>-l</code> doesn't do it, you can also use aliases which Aegir automatically creates for each site - you should find that <code>drush @example.org vget site_name</code> works and returns the name of the expected site, because there will be alias files in eg <code>/var/aegir/.drush/EXAMPLE.ORG.alias.drushrc.php</code> for each site.</p>
  
  <p>So, you probably want something like: <code>drush -l example.org scr /path/to/export.php</code></p>
  
  <ul>
  <li>If <code>drush vget site_name</code> returns the name of the expected site, you've confirmed Drush can connect to Drupal.</li>
  <li>If <code>drush cvapi Contact.get</code> returns contacts from your site, you've confirmed that CiviCRM works when called via Drush.</li>
  <li>If <code>drush scr import.php</code> or <code>drush scr export.php</code> still don't work, that sounds like those scripts don't bootstrap "normally" for CiviCRM and there may be work to do to get them to behave.</li>
  </ul>
  
  <p>I don't actually know how <code>import.php</code>/<code>export.php</code> are expected to behave - so I might have led you astray. Looking at them, I'd expect <code>export.php</code> probably works via Drush, but I see <code>import.php</code> is looking for <code>$_GET['file']</code> which Id' expect to require special treatment for Drush use (but I see <a href="https://civicrm.stackexchange.com/questions/4723/how-do-i-import-contacts-through-the-command-line">this SE answer</a> says it works using <code>--file=blah.csv</code>, and that you should call them via <code>php import.php</code> not <code>drush</code>).</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-30T14:26:35.483Z
Answers.Text: Unfortunately I get the same error. Alias works (drush @mysite.org help works) but I still get Could not load the settings file at: /var/aegir/platforms/beta/sites/all/modules/civicrm/../../../default/civicrm.settings.php. I guess it's still targeting the wrong civicrm.settings.php (the default one instead of mysite specific
Answers.UserDisplayName: Marko
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-30T22:49:22.747Z
Answers.Text: Good point - `drush help` works whether or not you have a valid site. I've updated my answer to recommend `drush vget site_name` which will confirm that Drush executes *and* connects to the site you expect.
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-06T11:48:34.477Z
Answers.Text: Yeah, drush works, and it identifies the proper site_name, but I can't execute the export script. I always get that same error.
Answers.UserDisplayName: Marko
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-30T02:50:14.230Z
Answers.LastActivityDate: 2018-01-30T23:08:59.043Z
Answers.LastEditDate: 2018-01-30T23:08:59.043Z
Answers.UserDisplayName: Chris Burgess
Body: <p>How do I use export.php and import.php to work with multiple sites run with Aegir.</p>
  
  <p>All of them share the same files (php classes) and when I specify the site with -s mysite.org I get nothing (literally the command executes without error it just doesn't output anything).</p>
  
  <p>When I run without spcifying mysite </p>
  
  <pre><code>php export.php -e Contact
  </code></pre>
  
  <blockquote>
    <p>PHP Warning: 
    include_once(/var/aegir/platforms/beta/sites/all/modules/civicrm/../../../default/civicrm.settings.php):
    failed to open stream: No such file or directory in
    /var/aegir/platforms/beta/sites/all/modules/civicrm/civicrm.config.php
    on line 118 PHP Warning:  include_once(): Failed opening
    '/var/aegir/platforms/beta/sites/all/modules/civicrm/../../../default/civicrm.settings.php'
    for inclusion (include_path='.:/usr/share/php') in
    /var/aegir/platforms/beta/sites/all/modules/civicrm/civicrm.config.php
    on line 118</p>
  </blockquote>
  
Tags: <import><civicrm.settings.php><core><multisite><drupal-multi-site>
Title: How do I use import and export php classes with aegir?
ThreadText: # How do I use import and export php classes with aegir?
  
  (Asked by: username_0 on 2018-01-29)
  
  How do I use export.php and import.php to work with multiple sites run with Aegir.
  All of them share the same files (php classes) and when I specify the site with -s mysite.org I get nothing (literally the command executes without error it just doesn't output anything).
  When I run without spcifying mysite 
  php export.php -e Contact
  
  
  PHP Warning: 
    include_once(/var/aegir/platforms/beta/sites/all/modules/civicrm/../../../default/civicrm.settings.php):
    failed to open stream: No such file or directory in
    /var/aegir/platforms/beta/sites/all/modules/civicrm/civicrm.config.php
    on line 118 PHP Warning:  include_once(): Failed opening
    '/var/aegir/platforms/beta/sites/all/modules/civicrm/../../../default/civicrm.settings.php'
    for inclusion (include_path='.:/usr/share/php') in
    /var/aegir/platforms/beta/sites/all/modules/civicrm/civicrm.config.php
    on line 118
  
  **Tags:** import, civicrm.settings.php, core, multisite, drupal-multi-site
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2018-10-05. Score: 1 | Accepted answer
  
  What finally made it work was this:
  First I needed to set the CIVICRM_SETTINGS env variable to the civicrm.settings.php file for my subsite 
   export CIVICRM_SETTINGS=/var/aegir/platforms/example/sites/my.site.org/civicrm.settings.php
  
  Only then could I execute the php file export.php, not with src but with php-script
  drush php-script  /var/aegir/platforms/example/sites/all/civicrm/bin/csv/export.php -e Contact
  
  
  ---
  
  ### Answer by username_1 on 2018-01-30. Score: 1
  
  To execute a PHP script in the context of a selected site, use `drush php-script` or `drush scr`.
  
  In your question you specified the site using `-s example.org`, and I suspect you may be looking for `-l` (`--uri`) rather than `-s` (`--simulate`) to determine which site to load. See the first section of `drush help` output for these flags.
  
  If `-l` doesn't do it, you can also use aliases which Aegir automatically creates for each site - you should find that `drush @example.org vget site_name` works and returns the name of the expected site, because there will be alias files in eg `/var/aegir/.drush/EXAMPLE.ORG.alias.drushrc.php` for each site.
  
  So, you probably want something like: `drush -l example.org scr /path/to/export.php`
  
  * If `drush vget site_name` returns the name of the expected site, you've confirmed Drush can connect to Drupal.
  * If `drush cvapi Contact.get` returns contacts from your site, you've confirmed that CiviCRM works when called via Drush.
  * If `drush scr import.php` or `drush scr export.php` still don't work, that sounds like those scripts don't bootstrap "normally" for CiviCRM and there may be work to do to get them to behave.
  
  I don't actually know how `import.php`/`export.php` are expected to behave - so I might have led you astray. Looking at them, I'd expect `export.php` probably works via Drush, but I see `import.php` is looking for `$_GET['file']` which Id' expect to require special treatment for Drush use (but I see [this SE answer](https://civicrm.stackexchange.com/questions/4723/how-do-i-import-contacts-through-the-command-line) says it works using `--file=blah.csv`, and that you should call them via `php import.php` not `drush`).
  
  > **Comments:**
  > **username_0**: Unfortunately I get the same error. Alias works (drush @mysite.org help works) but I still get Could not load the settings file at: /var/aegir/platforms/beta/sites/all/modules/civicrm/../../../default/civicrm.settings.php. I guess it's still targeting the wrong civicrm.settings.php (the default one instead of mysite specific  
  > **username_1**: Good point - `drush help` works whether or not you have a valid site. I've updated my answer to recommend `drush vget site_name` which will confirm that Drush executes *and* connects to the site you expect.  
  > **username_0**: Yeah, drush works, and it identifies the proper site_name, but I can't execute the export script. I always get that same error.  
  
  ---
  
  