<p>You can't create an new <code>yii\web\Request</code> instance in <em>general.php</em> because <a href="https://github.com/craftcms/cms/issues/6439#issuecomment-662923202" rel="nofollow noreferrer">Craft isn't fully initialized yet</a>. It worked in previous versions but the Craft team seem to have changed the loading order.</p>
<p>You must find another way to define you site base URL.</p>

CC BY-SA 4.0
2020-09-14T18:32:45.247Z
2020-09-14T18:32:45.247Z
nstCactus
<p>Did you try removing composer.lock file and the vendor directory and then doing a fresh composer install?</p>

CC BY-SA 4.0
2020-09-09T18:04:46.160Z
Yes, that was one of the first things I tried. It says it has installed everything correctly, but in the end Yii2 is still missing.
jishi
CC BY-SA 4.0
2020-09-09T18:50:16.360Z
What's weirder is that vendor/yiisoft/yii2 is actually there. Could it be something off with autoload? I'm not sure how that stuff works...
jishi
CC BY-SA 4.0
2020-09-10T07:04:43.900Z
I had similar issues when updating an older version of craft, I remember it was due to an incomaptible plugin. Could you try (temporarily) removing some of them and try running composer install again?
Matt Jenkins
CC BY-SA 4.0
2020-09-10T07:14:41.790Z
I have tried that as well, removing all plugins and only keeping craftcms, still the same issue. I even did a setup of a completely new project (which do work), then copy composer.json and composer.lock from that structure into my current install, but it still fails. I'm starting to wonder if there is something wrong with the bootstrap files, but index.php is identical and everything else seems to load from the vendor folder...
jishi
CC BY-SA 4.0
2020-09-10T09:46:05.917Z
Have you tried manually setting the craft version in composer.json, ditching the lock file, vendor dir and doing a composer install? So bypassing craft update altogether
Matt Jenkins
CC BY-SA 4.0
2020-09-10T10:11:49.037Z
I thought I did, but retried it again and I have managed to upgrade it to 3.3.18 so far... when I jump directly to 3.3.20 it still gets the same error. I'm stumped.
jishi
CC BY-SA 4.0
2020-09-10T10:14:46.793Z
I'm getting a similar problem at 3.3.19 now, as I had at 3.3.16 previously.
jishi
CC BY-SA 4.0
2020-09-09T16:36:59.563Z
2020-09-09T16:36:59.563Z
Matt Jenkins
<p>I'm trying to upgrade from 3.3.15 -&gt; 3.5.5 from control panel.</p>
<p>I run it via docker so all I need is to update the composer.lock file to have the correct dependencies and everything should be fine the next time I rebuild the image, but something strange is happening.</p>
<p>After selecting the upgrade, it runs for a few minutes and then just gets an internal server error. It logs the following:</p>
<pre><code>craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: &quot;NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Class 'Yii' not found in /app/vendor/yiisoft/yii2/validators/IpValidator.php:218&quot;
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: &quot;Stack trace:&quot;
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: &quot;#0 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): yii\validators\IpValidator-&gt;init()&quot;
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: &quot;#1 /app/vendor/yiisoft/yii2/web/Request.php(345): yii\base\BaseObject-&gt;__construct()&quot;
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: &quot;#2 /app/vendor/yiisoft/yii2/web/Request.php(1877): yii\web\Request-&gt;getIpValidator()&quot;
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: &quot;#3 /app/vendor/yiisoft/yii2/web/Request.php(1859): yii\web\Request-&gt;getSecureForwardedHeaderTrustedParts()&quot;
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: &quot;#4 /app/vendor/yiisoft/yii2/web/Request.php(1084): yii\web\Request-&gt;getSecureForwardedHeaderTrustedPart('proto')&quot;
craft_1        | 2020/08/21 07:38:50 [error] 139#139: *4 FastCGI sent in stderr: &quot;PHP message: PHP Fatal error:  Uncaught Error: Class 'Yii' not found in /app/vendor/yiisoft/yii2/validators/IpValidator.php:218
</code></pre>
<p>which is a bit odd, why would a dependency disappear when upgrading like this? After this attempted upgrade, the install is left in a broken state, giving 500 errors (and the same error, Yii not found) for all requests. Reverting the composer.json + composer.lock file and reinstalling dependencies restores functionality.</p>
<p>I had the same issue when trying to upgrade to 3.4, but postponed the upgrade at that point because I had other priorities.</p>
<p>I can add, remove and upgrade plugins from the store without problems with this image. I have composer.json and composer.lock writable, as well as the vendor folder, storage, and migrations.</p>
<p>EDIT: It actually seems like the change in 3.3.16 is causing this, the upgrade of yii to 2.0.30. Doing this:</p>
<pre><code>bash-4.4# composer require craftcms/cms:3.3.16
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Can only install one of: yiisoft/yii2[2.0.30, 2.0.21].
    - Can only install one of: yiisoft/yii2[2.0.30, 2.0.21].
    - Can only install one of: yiisoft/yii2[2.0.30, 2.0.21].
    - craftcms/cms 3.3.16 requires yiisoft/yii2 ~2.0.30.0 -&gt; satisfiable by yiisoft/yii2[2.0.30].
    - Installation request for craftcms/cms 3.3.16 -&gt; satisfiable by craftcms/cms[3.3.16].
    - Installation request for yiisoft/yii2 (locked at 2.0.21) -&gt; satisfiable by yiisoft/yii2[2.0.21].


Installation failed, reverting ./composer.json to its original content.
</code></pre>
<p>I don't understand why it complains about yii2 being locked to that version. Nothing in composer.lock is explicitly stating that version, they all use ~ versions.</p>
<p>But even when I delete the lock file, the vendor folder, and runs a composer install it seems to successfully install 2.0.30 of Yii2 but I still get that message, I'm starting to get very frustrated at composer...</p>
<p>EDIT 2: This is my composer file:</p>
<pre><code>{
  &quot;repositories&quot;: [
    {
      &quot;type&quot;: &quot;artifact&quot;,
      &quot;url&quot;: &quot;composer-artifacts/&quot;
    }
  ],
  &quot;require&quot;: {
    &quot;aws/aws-sdk-php&quot;: &quot;^3.112&quot;,
    &quot;carlcs/craft-redactorcustomstyles&quot;: &quot;3.0.2&quot;,
    &quot;codemix/yii2-streamlog&quot;: &quot;^1.2&quot;,
    &quot;craftcms/aws-s3&quot;: &quot;^1.2&quot;,
    &quot;craftcms/cms&quot;: &quot;^3.3.15&quot;,
    &quot;craftcms/redactor&quot;: &quot;2.3.3.2&quot;,
    &quot;dolphiq/redirect&quot;: &quot;1.0.24&quot;,
    &quot;mmikkel/retcon&quot;: &quot;2.0.12&quot;,
    &quot;thejoshsmith/craft-title-to-sidebar&quot;: &quot;1.0.1&quot;,
    &quot;verbb/super-table&quot;: &quot;2.3.3&quot;,
    &quot;vlucas/phpdotenv&quot;: &quot;^3.4.0&quot;
  },
  &quot;autoload&quot;: {
    &quot;psr-4&quot;: {
      &quot;rex\\craft\\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.0&quot;
    },
    &quot;github-oauth&quot;: {
      &quot;github.com&quot;: &quot;xxxxxx&quot;
    }
  },
  &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>EDIT 3: I used the same setup on a completely brand new 3.5.5 setup and did the upgrade to 3.5.6 without a hickup. Seems like there is some issues with 3.3.15 and upgrades, or perhaps some of the plugins (although I tried removing them from composer.json and it still fails).</p>
<p>EDIT 4: I tried running <code>./craft update all</code> within the container now, and the output just states:</p>
<pre><code>bash-5.0# ./craft update all
Fetching available updates ... done
Performing 6 updates:

    - craft 3.3.15 =&gt; 3.5.9
    - aws-s3 1.2.5 =&gt; 1.2.11
    - redactor 2.3.3.2 =&gt; 2.4.0
    - redactor-custom-styles 3.0.2 =&gt; 3.0.4
    - redirect 1.0.24 =&gt; 1.1.1
    - retcon 2.0.12 =&gt; 2.2.1

Backup the database? (yes|no) [yes]:no
Skipping database backup.
Performing update with Composer ... error: An error occurred

Output:

&lt;warning&gt;Package &quot;craftcms/vue-asset&quot; listed for update is not installed. Ignoring.&lt;/warning&gt;
&lt;warning&gt;Package &quot;danielstjules/stringy&quot; listed for update is not installed. Ignoring.&lt;/warning&gt;
&lt;warning&gt;Package &quot;yiisoft/yii2-shell&quot; listed for update is not installed. Ignoring.&lt;/warning&gt;
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for carlcs/craft-redactorcustomstyles 3.0.4 -&gt; satisfiable by carlcs/craft-redactorcustomstyles[3.0.4].
    - carlcs/craft-redactorcustomstyles 3.0.4 requires craftcms/redactor ^2.7.0 -&gt; satisfiable by craftcms/redactor[2.7.4, 2.7.3, 2.7.2, 2.7.1, 2.7.0] but these conflict with your requirements or minimum-stability.

&lt;warning&gt;Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.&lt;/warning&gt;


Revert the Composer changes? (yes|no) [yes]:
</code></pre>
<p>EDIT 5:</p>
<p>I have found the culprit, but don't really understand why this works in some versions but not in others.</p>
<p>In general.php, I'm using <code>yii\web\Request</code> to figure out the &quot;local&quot; hostname</p>
<pre><code>use yii\web\Request;
$request = new Request;

... 

'@baseUrlPrefix' =&gt; getenv('BASE_URL_PREFIX') ?: $request-&gt;getHostInfo(),
</code></pre>
<p>when setting an alias. That fails for some reason, on certain versions (of Yii? don't know).</p>

CC BY-SA 4.0
2020-08-21T15:28:44.200Z
What's in your composer.json file?
RitterKnight
CC BY-SA 4.0
2020-08-24T09:01:26.943Z
@RitterKnight I added my composer file. I have tried to set everything as "allow minor" changes with ^ but still no go.
jishi
CC BY-SA 4.0
2020-09-09T20:21:32.563Z
There's a lot going on here, but your last edit (#4) is easy enough. The Redactor Custom Styles plugin at 3.0.4 requires Redactor > 2.7.0. https://github.com/carlcs/craft-redactorcustomstyles/blob/v3/composer.json#L27 Change to `"carlcs/craft-redactorcustomstyles": "^3.0.2",` and `"craftcms/redactor": "^2.3.3.2",` then run `composer update` and that should resolve that one.
Brad Bell
CC BY-SA 4.0
2020-09-10T07:59:12.500Z
@BradBell When I choose to only upgrade craft, it just silently fails with error 255. everything I try ends up with the error that `use Yii` throws an error, albeit it being present in the vendor folder correctly. I even copied the composer.json/composer.lock from another working 3.5 site and ran composer install, and I still end up with the same error. I don't understand how my config or database state could trigger such a low level dependency error?
jishi
<upgrades><docker>
Upgrading Craft CMS fails
# Upgrading Craft CMS fails

(Asked by: username_0 on 2020-08-21)

I'm trying to upgrade from 3.3.15 -> 3.5.5 from control panel.
I run it via docker so all I need is to update the composer.lock file to have the correct dependencies and everything should be fine the next time I rebuild the image, but something strange is happening.
After selecting the upgrade, it runs for a few minutes and then just gets an internal server error. It logs the following:
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Class 'Yii' not found in /app/vendor/yiisoft/yii2/validators/IpValidator.php:218"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "Stack trace:"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "#0 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): yii\validators\IpValidator->init()"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "#1 /app/vendor/yiisoft/yii2/web/Request.php(345): yii\base\BaseObject->__construct()"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "#2 /app/vendor/yiisoft/yii2/web/Request.php(1877): yii\web\Request->getIpValidator()"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "#3 /app/vendor/yiisoft/yii2/web/Request.php(1859): yii\web\Request->getSecureForwardedHeaderTrustedParts()"
craft_1        | [21-Aug-2020 07:38:50] WARNING: [pool www] child 146 said into stderr: "#4 /app/vendor/yiisoft/yii2/web/Request.php(1084): yii\web\Request->getSecureForwardedHeaderTrustedPart('proto')"
craft_1        | 2020/08/21 07:38:50 [error] 139#139: *4 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: Class 'Yii' not found in /app/vendor/yiisoft/yii2/validators/IpValidator.php:218

which is a bit odd, why would a dependency disappear when upgrading like this? After this attempted upgrade, the install is left in a broken state, giving 500 errors (and the same error, Yii not found) for all requests. Reverting the composer.json + composer.lock file and reinstalling dependencies restores functionality.
I had the same issue when trying to upgrade to 3.4, but postponed the upgrade at that point because I had other priorities.
I can add, remove and upgrade plugins from the store without problems with this image. I have composer.json and composer.lock writable, as well as the vendor folder, storage, and migrations.
EDIT: It actually seems like the change in 3.3.16 is causing this, the upgrade of yii to 2.0.30. Doing this:
bash-4.4# composer require craftcms/cms:3.3.16
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Can only install one of: yiisoft/yii2[2.0.30, 2.0.21].
    - Can only install one of: yiisoft/yii2[2.0.30, 2.0.21].
    - Can only install one of: yiisoft/yii2[2.0.30, 2.0.21].
    - craftcms/cms 3.3.16 requires yiisoft/yii2 ~2.0.30.0 -> satisfiable by yiisoft/yii2[2.0.30].
    - Installation request for craftcms/cms 3.3.16 -> satisfiable by craftcms/cms[3.3.16].
    - Installation request for yiisoft/yii2 (locked at 2.0.21) -> satisfiable by yiisoft/yii2[2.0.21].


Installation failed, reverting ./composer.json to its original content.

I don't understand why it complains about yii2 being locked to that version. Nothing in composer.lock is explicitly stating that version, they all use ~ versions.
But even when I delete the lock file, the vendor folder, and runs a composer install it seems to successfully install 2.0.30 of Yii2 but I still get that message, I'm starting to get very frustrated at composer...
EDIT 2: This is my composer file:
{
  "repositories": [
    {
      "type": "artifact",
      "url": "composer-artifacts/"
    }
  ],
  "require": {
    "aws/aws-sdk-php": "^3.112",
    "carlcs/craft-redactorcustomstyles": "3.0.2",
    "codemix/yii2-streamlog": "^1.2",
    "craftcms/aws-s3": "^1.2",
    "craftcms/cms": "^3.3.15",
    "craftcms/redactor": "2.3.3.2",
    "dolphiq/redirect": "1.0.24",
    "mmikkel/retcon": "2.0.12",
    "thejoshsmith/craft-title-to-sidebar": "1.0.1",
    "verbb/super-table": "2.3.3",
    "vlucas/phpdotenv": "^3.4.0"
  },
  "autoload": {
    "psr-4": {
      "rex\\craft\\modules\\": "modules/"
    }
  },
  "config": {
    "sort-packages": true,
    "optimize-autoloader": true,
    "platform": {
      "php": "7.0"
    },
    "github-oauth": {
      "github.com": "xxxxxx"
    }
  },
  "scripts": {
    "post-root-package-install": [
      "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ]
  }
}


EDIT 3: I used the same setup on a completely brand new 3.5.5 setup and did the upgrade to 3.5.6 without a hickup. Seems like there is some issues with 3.3.15 and upgrades, or perhaps some of the plugins (although I tried removing them from composer.json and it still fails).
EDIT 4: I tried running ./craft update all within the container now, and the output just states:
bash-5.0# ./craft update all
Fetching available updates ... done
Performing 6 updates:

    - craft 3.3.15 => 3.5.9
    - aws-s3 1.2.5 => 1.2.11
    - redactor 2.3.3.2 => 2.4.0
    - redactor-custom-styles 3.0.2 => 3.0.4
    - redirect 1.0.24 => 1.1.1
    - retcon 2.0.12 => 2.2.1

Backup the database? (yes|no) [yes]:no
Skipping database backup.
Performing update with Composer ... error: An error occurred

Output:

Package "craftcms/vue-asset" listed for update is not installed. Ignoring.
Package "danielstjules/stringy" listed for update is not installed. Ignoring.
Package "yiisoft/yii2-shell" listed for update is not installed. Ignoring.
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for carlcs/craft-redactorcustomstyles 3.0.4 -> satisfiable by carlcs/craft-redactorcustomstyles[3.0.4].
    - carlcs/craft-redactorcustomstyles 3.0.4 requires craftcms/redactor ^2.7.0 -> satisfiable by craftcms/redactor[2.7.4, 2.7.3, 2.7.2, 2.7.1, 2.7.0] but these conflict with your requirements or minimum-stability.

Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.


Revert the Composer changes? (yes|no) [yes]:

EDIT 5:
I have found the culprit, but don't really understand why this works in some versions but not in others.
In general.php, I'm using yii\web\Request to figure out the "local" hostname
use yii\web\Request;
$request = new Request;

... 

'@baseUrlPrefix' => getenv('BASE_URL_PREFIX') ?: $request->getHostInfo(),

when setting an alias. That fails for some reason, on certain versions (of Yii? don't know).

**Tags:** upgrades, docker

> **Comments:**
> **username_1**: What's in your composer.json file?  
> **username_0**: @username_1 I added my composer file. I have tried to set everything as "allow minor" changes with ^ but still no go.  
> **username_2**: There's a lot going on here, but your last edit (#4) is easy enough. The Redactor Custom Styles plugin at 3.0.4 requires Redactor > 2.7.0. https://github.com/carlcs/craft-redactorcustomstyles/blob/v3/composer.json#L27 Change to `"carlcs/craft-redactorcustomstyles": "^3.0.2",` and `"craftcms/redactor": "^2.3.3.2",` then run `composer update` and that should resolve that one.  
> **username_0**: @BradBell When I choose to only upgrade craft, it just silently fails with error 255. everything I try ends up with the error that `use Yii` throws an error, albeit it being present in the vendor folder correctly. I even copied the composer.json/composer.lock from another working 3.5 site and ran composer install, and I still end up with the same error. I don't understand how my config or database state could trigger such a low level dependency error?  

---

## 2 answers

### Answer by username_3 on 2020-09-14. Score: 2

You can't create an new `yii\web\Request` instance in *general.php* because [Craft isn't fully initialized yet](https://github.com/craftcms/cms/issues/6439#issuecomment-662923202). It worked in previous versions but the Craft team seem to have changed the loading order.

You must find another way to define you site base URL.


---

### Answer by username_4 on 2020-09-09. Score: 0

Did you try removing composer.lock file and the vendor directory and then doing a fresh composer install?

> **Comments:**
> **username_0**: Yes, that was one of the first things I tried. It says it has installed everything correctly, but in the end Yii2 is still missing.  
> **username_0**: What's weirder is that vendor/yiisoft/yii2 is actually there. Could it be something off with autoload? I'm not sure how that stuff works...  
> **username_4**: I had similar issues when updating an older version of craft, I remember it was due to an incomaptible plugin. Could you try (temporarily) removing some of them and try running composer install again?  
> **username_0**: I have tried that as well, removing all plugins and only keeping craftcms, still the same issue. I even did a setup of a completely new project (which do work), then copy composer.json and composer.lock from that structure into my current install, but it still fails. I'm starting to wonder if there is something wrong with the bootstrap files, but index.php is identical and everything else seems to load from the vendor folder...  
> **username_4**: Have you tried manually setting the craft version in composer.json, ditching the lock file, vendor dir and doing a composer install? So bypassing craft update altogether  
> **username_0**: I thought I did, but retried it again and I have managed to upgrade it to 3.3.18 so far... when I jump directly to 3.3.20 it still gets the same error. I'm stumped.  
> **username_0**: I'm getting a similar problem at 3.3.19 now, as I had at 3.3.16 previously.  

---

