Answers.Body: <p>For vlucas/phpdotenv for 3.4.0, this index.php template should work:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  /**
   * Craft web bootstrap file
   */
  
  // Set path constants
  define('CRAFT_BASE_PATH', dirname(__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') &amp;&amp; file_exists(CRAFT_BASE_PATH.'/.env')) {
      Dotenv\Dotenv::create(CRAFT_BASE_PATH)-&gt;load();
  }
  
  // Load and run Craft
  define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
  $app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php';
  $app-&gt;run();
  </code></pre>
  <p>For console:</p>
  <pre class="lang-php prettyprint-override"><code>#!/usr/bin/env php
  &lt;?php
  /**
   * Craft console bootstrap file
   */
  
  // Set 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') &amp;&amp; file_exists(CRAFT_BASE_PATH.'/.env')) {
      Dotenv\Dotenv::create(CRAFT_BASE_PATH)-&gt;load();
  }
  
  // Load and run Craft
  define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
  $app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/console.php';
  $exitCode = $app-&gt;run();
  exit($exitCode);
  </code></pre>
  <p>It is the <code>Dotenv\Dotenv::create(CRAFT_BASE_PATH)-&gt;load();</code> line that allows it to work. Repeat for your craft console file.</p>
  <p>You can use the 5.x.x version of vlucas/phpdotenv, but it does require changes to how it is loaded compared to 3.4.x</p>
  <p>The Craft CMS starter project provides a 5.x.x example, however this is using a bootstrap include method across both web and console, so you'd have to refactor slightly, but worth it as you don't have to duplicate the same logic in the your console file anymore.</p>
  <p><a href="https://github.com/craftcms/craft/blob/main/bootstrap.php" rel="nofollow noreferrer">https://github.com/craftcms/craft/blob/main/bootstrap.php</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-27T19:34:03.063Z
Answers.Text: There's a separate console file???
Answers.UserDisplayName: joomkit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-27T21:03:50.093Z
Answers.Text: Dotenv is loaded on both the web/index.php and craft file at the root, so you'll need to update both to the necessary Dotenv loading syntax relative to the version in use. If you look at the Craft starter project, they use a bootstrap include file across both so you don't have to duplicate it.
  
  https://github.com/craftcms/craft
Answers.UserDisplayName: James White
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-29T14:39:53.963Z
Answers.Text: Thanks James. I still don't get what the issue is. I have upgraded another site on local dev with no issues - they have the same craft  and phpdotenv versions in their respective composer.json. Both load frontend fine. But one will not run craft commands on command line. Last ditch attempt i swapped the craft shell file from the working to the broken - hey presto. I realised thats what you call the console file? #still-learning thx
Answers.UserDisplayName: joomkit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-29T21:40:48.940Z
Answers.Text: Yes the craft file at the root is the PHP wrapper file for calling Craft console commands with ./craft. This was likely using the wrong dotenv syntax for loading based on the version.
Answers.UserDisplayName: James White
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-30T12:35:43.690Z
Answers.Text: Yes that was it
Answers.UserDisplayName: joomkit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-06-08T23:33:01.073Z
Answers.Text: Note: I just updated from Craft 3.7 to 4.x, and I found it easiest to leave phpdotenv version as 2.4.0, no changes to other files were required.
Answers.UserDisplayName: 4midori
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-27T18:02:08.930Z
Answers.LastActivityDate: 2022-07-01T07:02:36.010Z
Answers.LastEditDate: 2022-07-01T07:02:36.010Z
Answers.UserDisplayName: James White
Body: <p>Ran upgrade on my local dev environment.
  Seemed to go fine.
  Front end site broke and command line updates for craft also error.</p>
  <p>My index.php looks like</p>
  <pre><code>// Set path constants
  define('CRAFT_BASE_PATH', dirname(__DIR__));
  define('CRAFT_VENDOR_PATH', CRAFT_BASE_PATH.'/vendor');
  
  // Load Composer's autoloader
  require_once CRAFT_VENDOR_PATH.'/autoload.php';
  
  // Load dotenv?
  if (file_exists(CRAFT_BASE_PATH.'/.env')) {
      (new Dotenv\Dotenv(CRAFT_BASE_PATH))-&gt;load();
  }
  
  // Load and run Craft
  define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
  $app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php';
  $app-&gt;run();
  </code></pre>
  <p>CLI craft update gives me:</p>
  <pre><code> Uncaught TypeError: Argument 1 passed to Dotenv\Dotenv::__construct() 
  ...vendor/vlucas/phpdotenv/src/Dotenv.php:60
  </code></pre>
  <p>I tried downgrading vulcas DotEnv package with no luck.
  I then set craft requirement in compose to 3.4.0 but still getting issues loading and updating on CLI, all centered around the Dotenv package.</p>
  <p>I did a vanilla install via CLI to check index.php content which are different - AND i noticed composer.json states craft requires php8! Not what the docs say but thats another post.</p>
  <p>Any help appreciated</p>
  
Tags: <upgrades><cli>
Title: Broken site after upgrade via composer from craft 3.37.38
ThreadText: # Broken site after upgrade via composer from craft 3.37.38
  
  (Asked by: username_0 on 2022-06-27)
  
  Ran upgrade on my local dev environment.
  Seemed to go fine.
  Front end site broke and command line updates for craft also error.
  
  My index.php looks like
  
  ```
  // Set path constants
  define('CRAFT_BASE_PATH', dirname(__DIR__));
  define('CRAFT_VENDOR_PATH', CRAFT_BASE_PATH.'/vendor');
  
  // Load Composer's autoloader
  require_once CRAFT_VENDOR_PATH.'/autoload.php';
  
  // Load dotenv?
  if (file_exists(CRAFT_BASE_PATH.'/.env')) {
      (new Dotenv\Dotenv(CRAFT_BASE_PATH))->load();
  }
  
  // Load and run Craft
  define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
  $app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php';
  $app->run();
  
  ```
  
  CLI craft update gives me:
  
  ```
   Uncaught TypeError: Argument 1 passed to Dotenv\Dotenv::__construct() 
  ...vendor/vlucas/phpdotenv/src/Dotenv.php:60
  
  ```
  
  I tried downgrading vulcas DotEnv package with no luck.
  I then set craft requirement in compose to 3.4.0 but still getting issues loading and updating on CLI, all centered around the Dotenv package.
  
  I did a vanilla install via CLI to check index.php content which are different - AND i noticed composer.json states craft requires php8! Not what the docs say but thats another post.
  
  Any help appreciated
  
  **Tags:** upgrades, cli
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-06-27. Score: 4 | Accepted answer
  
  For vlucas/phpdotenv for 3.4.0, this index.php template should work:
  
  ```php
  <?php
  /**
   * Craft web bootstrap file
   */
  
  // Set path constants
  define('CRAFT_BASE_PATH', dirname(__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') && file_exists(CRAFT_BASE_PATH.'/.env')) {
      Dotenv\Dotenv::create(CRAFT_BASE_PATH)->load();
  }
  
  // Load and run Craft
  define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
  $app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/web.php';
  $app->run();
  
  ```
  
  For console:
  
  ```php
  #!/usr/bin/env php
  <?php
  /**
   * Craft console bootstrap file
   */
  
  // Set 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') && file_exists(CRAFT_BASE_PATH.'/.env')) {
      Dotenv\Dotenv::create(CRAFT_BASE_PATH)->load();
  }
  
  // Load and run Craft
  define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
  $app = require CRAFT_VENDOR_PATH.'/craftcms/cms/bootstrap/console.php';
  $exitCode = $app->run();
  exit($exitCode);
  
  ```
  
  It is the `Dotenv\Dotenv::create(CRAFT_BASE_PATH)->load();` line that allows it to work. Repeat for your craft console file.
  
  You can use the 5.x.x version of vlucas/phpdotenv, but it does require changes to how it is loaded compared to 3.4.x
  
  The Craft CMS starter project provides a 5.x.x example, however this is using a bootstrap include method across both web and console, so you'd have to refactor slightly, but worth it as you don't have to duplicate the same logic in the your console file anymore.
  
  <https://github.com/craftcms/craft/blob/main/bootstrap.php>
  
  > **Comments:**
  > **username_0**: There's a separate console file???  
  > **username_1**: Dotenv is loaded on both the web/index.php and craft file at the root, so you'll need to update both to the necessary Dotenv loading syntax relative to the version in use. If you look at the Craft starter project, they use a bootstrap include file across both so you don't have to duplicate it.  https://github.com/craftcms/craft  
  > **username_0**: Thanks username_1. I still don't get what the issue is. I have upgraded another site on local dev with no issues - they have the same craft  and phpdotenv versions in their respective composer.json. Both load frontend fine. But one will not run craft commands on command line. Last ditch attempt i swapped the craft shell file from the working to the broken - hey presto. I realised thats what you call the console file? #still-learning thx  
  > **username_1**: Yes the craft file at the root is the PHP wrapper file for calling Craft console commands with ./craft. This was likely using the wrong dotenv syntax for loading based on the version.  
  > **username_0**: Yes that was it  
  > **username_2**: Note: I just updated from Craft 3.7 to 4.x, and I found it easiest to leave phpdotenv version as 2.4.0, no changes to other files were required.  
  
  ---
  
  