PHP error Class Env not found in application.php after upgrading to Wordpress 5.5

Good afternoon,

I am getting the following error in my docker console (when I try to navigate to my Wordpress site). FYI I’m mapping /bedrock directory to /var/www/html.

tbp-wp-wordpress    | NOTICE: PHP message: PHP Fatal error:  Uncaught Error: Class 'Env' not found in /var/www/html/config/application.php:30
tbp-wp-wordpress    | Stack trace:
tbp-wp-wordpress    | #0 /var/www/html/web/wp-config.php(8): require_once()
tbp-wp-wordpress    | #1 /var/www/html/web/wp/wp-load.php(42): require_once('/var/www/html/w...')
tbp-wp-wordpress    | #2 /var/www/html/web/wp/wp-blog-header.php(13): require_once('/var/www/html/w...')
tbp-wp-wordpress    | #3 /var/www/html/web/index.php(6): require('/var/www/html/w...')
tbp-wp-wordpress    | #4 {main}
tbp-wp-wordpress    |   thrown in /var/www/html/config/application.php on line 30
tbp-wp-wordpress    | -  12/Aug/2020:21:08:47 +0000 "GET /index.php" 500

To upgrade to Wordpress 5.5, I updated the values to the following in my composer.json and ran composer update.

  "require": {
    "php": ">=7.4",
    "composer/installers": "^1.8",
    "vlucas/phpdotenv": "^4.1.8",
    "oscarotero/env": "^2.1",
    "roots/wordpress": "^5.5",
    "roots/wp-config": "1.0.0",
    "roots/wp-password-bcrypt": "1.0.0",
    "wpackagist-plugin/redis-cache": "^2.0",
    "wpackagist-theme/twentytwenty": "^1.4",
    "wpackagist-plugin/elementor": "^2.9",
  "require-dev": {
    "squizlabs/php_codesniffer": "^3.5.6",
    "roave/security-advisories": "dev-master"

Line 30 in application.php is:

Things I have tried:

  • First time updating to WP 5.5 I used composer update
  • After encountering the error, and after reading the forums I deleted the /vendor directory and the /wp directory inside bedrock, and ran composer create-project
  • To confirm that the .env file was present, I entered my wordpress docker container and it was there

Any help or suggestions would be appreciated!

Thank you!

A few additional comments:

  • I removed the bedrock-autoloader as I wasn’t using that functionality (in case you are wondering why that isn’t in the composer.json
  • Composer version 1.10.9 2020-07-16 12:57:00

I tracked down the change that broke things, but I don’t know why this happened.

I tried my previous composer.json, and everything worked.

When I look at what packages are installed, because of the ^ everything is the same as the ones listed in my post above, except “oscarotero/env”

In my previous composer.json it was:
"oscarotero/env": "^1.2.0",

And for the WP5.5 update I updated it to match the latest release on GitHub which is:
"oscarotero/env": "^2.1",

Now I have no idea what the impact is of the new version, or whether there is a risk of using the older version - but at the moment everything works when I use the older one, and if I update that package to 2.1 then the PHP error returns.

Check out for the code required to use oscarotero/env @ version 2

1 Like

Hi @ben thank you for pointing this out. I’ll update the files that were changed in that PR for my own project.