Answers.Body: <p>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.</p>
  <p>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.</p>
  <p>For 5.4.x it should look something like this:</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?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)-&gt;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-&gt;run();
  </code></pre>
  <p>Adjust any variables/paths required to your specific site.</p>
  <p>Alternatively, downgrade your Dotenv version to this:</p>
  <pre><code>&quot;vlucas/phpdotenv&quot;: &quot;^3.4.0&quot;
  </code></pre>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-06-02T07:02:52.190Z
Answers.LastActivityDate: 2022-06-02T07:02:52.190Z
Answers.UserDisplayName: James White
Body: <p>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.</p>
  <p>Both frontend and backend stopped working. I get server errors 503.</p>
  <p>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:</p>
  <pre><code>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
  </code></pre>
  <p>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.</p>
  <p>Some more information (from composer.json):</p>
  <pre><code>&quot;aelvan/imager&quot;: &quot;^2.3&quot;,
  &quot;born05/craft-enforcepassword&quot;: &quot;1.0.4.2&quot;,
  &quot;clubstudioltd/craft-asset-rev&quot;: &quot;^6.0&quot;,
  &quot;codemonauts/craft-readonly-field&quot;: &quot;1.0.2&quot;,
  &quot;craftcms/cms&quot;: &quot;3.7.43&quot;,
  &quot;craftcms/redactor&quot;: &quot;2.10.8&quot;,
  &quot;davist11/craft-reroute&quot;: &quot;^2.0&quot;,
  &quot;doublesecretagency/craft-upvote&quot;: &quot;2.2.2&quot;,
  &quot;mattgrayisok/craft-recently-viewed&quot;: &quot;1.0.3&quot;,
  &quot;mildlygeeky/craft-kint&quot;: &quot;^1.0&quot;,
  &quot;nesbot/carbon&quot;: &quot;^2.32&quot;,
  &quot;pierrestoffe/craft-language-redirector&quot;: &quot;2.0.0&quot;,
  &quot;sebastianlenz/linkfield&quot;: &quot;1.0.25&quot;,
  &quot;solspace/craft-freeform&quot;: &quot;3.13.10&quot;,
  &quot;studioespresso/craft-scout&quot;: &quot;2.7.2&quot;,
  &quot;supercool/tablemaker&quot;: &quot;2.0.1&quot;,
  &quot;thejoshsmith/craft-fab-permissions&quot;: &quot;2.0.2&quot;,
  &quot;twentyfourhoursmedia/views-work&quot;: &quot;1.3.0.7&quot;,
  &quot;verbb/super-table&quot;: &quot;2.7.2&quot;,
  &quot;verbb/workflow&quot;: &quot;1.7.3&quot;,
  &quot;vlucas/phpdotenv&quot;: &quot;^5.4.0&quot;
  </code></pre>
  <p>Does anyone have an idea what's going wrong here?</p>
  
Tags: <upgrades>
Title: After upgrading via composer and moving to another server, Craft stopped working. dotenv error
ThreadText: # After upgrading via composer and moving to another server, Craft stopped working. dotenv error
  
  (Asked by: username_0 on 2022-06-02)
  
  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?
  
  **Tags:** upgrades
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-06-02. Score: 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
  <?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.
  
  
  ---
  
  