1

Updating my Craft CMS website to Craft 3.8 on PHP 8.1 yielded the first of its kind: the fatal deprecation error that would not allow the migration to continue. Turns out, PHPdotEnv v 2.8 is too old:


Response: <br />
<b>Deprecated</b>: auto_detect_line_endings is deprecated in <b>/var/www/html/vendor/vlucas/phpdotenv/src/Loader.php</b> on line <b>172</b><br />
{"nextAction":"migrate","status":"Updating database…","data":"be949987ebeecde262b9c6aba5c52e4c481d6fbc099cc40f7581df02266a74ef{\"migrate\":[\"craft\"],\"returnUrl\":\"\",\"postPrecheckState\":{\"nextAction\":\"migrate\",\"status\":\"Updating database…\"}}"}

Looking up the new version yielded 5.6, so I composer installd that but I still get an error:

Fatal error: Uncaught TypeError: Dotenv\Dotenv::__construct(): Argument #1 ($store) must be of type Dotenv\Store\StoreInterface, string given, called in /var/www/html/public/index.php on line 15 and defined in /var/www/html/vendor/vlucas/phpdotenv/src/Dotenv.php:60 Stack trace: #0 /var/www/html/public/index.php(15): Dotenv\Dotenv->__construct('/var/www/html') #1 {main} thrown in /var/www/html/vendor/vlucas/phpdotenv/src/Dotenv.php on line 60

I'm not really sure what to make of this. Does Craft CMS support higher versions of phpdotenv? Is some kind of work-around required? I tried version 4.2 and there was some other error just as arcane.

Here's my composer.json

  "require": {
    "aelvan/imager": "v2.4.0",
    "craftcms/cms": "3.8.12",
    "craftcms/contact-form": "2.2.7",
    "craftcms/feed-me": "4.3.6",
    "craftcms/redactor": "2.8.7",
    "craftcms/store-hours": "2.1.1.1",
    "doublesecretagency/craft-cpcss": "2.3.0",
    "doublesecretagency/craft-smartmap": "3.3.5",
    "doublesecretagency/craft-viewcount": "1.0.5",
    "ether/simplemap": "3.9.4",
    "ether/tags": "1.0.7",
    "intoeetive/protectedlinks": "0.0.4",
    "kinoli/groupie": "1.0.8",
    "mmikkel/cp-field-inspect": "1.2.5",
    "mmikkel/incognito-field": "1.2.0",
    "nystudio107/craft-seomatic": "3.3.46",
    "putyourlightson/craft-sprig": "1.7.0",
    "robuust/craft-reverserelations": "1.1.7",
    "sebastianlenz/linkfield": "1.0.25",
    "stripe/stripe-php": "^7.69",
    "superbig/craft3-mobiledetect": "^1.0",
    "tinydots/craft-cpeditsegment": "1.0.0",
    "verbb/super-table": "2.6.8",
    "vlucas/phpdotenv": "^5.6",
    "wrav/oembed": "1.3.11",
    "yiisoft/yii2-redis": "^2.0"
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  
  "autoload": {
    "psr-4": {
      "modules\\": "modules/"
    }
  },
  "config": {
    "sort-packages": true,
    "optimize-autoloader": true,
    "platform": {
      "php": "7.4"
    },
    "allow-plugins": {
      "yiisoft/yii2-composer": true,
      "craftcms/plugin-installer": true
    }
  },
  "scripts": {
    "post-root-package-install": [
      "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ]
  }
}

Other things to know about the site is that I just turned off Redis and it connects to PostgreSQL 14. Thanks in advance -

1 Answer 1

3

If you upgrade to a new major version of vlucas/phpdotenv you also need to ensure that any code that uses it is updated to be compatible as well.

In the case of Craft, that means:

  • web/index.php - the Craft web app
  • craft - the Craft CLI app

Neither of these are auto-updated in any way, because they aren't Composer packages, and people can make modifications to either, so you need to do it manually.

The easiest way to do that is just look at the corresponding files in the craftcms/craft starter project:

You can just copy & paste them, assuming you didn't make any changes to either that need to be carried over.

There's one additional step, because P&T chose to refactor some common code from both out to a bootstrap.php file, so you'll need to create this file in the project root too, and add it to your git repository:

It's in this last file that you'll see it actually using vlucas/phpdotenv

This is documented in the Entry Script section of the Craft CMS documentation here: https://craftcms.com/docs/4.x/upgrade.html#entry-script

2
  • Andrew - thank you. I feel like I need 2 points of clarification. 1) Any particular target version for late Craft 3? 2) Looking at these files and copy-pasting them - I feel like these actions might vary for Craft 3? I'm also interested in the Craft 4 version of events because I'll be upgrading this ASAP. Last point - can you help me conceptialize why any kind of work-around is needed and when I won't need it anymore? Brand new to this. thx Commented Jan 25 at 16:26
  • Just copy the same files from the latest 1.x-tagged version of that same repo, which will have the appropriate files for Craft 3: github.com/craftcms/craft/tree/1.1.7 Commented Jan 25 at 19:05

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.