1

I have a hard time updating the staging server. After performing Craft core and plugins updates locally on my Windows machine, I transferred the composer.json, composer.lock files, and also the migrate.yaml file and folders to the remote staging server. I have also added/updated the web/index.php + bootstrap.php files. composer install went through without errors.

Both frontend and backend stopped working. I get server errors 503.

What also stopped working, is the craft PHP script. When I call it as usual via SSH, I get the following response in the terminal:

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Dotenv\Dotenv::create() must be an instance of Dotenv\Repository\RepositoryInterface, string given, called in /home/foo/www/lorem/ipsum/backend/craft on line 16 and defined in /home/foo/www/lorem/ipsum/backend/vendor/vlucas/phpdotenv/src/Dotenv.php:83
Stack trace:
#0 /home/foo/www/lorem/ipsum/backend/craft(16): Dotenv\Dotenv::create('/home/foo/...')
#1 {main}
  thrown in /home/foo/www/lorem/ipsum/backend/vendor/vlucas/phpdotenv/src/Dotenv.php on line 83

Googling that error in combination with Craft CMS don't reveal many results. Some hint at version mismatch, but it's not clear which version is supposed to work. It's also confusing that it works on my local machine with the same PHP version, but not anymore on the remote server. I think I've tried most recommended fixes I could find.

Some more information (from composer.json):

"aelvan/imager": "^2.3",
"born05/craft-enforcepassword": "1.0.4.2",
"clubstudioltd/craft-asset-rev": "^6.0",
"codemonauts/craft-readonly-field": "1.0.2",
"craftcms/cms": "3.7.43",
"craftcms/redactor": "2.10.8",
"davist11/craft-reroute": "^2.0",
"doublesecretagency/craft-upvote": "2.2.2",
"mattgrayisok/craft-recently-viewed": "1.0.3",
"mildlygeeky/craft-kint": "^1.0",
"nesbot/carbon": "^2.32",
"pierrestoffe/craft-language-redirector": "2.0.0",
"sebastianlenz/linkfield": "1.0.25",
"solspace/craft-freeform": "3.13.10",
"studioespresso/craft-scout": "2.7.2",
"supercool/tablemaker": "2.0.1",
"thejoshsmith/craft-fab-permissions": "2.0.2",
"twentyfourhoursmedia/views-work": "1.3.0.7",
"verbb/super-table": "2.7.2",
"verbb/workflow": "1.7.3",
"vlucas/phpdotenv": "^5.4.0"

Does anyone have an idea what's going wrong here?

1 Answer 1

2

Sounds like the way you are loading Dotenv in your index.php may be out of sync with the version of Dotenv being used, through various versions the way you initalise Dotenv has changed.

Have a look at the Craft CMS starter repo and compare the web/index.php file to see if the Dotenv part matches what your Craft site has.

For 5.4.x it should look something like this:

<?php

// Define path constants
define('CRAFT_BASE_PATH', __DIR__);
define('CRAFT_VENDOR_PATH', CRAFT_BASE_PATH . '/vendor');

// Load Composer's autoloader
require_once CRAFT_VENDOR_PATH . '/autoload.php';

// Load dotenv?
if (class_exists('Dotenv\Dotenv')) {
    // By default, this will allow .env file values to override environment variables
    // with matching names. Use `createUnsafeImmutable` to disable this.
    Dotenv\Dotenv::createUnsafeMutable(CRAFT_BASE_PATH)->safeLoad();
}

// Define additional PHP constants
// (see https://craftcms.com/docs/3.x/config/#php-constants)
define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');

// Load and run Craft
/** @var craft\web\Application $app */
$app = require CRAFT_VENDOR_PATH . '/craftcms/cms/bootstrap/web.php';
$app->run();

Adjust any variables/paths required to your specific site.

Alternatively, downgrade your Dotenv version to this:

"vlucas/phpdotenv": "^3.4.0"

If you do update your index.php to be compatible, you can implement the bootstrap include method that is shared across both web and console for less code duplication and will match the Craft CMS starter template.

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.