Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jonnybarnes's avatar

I’m getting a DotEnv related error from Travis-CI

Here’s the full error message

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Dotenv: Environment file .env not found or not readable. Create file with your environment settings at /home/travis/build/jonnybarnes/push-lumen/bootstrap/../.env' in /home/travis/build/jonnybarnes/push-lumen/vendor/vlucas/phpdotenv/src/Dotenv.php on line 33

Is there anyway around this issue?

0 likes
2 replies
mikebronner's avatar

Your tests are probably relying on env variables. So, to get around this, you need to set the environment variables for the given project in the Travis UI: https://travis-ci.org/organization/project/settings/env_vars (replace organization and project)

If you are then still getting the error, it seems you might be explicitly looking for the .env file in your tests, instead of letting Laravel load them automatically?

jonnybarnes's avatar

I think I added the right env variables, but I'm still getting the errors. Here's the full stack if its helpful

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Dotenv: Environment file .env not found or not readable. Create file with your environment settings at /home/travis/build/jonnybarnes/push-lumen/bootstrap/../.env' in /home/travis/build/jonnybarnes/push-lumen/vendor/vlucas/phpdotenv/src/Dotenv.php on line 33

InvalidArgumentException: Dotenv: Environment file .env not found or not readable. Create file with your environment settings at /home/travis/build/jonnybarnes/push-lumen/bootstrap/../.env in /home/travis/build/jonnybarnes/push-lumen/vendor/vlucas/phpdotenv/src/Dotenv.php on line 33

Call Stack:

    0.0003     240584   1. {main}() /home/travis/build/jonnybarnes/push-lumen/vendor/phpunit/phpunit/phpunit:0
    0.0146    1295800   2. PHPUnit_TextUI_Command::main() /home/travis/build/jonnybarnes/push-lumen/vendor/phpunit/phpunit/phpunit:36
    0.0146    1302808   3. PHPUnit_TextUI_Command->run() /home/travis/build/jonnybarnes/push-lumen/vendor/phpunit/phpunit/src/TextUI/Command.php:103
    0.0146    1305488   4. PHPUnit_TextUI_Command->handleArguments() /home/travis/build/jonnybarnes/push-lumen/vendor/phpunit/phpunit/src/TextUI/Command.php:113
    0.0255    1932360   5. PHPUnit_TextUI_Command->handleBootstrap() /home/travis/build/jonnybarnes/push-lumen/vendor/phpunit/phpunit/src/TextUI/Command.php:576
    0.0257    1941896   6. PHPUnit_Util_Fileloader::checkAndLoad() /home/travis/build/jonnybarnes/push-lumen/vendor/phpunit/phpunit/src/TextUI/Command.php:751
    0.0257    1942080   7. PHPUnit_Util_Fileloader::load() /home/travis/build/jonnybarnes/push-lumen/vendor/phpunit/phpunit/src/Util/Fileloader.php:40
    0.0258    1950472   8. include_once('/home/travis/build/jonnybarnes/push-lumen/bootstrap/app.php') /home/travis/build/jonnybarnes/push-lumen/vendor/phpunit/phpunit/src/Util/Fileloader.php:56
    0.0265    2001256   9. Dotenv::load() /home/travis/build/jonnybarnes/push-lumen/bootstrap/app.php:5

The command "vendor/bin/phpunit --verbose --coverage-text" exited with 255.

It appears to have not even gotten to running any tests. Does the Dotenv::load(__DIR__.'/../'); command in bootstrap/app.php perhaps need to be conditional on if we are in the testing environment or not?

Please or to participate in this conversation.