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

Hello everybody

I use Trellis and Bedrock in several projects and really like it so far!

Today I tried to create a new project and suddenly an unknown error occurred during provisioning:

TASK [wordpress-install : Install WP] ******************************************
System info:
Ansible 2.4.2.0; Vagrant 2.0.1; Darwin
Trellis at "Bump Ansible `version_tested_max` to 2.4.2.0"
---------------------------------------------------
non-zero return code
PHP Fatal error:  Uncaught Error: Class 'Dotenv\Dotenv' not found in
/srv/www/fcsaliansa.ch/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->p
rocess(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/fcsaliansa.ch/current/config/application.php on line 17
failed: [default] (item=fcsaliansa.ch) => {"changed": true, "cmd": ["wp", "core", "install", "--allow-root", "--url=http://fcsaliansa.test", "--title=fcsaliansa.ch", "--admin_user=admin", "--admin_password=welcome1", "--admin_email=admin@fcsaliansa.test"], "delta": "0:00:00.090601", "end": "2018-01-04 16:34:23.628926", "item": "fcsaliansa.ch", "rc": 255, "start": "2018-01-04 16:34:23.538325", "stderr_lines": ["PHP Fatal error:  Uncaught Error: Class 'Dotenv\\Dotenv' not found in /srv/www/fcsaliansa.ch/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/fcsaliansa.ch/current/config/application.php on line 17"], "stdout": "", "stdout_lines": []}

I used the newest version of Trellis/Bedrock and only edited the development variables in group_vars.
Can someone guess a solution?

Thank you very much in advance!

3 Likes

Weird :thinking:

That error means Dotenv wasn’t autoloaded properly. Which means something likely went wrong with Composer.

I suggest making sure Composer is working as expected on the VM. You can run composer install and make sure the output looks fine. And that a dotenv dir exists in /srv/www/fcsaliansa.ch/current/vendor.

I have the exact same issue. So I can’t imagine that it is a local problem.
But I also get the following notice before, what might be the root as well:

TASK [wordpress-install : Setup packagist.com authentication] ******************
 [WARNING]: Failure using method (v2_runner_item_on_skipped) in callback plugin
(<ansible.plugins.callback.output.CallbackModule object at 0x10cd09c90>):
'item'

Best regards

Thanks for your advice. First I thought the “dotenv” folder is missing in /vendor but it’s located in /vendor/vlucas/phpdotenv

vagrant up --provision still has the same error.

Best regards,

Philipp

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