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

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.

2 Answers 2


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:


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 for your dev sites. It always produces standard builds.
  • Submit a patch for Civi/Cv/Bootstrap to add support for your directory structure.

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.

Your Answer

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

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