rest.php crashes with 'Failed to open' ... civicrm.config.php under Drupal 9
Overview
Having solved issue The REST link produced by API v3 Explorer gives 'page not found' under Drupal 9, running the link gives Warning: require_once(../civicrm.config.php): failed to open stream: No such file or directory in /vendor/civicrm/civicrm-core/extern/rest.php on line 12
Fatal error: require_once(): Failed opening required '../civicrm.config.php' (include_path='...) in ...
Reproduction steps
- Run a REST query from a browser as generated by API Explorer v3 with the FIXMEs fixed.
Current behaviour
See the above.
Expected behaviour
A JSON list of contacts should appear.
Environment information
- Browser: MS Edge but probably irrelevant
- CiviCRM: 5.38.1alpha/5.37.2
- PHP: 7.4 but probably irrelevant
- CMS: Drupal 9.1.8
- Database: MySQL 8.0.25. but probably irrelevant.
- Web Server: IIS but probably irrelevant.
Comments
I know that the REST approach is being deprecated, but we do not seem to have replacement.
- I could not find civicrm.config.php in the CiviCRM distribution; I suspect it may be obsolete.
- Replacing line 12 with
require_once filter_input(INPUT_SERVER, 'APPL_PHYSICAL_PATH') . 'sites/default/civicrm.settings.php';
cured the problem. Someone with more CiviCRM expertise than I may be able to suggest a better solution.