Answers.Body: <p>Note that civix does not generate/add anything because it can not find your civicrm.settings.php - that's a configuration issue</p>
  
  <p>Can you e.g.</p>
  
  <pre><code>civix generate:api -h
  </code></pre>
  
  <p>Note the option that you can set an environment variable CIVICRM_SETTINGS pointing to where your civicrm.settings.php is - if needed.  </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-02T00:32:50.823Z
Answers.LastActivityDate: 2016-07-02T00:32:50.823Z
Answers.UserDisplayName: KarinG - Semper IT
Answers.Body: <p>The <code>generate:api</code> subcommand (and a few others) require access to a working copy of CiviCRM.</p>
  
  <p>To locate this, it uses a process reminiscent of <code>drush</code> or <code>wp-cli</code>. For example, if the command-line is running inside <code>/var/www/sites/default/files/civicrm/ext/org.example.foo/</code>, then it will perform an upward search to find the CMS root:</p>
  
  <pre><code>/var/www/sites/default/files/civicrm/ext/org.example.foo
  /var/www/sites/default/files/civicrm/ext
  /var/www/sites/default/files/civicrm
  /var/www/sites/default/files
  /var/www/sites/default
  /var/www/sites
  /var/www
  /var
  </code></pre>
  
  <p>In each case, it is looking for a tell-tale sign of a CMS+Civi system. For example, in a typical Drupal installation, you'd expect to see the file <code>sites/default/civicrm.settings.php</code>.</p>
  
  <p>There are some cases where the default search may not work correctly, e.g.</p>
  
  <ul>
  <li>Using a new or custom CMS.</li>
  <li>Using a multisite configuration.</li>
  <li>Using symlinks.</li>
  </ul>
  
  <p>The quickest way to resolve this? Don't rely on a search. Instead, tell <code>civix</code> specifically where to find your copy of CiviCRM by setting the variable <code>CIVICRM_SETTINGS</code>, e.g.</p>
  
  <pre><code>export CIVICRM_SETTINGS=/var/www/sites/default/civicrm.settings.php
  civix generate:api ...
  </code></pre>
  
  <p>More aggressive ways to resolve this would be:</p>
  
  <ul>
  <li>Arrange your directory structure so that it looks like a normal build (e.g. replace symlinks with real folders).</li>
  <li>Use <a href="https://github.com/civicrm/civicrm-buildkit/" rel="noreferrer"><code>civibuild</code></a> for your dev sites. It always produces standard builds.</li>
  <li>Submit a patch for <a href="https://github.com/civicrm/cv/blob/master/src/Bootstrap.php" rel="noreferrer"><code>Civi/Cv/Bootstrap</code></a> to add support for your directory structure.</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-18T10:58:00.217Z
Answers.Text: Note sure if this answer is still true today? https://github.com/civicrm/cv/issues/130
Answers.UserDisplayName: artfulrobot
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-07-02T00:57:26.017Z
Answers.LastActivityDate: 2016-07-02T00:57:26.017Z
Answers.UserDisplayName: Tim Otten
Body: <p>I used the command <code>civix generate:api Civicrmzapier submit</code> to an API function to an extension i am working on, but got the following error as on the screenshot and the api function is not added.</p>
  
  <p><a href="https://i.sstatic.net/EFT99.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/EFT99.png" alt="Civix Error unable to find civicrm.settings.php file"></a></p>
  
  <blockquote>
    <p>Failed to locate civicrm.settings.php. By default, this tool searches the parent directories for a standard CMS (Drupal, WordPress, etal) and standard civicrm.settings.php. Symlinks and multisite configurations may interfere. To customize, set variable CIVICRM_SETTINGS to point to the preferred civicrm.settings.php.</p>
  </blockquote>
  
Tags: <drupal><api><extension><developer><civix>
Title: Civix reports "Failed to locate civicrm.settings.php"
ThreadText: # Civix reports "Failed to locate civicrm.settings.php"
  
  (Asked by: username_0 on 2016-07-01)
  
  I used the command `civix generate:api Civicrmzapier submit` to an API function to an extension i am working on, but got the following error as on the screenshot and the api function is not added.
  
  [![Civix Error unable to find civicrm.settings.php file](https://i.sstatic.net/EFT99.png)](https://i.sstatic.net/EFT99.png)
  
  > Failed to locate civicrm.settings.php. By default, this tool searches the parent directories for a standard CMS (Drupal, WordPress, etal) and standard civicrm.settings.php. Symlinks and multisite configurations may interfere. To customize, set variable CIVICRM\_SETTINGS to point to the preferred civicrm.settings.php.
  
  **Tags:** drupal, api, extension, developer, civix
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-07-02. Score: 6 | Accepted answer
  
  The `generate:api` subcommand (and a few others) require access to a working copy of CiviCRM.
  
  To locate this, it uses a process reminiscent of `drush` or `wp-cli`. For example, if the command-line is running inside `/var/www/sites/default/files/civicrm/ext/org.example.foo/`, then it will perform an upward search to find the CMS root:
  
  ```
  /var/www/sites/default/files/civicrm/ext/org.example.foo
  /var/www/sites/default/files/civicrm/ext
  /var/www/sites/default/files/civicrm
  /var/www/sites/default/files
  /var/www/sites/default
  /var/www/sites
  /var/www
  /var
  
  ```
  
  In each case, it is looking for a tell-tale sign of a CMS+Civi system. For example, in a typical Drupal installation, you'd expect to see the file `sites/default/civicrm.settings.php`.
  
  There are some cases where the default search may not work correctly, e.g.
  
  * Using a new or custom CMS.
  * Using a multisite configuration.
  * Using symlinks.
  
  The quickest way to resolve this? Don't rely on a search. Instead, tell `civix` specifically where to find your copy of CiviCRM by setting the variable `CIVICRM_SETTINGS`, e.g.
  
  ```
  export CIVICRM_SETTINGS=/var/www/sites/default/civicrm.settings.php
  civix generate:api ...
  
  ```
  
  More aggressive ways to resolve this would be:
  
  * Arrange your directory structure so that it looks like a normal build (e.g. replace symlinks with real folders).
  * Use [`civibuild`](https://github.com/civicrm/civicrm-buildkit/) for your dev sites. It always produces standard builds.
  * Submit a patch for [`Civi/Cv/Bootstrap`](https://github.com/civicrm/cv/blob/master/src/Bootstrap.php) to add support for your directory structure.
  
  > **Comments:**
  > **username_3**: Note sure if this answer is still true today? https://github.com/civicrm/cv/issues/130  
  
  ---
  
  ### Answer by username_1 on 2016-07-02. Score: 0
  
  Note that civix does not generate/add anything because it can not find your civicrm.settings.php - that's a configuration issue
  
  Can you e.g.
  
  ```
  civix generate:api -h
  
  ```
  
  Note the option that you can set an environment variable CIVICRM\_SETTINGS pointing to where your civicrm.settings.php is - if needed.
  
  
  ---
  
  