Cannot *trellis* ssh into production server or use wp commands

Hi all. I’m new to figuring out the Roots stack and am starting to have some issues after my initial deployment. Right now I’m working on figuring out backing up and syncing databases between local and production servers deployed on GCP, AWS and other CloudVPS services.

I guess part of this issue is similar to, if not the same as this one which doesn’t appear to have a solve, and then maybe I have a separate issue re: using wp-cli on the production server.

So right now I can use trellis deploy production or trellis provision production with no issues, but when I use trellis ssh production it automatically tries to connect to admin@myhost even though I have admin_user: nathandonnelly at the top of my group_vars > all > users.yml file.

I also have the wp aliases set up as per the docs and can run wp @development theme activate *themename* or wp @development db export with no issues, but if I run wp @production db export I get a stack trace that seems to connect to the server but says something about dotenv and wp-cli not working right, and results in Error: Cannot connect over SSH using provided configuration.

I can ssh directly into the production server with trellis ssh -u nathandonnelly production but then if I run wp db export from there it gives me the same error re: dotenv which I’ll paste below but change my site name to example.com.

Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/srv/www/test.example.com/releases/20250205194622/.env]. in /srv/www/test.example.com/releases/20250205194622/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /srv/www/test.example.com/releases/20250205194622/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /srv/www/test.example.com/releases/20250205194622/config/application.php(49): Dotenv\Dotenv->load()
#2 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1335) : eval()'d code(7): require_once('/srv/www/test.e...')
#3 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1335): eval()
#4 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1294): WP_CLI\Runner->load_wordpress()
#5 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#6 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#7 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#8 phar:///usr/bin/wp/php/boot-phar.php(20): include('phar:///usr/bin...')
#9 /usr/bin/wp(4): include('phar:///usr/bin...')
#10 {main}
  thrown in /srv/www/test.example.com/releases/20250205194622/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68

I’ve tried re-provisioning, deploying, rolling back. Those commands seem to work. Anyone have any insight into this? I asked ChatGPT about it and it said something about symlinking the .env file to the shared folder vs. being available in the current and individual release folders but I figured that’s gotta be wrong because I think trellis should take care of where that goes.

I’m using trellis-cli v1.13.0 and lima for local development on MacOS if that matters.

Thanks in advance,
Nathan.

Can you show us your site/wp-cli.yml config?

1 Like

Sure thing. Everything in the site > config folder is completely stock, out of the box and has not been edited - but it looks like I don’t have a production.php file… I think that’s normal. There’s an application.php and folder called environment which has a development.php and staging.php. None of these files have been touched.

wp-cli.yml:

path: web/wp
server:
  docroot: web
_:
  inherit: wp-cli.trellis-alias.yml

wp-cli.trellis-alias.yml:

"@development":
  ssh: "test.ichangedthis.test"
  path: "/srv/www/test.ichangedthis.com/current/web/wp"
"@production":
  ssh: "nathandonnelly@test.ichangedthis.com:22"
  path: "/srv/www/test.ichangedthis.com/current/web/wp"
"@staging":
  ssh: "web@your_server_hostname:22"
  path: "/srv/www/test.ichangedthis.com/current/web/wp"

Have changed the website name in the pasted code because it shouldn’t matter. The @production ssh user also used to read web@myhostname:22 and that didn’t work as well.

WP-CLI alias and Trellis CLI issues aside, you’re not able to run any wp commands on the remote server at all?

Is there an .env file in the latest release directory?

Does the front-end of the website work?

You’re able to deploy without failures?

Front end of the website works. I can log into the WordPress backend.

There is a .env in the latest release directory and current which looks symlinked.

To my knowledge, it looks like I am able to deploy without any issues. Here’s some intel on the directory structure of the server:

nathandonnelly@Nathans-MacBook-Air site % trellis ssh -u nathandonnelly production                                                                                                                     main
Running command => ssh nathandonnelly@test.mysite.com
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-1074-gcp x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

 System information as of Thu Feb  6 19:30:42 UTC 2025

  System load:  0.22              Processes:             118
  Usage of /:   64.7% of 9.51GB   Users logged in:       0
  Memory usage: 23%               IPv4 address for ens4: 10.128.0.3
  Swap usage:   37%

 * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
   just raised the bar for easy, resilient and secure K8s cluster deployment.

   https://ubuntu.com/engage/secure-kubernetes-at-the-edge

Expanded Security Maintenance for Applications is not enabled.

25 updates can be applied immediately.
5 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable

10 additional security updates can be applied with ESM Apps.
Learn more about enabling ESM Apps service at https://ubuntu.com/esm

New release '22.04.5 LTS' available.
Run 'do-release-upgrade' to upgrade to it.


*** System restart required ***
nathandonnelly@instance-20250124-040305:~$ cd /srv/www/test.mysite.com/
nathandonnelly@instance-20250124-040305:/srv/www/test.mysite.com$ ls -la
total 20
drwxr-xr-x 5 web www-data 4096 Feb  5 21:10 .
drwxr-xr-x 4 web www-data 4096 Feb  5 00:07 ..
lrwxrwxrwx 1 web www-data   56 Feb  5 21:10 current -> /srv/www/test.mysite.com/releases/20250205194622
drwxr-xr-x 2 web www-data 4096 Feb  5 00:11 logs
drwxr-xr-x 5 web www-data 4096 Feb  5 20:08 releases
drwxr-xr-x 4 web www-data 4096 Feb  5 00:39 shared
nathandonnelly@instance-20250124-040305:/srv/www/test.mysite.com$ cd releases/20250205194622/
nathandonnelly@instance-20250124-040305:/srv/www/test.mysite.com/releases/20250205194622$ ls -la
total 360
drwxr-xr-x  5 web www-data   4096 Feb  5 19:47 .
drwxr-xr-x  5 web www-data   4096 Feb  5 20:08 ..
-rw-r--r--  1 web www-data   6148 Feb  5 19:46 .DS_Store
-rw-------  1 web www-data   1499 Feb  5 19:46 .env
-rw-r--r--  1 web www-data    805 Feb  5 19:46 .env.example
-rw-r--r--  1 web www-data    320 Feb  5 19:46 .gitignore
-rw-r--r--  1 web www-data   1057 Feb  5 19:46 LICENSE.md
-rw-r--r--  1 web www-data   3854 Feb  5 19:46 README.md
-rw-r--r--  1 web www-data   2400 Feb  5 19:46 composer.json
-rw-r--r--  1 web www-data 301868 Feb  5 19:46 composer.lock
drwxr-xr-x  3 web www-data   4096 Feb  5 19:46 config
-rw-r--r--  1 web www-data    169 Feb  5 19:46 pint.json
drwxr-xr-x 28 web www-data   4096 Feb  5 19:46 vendor
drwxr-xr-x  4 web www-data   4096 Feb  5 19:46 web
-rw-r--r--  1 web www-data    325 Feb  5 19:46 wp-cli.trellis-alias.yml
-rw-r--r--  1 web www-data     75 Feb  5 19:46 wp-cli.yml
nathandonnelly@instance-20250124-040305:/srv/www/test.mysite.com/releases/20250205194622$ cd ../../current
nathandonnelly@instance-20250124-040305:/srv/www/test.mysite.com/current$ ls -la
total 360
drwxr-xr-x  5 web www-data   4096 Feb  5 19:47 .
drwxr-xr-x  5 web www-data   4096 Feb  5 20:08 ..
-rw-r--r--  1 web www-data   6148 Feb  5 19:46 .DS_Store
-rw-------  1 web www-data   1499 Feb  5 19:46 .env
-rw-r--r--  1 web www-data    805 Feb  5 19:46 .env.example
-rw-r--r--  1 web www-data    320 Feb  5 19:46 .gitignore
-rw-r--r--  1 web www-data   1057 Feb  5 19:46 LICENSE.md
-rw-r--r--  1 web www-data   3854 Feb  5 19:46 README.md
-rw-r--r--  1 web www-data   2400 Feb  5 19:46 composer.json
-rw-r--r--  1 web www-data 301868 Feb  5 19:46 composer.lock
drwxr-xr-x  3 web www-data   4096 Feb  5 19:46 config
-rw-r--r--  1 web www-data    169 Feb  5 19:46 pint.json
drwxr-xr-x 28 web www-data   4096 Feb  5 19:46 vendor
drwxr-xr-x  4 web www-data   4096 Feb  5 19:46 web
-rw-r--r--  1 web www-data    325 Feb  5 19:46 wp-cli.trellis-alias.yml
-rw-r--r--  1 web www-data     75 Feb  5 19:46 wp-cli.yml
nathandonnelly@instance-20250124-040305:/srv/www/test.mysite.com/current$ cd ../shared
nathandonnelly@instance-20250124-040305:/srv/www/test.mysite.com/shared$ ls -la
total 16
drwxr-xr-x 4 web www-data 4096 Feb  5 00:39 .
drwxr-xr-x 5 web www-data 4096 Feb  5 21:10 ..
drwxr-xr-x 5 web www-data 4096 Feb  5 19:46 source
drwxr-xr-x 5 web www-data 4096 Feb  5 00:41 uploads
 

Here’s what a wp command run on the remote server appears to do.

wp db export gives:

nathandonnelly@instance-20250124-040305:/srv/www/test.mysite.com/current$ wp db export

Fatal error: Uncaught Dotenv\Exception\InvalidPathException: Unable to read any of the environment file(s) at [/srv/www/test.mysite.com/releases/20250205194622/.env]. in /srv/www/test.mysite.com/releases/20250205194622/vendor/vlucas/phpdotenv/src/Store/FileStore.php:68
Stack trace:
#0 /srv/www/test.mysite.com/releases/20250205194622/vendor/vlucas/phpdotenv/src/Dotenv.php(222): Dotenv\Store\FileStore->read()
#1 /srv/www/test.mysite.com/releases/20250205194622/config/application.php(49): Dotenv\Dotenv->load()
#2 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1335) : eval()'d code(7): require_once('/srv/www/test.c...')
#3 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1335): eval()
#4 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1294): WP_CLI\Runner->load_wordpress()
#5 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start()
#6 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process(Object(WP_CLI\Bootstrap\BootstrapState))
#7 phar:///usr/bin/wp/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap()
#8 phar:///usr/bin/wp/php/boot-phar.php(20): include('phar:///usr/bin...')
#9 /usr/bin/wp(4): include('phar:///usr/bin...')
#10 {main}
  thrown in /srv/www/test.mysite.com/releases/20250205194622/vendor/vlucas/phpdotenv/src/Store/FileStore.php on line 68

wp theme activate mythemename gives the same error.

1 Like

Can you try connecting to the server as web, not as nathandonnelly? I think that as you are connecting as nathandonnelly and the .env file owner is the user web the wp db export command is executing with your user and it doesn’t have the correct permission.

Did you provision the production server with the nathandonnelly user? If the web server is executing with the nathandonnelly user, maybe u should deploy with that user instead of the web user. You can change that in the trellis/group_vars/production/main.yml file:

web_user: nathandonnelly
web_group: www-data

… and deploy again to set the correct owner to the files on deploy… :smiley: