PHP Fatal error: Uncaught Error: Class 'Dotenv\Dotenv' not found

Same here. dontenv is not available for wp-cli, but on the regular webserver environment. I’m using the latest trellis version together with ansible 2.4.0.0. But dotenv is installed in vendor/vlucas/phpdotenv

I’ve already tried switching wp-cli versions without any success.

I have a feeling this has to do with the new version of Composer that just came out

Yup, good catch. I ran this in the vagrant box to fix it:
rm -rf vendor/
sudo rm /usr/local/bin/composer
wget https://github.com/composer/composer/releases/download/1.5.6/composer.phar
chmod +x composer.phar
sudo mv composer.phar /usr/local/bin/composer
composer install

1 Like

Add this to group_vars/all/main.yml:

composer_version: 1.5.6
1 Like

In the middle of a launch so don’t have time to comment, but this seems to be relevant:

UPDATE:

Composer 1.6.2 is out which fixes this bug. If you re-provision your server you should get the new version. If you made the edits originally listed below, remove them first.

Your main config should have this setting:

# group_vars/all/main.yml
composer_keep_updated: true
  1. reprovision your server (ansible-playbook server.yml -e env=<environment> --tags "composer")
  2. re-deploy your site

For development, run this: ANSIBLE_TAGS=composer vagrant provision.


Old details:

Summary

To sum this issue up:

Composer 1.6.1 came out and apparently has an autoload bug.

The solution in Trellis is to pin the Composer version to the last release and turn off the auto-update feature.

# group_vars/all/main.yml
composer_keep_updated: false
composer_version: 1.5.6

Add this to group_vars/all/main.yml.

Then do the following for remote servers

  1. reprovision your server (ansible-playbook server.yml -e env=<environment> --tags "composer")
  2. re-deploy your site

For development, run this: ANSIBLE_TAGS=composer vagrant provision.

10 Likes

When I run

ansible-playbook server.yml -e env=development --tags "composer"

I get

MODULE FAILURE
sudo: a password is required
1 Like

Same here. I even deleted the whole server from virtual box and set
composer_keep_updated: false
composer_version: 1.5.6
in group_vars/all/main.yml but still I get the following error on vagrant up:

ASK [wordpress-install : Install Dependencies with Composer] ******************
System info:
  Ansible 2.4.2.0; Vagrant 2.0.0; Darwin
  Trellis at "Bump Ansible `version_tested_max` to 2.4.2.0"
---------------------------------------------------
Loading composer repositories with package information Installing
dependencies (including require-dev) from lock file Package operations: 6
installs, 0 updates, 0 removals - Installing johnpbloch/wordpress-core
(4.9.1): Failed to download johnpbloch/wordpress-core from dist: Could not
delete web/wp/wp-content/themes/twentyfifteen: Now trying to download from
source - Installing johnpbloch/wordpress-core (4.9.1): [RuntimeException]
Could not delete web/wp/wp-content/themes/twentyfifteen: install [--prefer-
source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-
installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest]
[-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-
authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--]
[<packages>]...
failed: [default] (item=ouun.io) => {"changed": false, "item": "ouun.io", "stdout": "Loading composer repositories with package information\nInstalling dependencies (including require-dev) from lock file\nPackage operations: 6 installs, 0 updates, 0 removals\n  - Installing johnpbloch/wordpress-core (4.9.1):     Failed to download johnpbloch/wordpress-core from dist: Could not delete web/wp/wp-content/themes/twentyfifteen: \n    Now trying to download from source\n  - Installing johnpbloch/wordpress-core (4.9.1): \n                                                            \n  [RuntimeException]                                        \n  Could not delete web/wp/wp-content/themes/twentyfifteen:  \n                                                            \n\ninstall [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]...\n\n", "stdout_lines": ["Loading composer repositories with package information", "Installing dependencies (including require-dev) from lock file", "Package operations: 6 installs, 0 updates, 0 removals", "  - Installing johnpbloch/wordpress-core (4.9.1):     Failed to download johnpbloch/wordpress-core from dist: Could not delete web/wp/wp-content/themes/twentyfifteen: ", "    Now trying to download from source", "  - Installing johnpbloch/wordpress-core (4.9.1): ", "                                                            ", "  [RuntimeException]                                        ", "  Could not delete web/wp/wp-content/themes/twentyfifteen:  ", "                                                            ", "", "install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]...", ""]}

Might there be any relation with the following in requirements.yml:

- name: composer
  src: geerlingguy.composer
  version: 1.6.1
1 Like

You wouldn’t run this on development. Sorry I should have been clear those steps are for remote servers.

For dev just run ANSIBLE_TAGS=composer vagrant provision

1 Like

No, it’s just a hilarious coincidence that those release numbers match up :frowning:

1 Like

I’d try just deleting your vendor dir and run it again.

2 Likes

Thanks for the updates and fixes here guys. I ran into the same issue today and can confirm the fix @swalkinshaw posted works.

Thank you @swalkinshaw for the fix! I can confirm it too.

Best regards

Works!

Please publish this as a hotpatch in the current master branche (at least, for now).

Composer 1.6.2 is out that fixed this autoload bug.

2 Likes

I’ve updated my pinned solution to reflect the new Composer version.

1 Like

Not sure if this is related to this but I now receive the following error if I want to use WP-CLI directly in the terminal as well as connected via “vagrant ssh”:

PHP Fatal error:  Uncaught Error: Class 'Dotenv\Dotenv' not found in /srv/www/xyz/current/config/application.php:17
Stack trace:
#0 phar:///usr/bin/wp/php/WP_CLI/Runner.php(1070) : eval()'d code(7): require_once()
#1 phar:///usr/bin/wp/php/WP_CLI/Runner.php(1070): eval()
#2 phar:///usr/bin/wp/php/WP_CLI/Runner.php(1032): WP_CLI\Runner->load_wordpress()
#3 phar:///usr/bin/wp/php/WP_CLI/Bootstrap/LaunchRunner.php(23): WP_CLI\Runner->start()
#4 phar:///usr/bin/wp/php/bootstrap.php(75): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#5 phar:///usr/bin/wp/php/wp-cli.php(23): WP_CLI\bootstrap()
#6 phar:///usr/bin/wp/php/boot-phar.php(8): include('phar:///usr/bin...')
#7 /usr/bin/wp(4): include('phar:///usr/bin...')
#8 {main}
  thrown in /srv/www/xyz/current/config/application.php on line 17

I already switched back to composer_keep_updated: true and run ANSIBLE_TAGS=composer vagrant provision. But with composer 1.5.6 and 1.6.2 I get the same result.

Thank you again and best regards,

Philipp

I’ve spooled up a fresh install and I’m getting the following error:

non-zero return code
PHP Fatal error: Uncaught Error: Call to undefined method
Dotenv\Dotenv::create() in /srv/www/site.com/releases/20190227223826/config/application.php:27

Since I’m replying to a year old thread, not sure if this is still relevant but I’ve performed the following without any luck:

rm -rf vendor/
sudo rm /usr/local/bin/composer
wget https://github.com/composer/composer/releases/download/1.5.6/composer.phar
chmod +x composer.phar
sudo mv composer.phar /usr/local/bin/composer
composer install

I’m able to provision the server locally and on a DO droplet but when I attempt a deploy, I get the error above.

Prior to attempting my first deploy, I first installed all my composer dependencies and was given an error when composer attempts to install: philippbaschke/acf-pro-installer

The error states that it requires phpdotenv 2.2 so I changed the version from 3.0.0 to 2.2 and ran composer update which then throws the error from above.

I reverted back to the default composer file supplied with Bedrock and I’m still getting the same error.