Skip to content
Latchkey

PHP Warning: require(): Failed Opening Required File in CI

When require/include cannot find the target file, PHP emits a "failed to open stream" warning and require then halts with a fatal error. In CI this usually means a relative path resolves differently, the file is not present, or the checkout layout differs from local.

What this error means

CI shows "Warning: require(bootstrap.php): Failed to open stream: No such file or directory" followed by "Fatal error: Failed opening required". The same require works locally where the working directory or include_path differs.

php
PHP Warning:  require(/app/vendor/autoload.php): Failed to open stream:
No such file or directory in /app/bin/run.php on line 3
PHP Fatal error:  Uncaught Error: Failed opening required
'/app/vendor/autoload.php' (include_path='.:/usr/share/php')

Common causes

The path is relative to the wrong directory

A bare require 'config.php' resolves against the current working directory, which in CI may differ from where you run locally. The file is not where the path points.

The required file was never created in CI

Requiring vendor/autoload.php before composer install, or a generated file before its build step, fails because the file does not exist yet.

How to fix it

Use __DIR__-relative paths

Anchor requires to the file location so they do not depend on the working directory.

php
require __DIR__ . '/../vendor/autoload.php';

Ensure the file exists before requiring it

  1. For vendor/autoload.php, run composer install before any script that requires it.
  2. For generated files, run the generating step earlier in the CI job.
  3. Check the file is committed (or produced) and not gitignored away in CI.
composer
composer install --no-interaction
php bin/run.php

Confirm include_path if you rely on it

If a require depends on include_path, print it to see what the runner actually uses.

php
php -r "echo get_include_path(), PHP_EOL;"

How to prevent it

  • Always require with __DIR__-relative or absolute paths.
  • Run composer install before any script that requires the autoloader.
  • Do not depend on the CI working directory matching your local shell.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →