Answers.Body: <p>If you upgrade to a new major version of <code>vlucas/phpdotenv</code> you also need to ensure that any code that uses it is updated to be compatible as well.</p>
  <p>In the case of Craft, that means:</p>
  <ul>
  <li><code>web/index.php</code> - the Craft web app</li>
  <li><code>craft</code> - the Craft CLI app</li>
  </ul>
  <p>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.</p>
  <p>The easiest way to do that is just look at the corresponding files in the <code>craftcms/craft</code> starter project:</p>
  <ul>
  <li><code>web/index.php</code> - <a href="https://github.com/craftcms/craft/blob/main/web/index.php" rel="nofollow noreferrer">https://github.com/craftcms/craft/blob/main/web/index.php</a></li>
  <li><code>craft</code> - <a href="https://github.com/craftcms/craft/blob/main/craft" rel="nofollow noreferrer">https://github.com/craftcms/craft/blob/main/craft</a></li>
  </ul>
  <p>You can just copy &amp; paste them, assuming you didn't make any changes to either that need to be carried over.</p>
  <p>There's one additional step, because P&amp;T chose to refactor some common code from both out to a <code>bootstrap.php</code> file, so you'll need to create this file in the project root too, and add it to your git repository:</p>
  <ul>
  <li><code>bootstrap.php</code> - <a href="https://github.com/craftcms/craft/blob/main/bootstrap.php" rel="nofollow noreferrer">https://github.com/craftcms/craft/blob/main/bootstrap.php</a></li>
  </ul>
  <p>It's in this last file that you'll see it actually using <code>vlucas/phpdotenv</code></p>
  <p>This is documented in the <strong>Entry Script</strong> section of the Craft CMS documentation here: <a href="https://craftcms.com/docs/4.x/upgrade.html#entry-script" rel="nofollow noreferrer">https://craftcms.com/docs/4.x/upgrade.html#entry-script</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-01-25T16:26:05.520Z
Answers.Text: 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
Answers.UserDisplayName: Caroline Blaker
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-01-25T19:05:20.177Z
Answers.Text: 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: https://github.com/craftcms/craft/tree/1.1.7
Answers.UserDisplayName: andrew.welch
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-01-25T03:39:37.690Z
Answers.LastActivityDate: 2024-01-25T03:39:37.690Z
Answers.UserDisplayName: andrew.welch
Body: <p>Updating my Craft CMS website to Craft 3.8 on PHP 8.1 yielded the first of its kind: the <em>fatal deprecation error</em> that would not allow the migration to continue. Turns out, PHPdotEnv v 2.8 is too old:</p>
  <pre><code>
  Response: &lt;br /&gt;
  &lt;b&gt;Deprecated&lt;/b&gt;: auto_detect_line_endings is deprecated in &lt;b&gt;/var/www/html/vendor/vlucas/phpdotenv/src/Loader.php&lt;/b&gt; on line &lt;b&gt;172&lt;/b&gt;&lt;br /&gt;
  {&quot;nextAction&quot;:&quot;migrate&quot;,&quot;status&quot;:&quot;Updating database…&quot;,&quot;data&quot;:&quot;be949987ebeecde262b9c6aba5c52e4c481d6fbc099cc40f7581df02266a74ef{\&quot;migrate\&quot;:[\&quot;craft\&quot;],\&quot;returnUrl\&quot;:\&quot;\&quot;,\&quot;postPrecheckState\&quot;:{\&quot;nextAction\&quot;:\&quot;migrate\&quot;,\&quot;status\&quot;:\&quot;Updating database…\&quot;}}&quot;}
  </code></pre>
  <p>Looking up the new version yielded <code>5.6</code>, so I <code>composer install</code>d that but I still get an error:</p>
  <pre><code>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-&gt;__construct('/var/www/html') #1 {main} thrown in /var/www/html/vendor/vlucas/phpdotenv/src/Dotenv.php on line 60
  </code></pre>
  <p>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 <code>4.2</code> and there was some other error just as arcane.</p>
  <p>Here's my composer.json</p>
  <pre><code>  &quot;require&quot;: {
      &quot;aelvan/imager&quot;: &quot;v2.4.0&quot;,
      &quot;craftcms/cms&quot;: &quot;3.8.12&quot;,
      &quot;craftcms/contact-form&quot;: &quot;2.2.7&quot;,
      &quot;craftcms/feed-me&quot;: &quot;4.3.6&quot;,
      &quot;craftcms/redactor&quot;: &quot;2.8.7&quot;,
      &quot;craftcms/store-hours&quot;: &quot;2.1.1.1&quot;,
      &quot;doublesecretagency/craft-cpcss&quot;: &quot;2.3.0&quot;,
      &quot;doublesecretagency/craft-smartmap&quot;: &quot;3.3.5&quot;,
      &quot;doublesecretagency/craft-viewcount&quot;: &quot;1.0.5&quot;,
      &quot;ether/simplemap&quot;: &quot;3.9.4&quot;,
      &quot;ether/tags&quot;: &quot;1.0.7&quot;,
      &quot;intoeetive/protectedlinks&quot;: &quot;0.0.4&quot;,
      &quot;kinoli/groupie&quot;: &quot;1.0.8&quot;,
      &quot;mmikkel/cp-field-inspect&quot;: &quot;1.2.5&quot;,
      &quot;mmikkel/incognito-field&quot;: &quot;1.2.0&quot;,
      &quot;nystudio107/craft-seomatic&quot;: &quot;3.3.46&quot;,
      &quot;putyourlightson/craft-sprig&quot;: &quot;1.7.0&quot;,
      &quot;robuust/craft-reverserelations&quot;: &quot;1.1.7&quot;,
      &quot;sebastianlenz/linkfield&quot;: &quot;1.0.25&quot;,
      &quot;stripe/stripe-php&quot;: &quot;^7.69&quot;,
      &quot;superbig/craft3-mobiledetect&quot;: &quot;^1.0&quot;,
      &quot;tinydots/craft-cpeditsegment&quot;: &quot;1.0.0&quot;,
      &quot;verbb/super-table&quot;: &quot;2.6.8&quot;,
      &quot;vlucas/phpdotenv&quot;: &quot;^5.6&quot;,
      &quot;wrav/oembed&quot;: &quot;1.3.11&quot;,
      &quot;yiisoft/yii2-redis&quot;: &quot;^2.0&quot;
    },
    &quot;minimum-stability&quot;: &quot;dev&quot;,
    &quot;prefer-stable&quot;: true,
    
    &quot;autoload&quot;: {
      &quot;psr-4&quot;: {
        &quot;modules\\&quot;: &quot;modules/&quot;
      }
    },
    &quot;config&quot;: {
      &quot;sort-packages&quot;: true,
      &quot;optimize-autoloader&quot;: true,
      &quot;platform&quot;: {
        &quot;php&quot;: &quot;7.4&quot;
      },
      &quot;allow-plugins&quot;: {
        &quot;yiisoft/yii2-composer&quot;: true,
        &quot;craftcms/plugin-installer&quot;: true
      }
    },
    &quot;scripts&quot;: {
      &quot;post-root-package-install&quot;: [
        &quot;@php -r \&quot;file_exists('.env') || copy('.env.example', '.env');\&quot;&quot;
      ]
    }
  }
  </code></pre>
  <p>Other things to know about the site is that I just turned off Redis and it connects to PostgreSQL 14. Thanks in advance -</p>
  
Tags: <php><composer>
Title: PHPdotEnv upgrade not working
ThreadText: # PHPdotEnv upgrade not working
  
  (Asked by: username_0 on 2024-01-24)
  
  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 install`d 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 -
  
  **Tags:** php, composer
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-01-25. Score: 3 | Accepted answer
  
  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:
  
  * `web/index.php` - <https://github.com/craftcms/craft/blob/main/web/index.php>
  * `craft` - <https://github.com/craftcms/craft/blob/main/craft>
  
  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:
  
  * `bootstrap.php` - <https://github.com/craftcms/craft/blob/main/bootstrap.php>
  
  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>
  
  > **Comments:**
  > **username_0**: 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  
  > **username_1**: 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: https://github.com/craftcms/craft/tree/1.1.7  
  
  ---
  
  