Roots Discourse

Wp-cli fatal error on remote

SSHing into production server - works
wp-cli @dev <command> - works
wp-cli @prod --info - works
wp-cli @prod plugin list - returns this error:

Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/srv/www/website.com/releases/20210624173918/.env]. in /srv/www/website.com/releases/20210624173918/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /srv/www/website.com/releases/20210624173918/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /srv/www/website.com/releases/20210624173918/config/application.php(33): Dotenv\Dotenv->load()
#2 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1197) : eval()'d code(7): require_once('/srv/www/website...')
#3 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1197): eval()
#4 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1158): WP_CLI\Runner->load_wordpress()
#5 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(23): WP_CLI\Runner->start()
#6 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(74): WP_CLI\Bootstrap\LaunchRunner->p in /srv/www/website.com/releases/20210624173918/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68
Error: Cannot connect over SSH using provided configuration.

I’m using a recent bedrock, which has these versions in composer.json:

"php": ">=7.1",
    "composer/installers": "^1.10",
    "vlucas/phpdotenv": "^5.3",
    "oscarotero/env": "^2.1",

Also a recent trellis. The remote server has this version of wp-cli installed:

~$ wp --version
WP-CLI 2.4.0

This may be a separate issue, but I’m not able to run a wp command on the server without hitting a memory issue so I have to run it with some special addons as was advised in an issue on the trellis repo.
php -dmemory_limit=-1 "$(which wp)" package list
Is it possible to do that via an alias as well? Or is this not the problem.

The .env file on the remote has 600 permissions, is this correct?

Is this a Trellis web server?
Have you successfully ran the playbook (provision)?
Was the last site deployment successful?

Is this a Trellis web server? - yes
Have you successfully ran the playbook (provision)? - yes
Was the last site deployment successful? - yes

The phpdotenv Filestore line 68 is just checking that the file exists and has contents. When I SSH into the remote and check, the .env file exists and has what looks to be all the right variables in it. So, maybe something about the connection or permissions is not right.
ls -al on the remote:
Screen Shot 2021-06-24 at 12.35.37 PM

Edit: Correction: The permissions should be fine already with just the owner being able to read the file
But maybe your code expects more permissions than that?

Does the file /srv/www/website.com/releases/20210624173918/.env actually exist under that path?
What does stats /srv/www/website.com/releases/20210624173918/.env show you?

Some funky stuff is happening here. I’ll reply back a bit later. Thank you @strarsis appreciate it

Also check what alias you are actually using. I had once the issue that I thought I am running wp on the staging system, but it was production instead, and things were missing (like releases).