Answers.Body: <p>Sorted. The problem was that the script was being run by the web server cron, rather than civi cron. As such the working directory was my home directory. Hacky fix is:</p>
  
  <pre><code>chdir(__DIR__);
  eval(`cv php:boot`);
  </code></pre>
  
  <p>Better fix is to make it run via Civi cron.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-12-16T13:16:15.873Z
Answers.LastActivityDate: 2016-12-16T13:16:15.873Z
Answers.UserDisplayName: Andrew West
Body: <p>We have an old script in the bin folder that bootstraps Civi like so:</p>
  
  <pre><code>require_once '[whatever]/wp-content/plugins/civicrm/civicrm/civicrm.config.php';
  require_once 'CRM/Core/Config.php';
  </code></pre>
  
  <p>But as of 4.7 this no longer works. We get:</p>
  
  <pre><code>PHP Fatal error:  Uncaught exception 'Exception' with message 'Failed to locate civicrm.settings.php. Please boot with settingsFile, search, or CIVICRM_SETTINGS; or normalize your directory structure.' in /var/www/vhosts/humanism.org.uk/wp-content/plugins/civicrm/civicrm/civicrm.config.php:125
  </code></pre>
  
  <p>I've tried hardcoding the link as recommended <a href="https://civicrm.stackexchange.com/questions/12207/failed-to-locate-civicrm-settings-php?noredirect=1&amp;lq=1">here</a>. This gets me a step further, but it then can't find the CMS root folder. And I'm not sure where to set that. I've also tried creating a settings_location.php file to no avail.</p>
  
  <p>I've tried to modernise it by using cv as per <a href="https://wiki.civicrm.org:8090/confluence/display/CRMDOC/Bootstrap+Reference" rel="nofollow noreferrer">the wiki</a>, but I get the same problem:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Civi runs fine otherwise - it's just external scripts that aren't happy.</p>
  
  <p>Any ideas? We're on WordPress, with a standard folder structure: Civi sits in /wp-content/plugins/civicrm.</p>
  
Tags: <wordpress><installation>
Title: Cannot bootstrap Civi from standalone script in WP
ThreadText: # Cannot bootstrap Civi from standalone script in WP
  
  (Asked by: username_0 on 2016-12-13)
  
  We have an old script in the bin folder that bootstraps Civi like so:
  require_once '[whatever]/wp-content/plugins/civicrm/civicrm/civicrm.config.php';
  require_once 'CRM/Core/Config.php';
  
  But as of 4.7 this no longer works. We get:
  PHP Fatal error:  Uncaught exception 'Exception' with message 'Failed to locate civicrm.settings.php. Please boot with settingsFile, search, or CIVICRM_SETTINGS; or normalize your directory structure.' in /var/www/vhosts/humanism.org.uk/wp-content/plugins/civicrm/civicrm/civicrm.config.php:125
  
  I've tried hardcoding the link as recommended here. This gets me a step further, but it then can't find the CMS root folder. And I'm not sure where to set that. I've also tried creating a settings_location.php file to no avail.
  I've tried to modernise it by using cv as per the wiki, but I get the same problem:
  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
  
  Civi runs fine otherwise - it's just external scripts that aren't happy.
  Any ideas? We're on WordPress, with a standard folder structure: Civi sits in /wp-content/plugins/civicrm.
  
  **Tags:** wordpress, installation
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-12-16. Score: 1 | Accepted answer
  
  Sorted. The problem was that the script was being run by the web server cron, rather than civi cron. As such the working directory was my home directory. Hacky fix is:
  chdir(__DIR__);
  eval(`cv php:boot`);
  
  Better fix is to make it run via Civi cron.
  
  
  ---
  
  