Trellis provision development fails on TASK [wordpress-install : Install WP]

I am migrating an old trellis vagrant project to the latest version (1.22.2) using lima on MacOS Ventura (M1).

In composer.json under extras I have
"wordpress-install-dir": "web/wp"

When I run trellis provision development I get a path error “This does not seem to be a WordPress installation. The used path is: /srv/www/***.com/current/”

TASK [wordpress-install : Install WP] ******************************************

failed: [default] (item=***.com) => {"ansible_loop_var": "item", "changed": true, "cmd": ["wp", "core", "install", "--allow-root", "--url=https://***.test", "--title=***.com", "--admin_user=admin", "--admin_password=password", "--admin_email=name@domain.com"], "delta": "0:00:00.077987", "end": "2024-06-11 17:45:11.594781", "item": {"key": "***.com", "value": {"admin_email": "name@domain.com", "cache": {"enabled": false}, "local_path": "../site", "multisite": {"enabled": false}, "site_hosts": [{"canonical": "***.test", "redirects": ["www.***.test"]}], "ssl": {"enabled": true, "provider": "self-signed"}}}, "msg": "non-zero return code", "rc": 1, "start": "2024-06-11 17:45:11.516794", "stderr": "Error: This does not seem to be a WordPress installation.\nThe used path is: /srv/www/***.com/current/\nPass --path=`path/to/wordpress` or run `wp core download`.", "stderr_lines": ["Error: This does not seem to be a WordPress installation.", "The used path is: /srv/www/***.com/current/", "Pass --path=`path/to/wordpress` or run `wp core download`."], "stdout": "", "stdout_lines": []}


PLAY RECAP *********************************************************************
default                    : ok=122  changed=6    unreachable=0    failed=1    skipped=35   rescued=0    ignored=0   

exit status 2

I’ve checked other posts regarding this but they seem to be vagrant specific (and from 2019 and earlier). Does the ‘wordpress-install-dir’ entry need to be put elsewhere in composer.json in v1.22.2?

Thanks,
Julian

In current roots Bedrock (1.24.2) the wordpress-install-dir is (still) set in that way:

What is inside /srv/www/***.com/current, are the WordPress core files installed? Has composer install successfully ran before the wp CLI install step? Can you invoke the composer install command manually (https://github.com/roots/trellis/blob/daf531f2fb94394ce658f5d441a7e48eaa14e20e/roles/wordpress-install/tasks/main.yml#L29; so as web user (no root) web@[...]:~$ composer install --no-dev --optimize-autoloader --working-dir=/srv/www/***.com/current) in terminal?

@strarsis

Everything seems to be in place.
WordPress files are in …/current/web/wp

current contains vendor/ & web/, .env, composer.json, composer.lock
web contains app/ & wp/

composer install --no-dev --optimize-autoloader --working-dir=/srv/www/headphonecommute.com/current/

returns

Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Nothing to install, update or remove
Generating optimized autoload files

OK, so what do you get when you invoke in terminal as user web in that current/ directory wp core install:
wp core install --allow-root --url=https://***.test --title=***.com --admin_user=admin --admin_password=password --admin_email=name@domain.com (with the redacted values completed, of course).
Any error messages? What is the exit status code of that command (echo $? to get the exit status code of last command)?

running that from current/ I get:

Error: This does not seem to be a WordPress installation.
The used path is: /srv/www/***.com/current/
Pass --path=`path/to/wordpress` or run `wp core download`.

exit status code : 127

Is there a file wp-includes/version.php in web/wp in current/ of that affected site (e.g. $ stat web/wp/wp-includes/version.php)?

https://github.com/wp-cli/wp-cli/blob/a339dca576df73c31af4b4d8054efc2dab9a0685/php/WP_CLI/Runner.php#L1007

What composer.json are you using for that site?
Does it require roots/wordpress package?
https://github.com/roots/bedrock/blob/8df74d1dfdd60953db939ac7cbd3d134310aa863/composer.json#L40

stat results look ok

File: web/wp/wp-includes/version.php
  Size: 930             Blocks: 8          IO Block: 4096   regular file
Device: 27h/39d Inode: 7542        Links: 1
Access: (0644/-rw-r--r--)  Uid: (  501/julianweaver)   Gid: ( 1000/julianweaver)
Access: 2024-06-11 14:43:52.704913624 +0000
Modify: 2024-06-05 15:13:19.000000000 +0000
Change: 2024-06-11 14:43:11.033083541 +0000
 Birth: -

composer.json is based on Bedrock 1.24.2 :

{
  "name": "roots/bedrock",
  "type": "project",
  "license": "MIT",
  "description": "WordPress boilerplate with Composer, easier configuration, and an improved folder structure",
  "homepage": "https://roots.io/bedrock/",
  "authors": [
    {
      "name": "Scott Walkinshaw",
      "email": "scott.walkinshaw@gmail.com",
      "homepage": "https://github.com/swalkinshaw"
    },
    {
      "name": "Ben Word",
      "email": "ben@benword.com",
      "homepage": "https://github.com/retlehs"
    }
  ],
  "keywords": [
    "bedrock", "composer", "roots", "wordpress", "wp", "wp-config"
  ],
  "support": {
    "issues": "https://github.com/roots/bedrock/issues",
    "forum": "https://discourse.roots.io/category/bedrock"
  },
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org",
      "only": ["wpackagist-plugin/*", "wpackagist-theme/*"]
    },
    {
      "type": "git",
      "name": "**/**",
      "url": "git@github.com:***/***.git"
    },
    {
      "type": "composer",
      "url": "https://connect.advancedcustomfields.com"
    }
  ],
  "require": {
    "php": ">=8.0",
    "composer/installers": "^2.2",
    "vlucas/phpdotenv": "^5.5",
    "oscarotero/env": "^2.1",
    "roots/bedrock-autoloader": "^1.0",
    "roots/bedrock-disallow-indexing": "^2.0",
    "roots/wordpress": "6.5.4",
    "roots/wp-config": "1.0.0",
    "roots/wp-password-bcrypt": "1.1.0",
    "**/**": "dev-modernise/sage/update-to-v10",
    "wpengine/advanced-custom-fields-pro": "*",
    "stoutlogic/acf-builder": "^1.12.0",
    "wpackagist-plugin/autodescription": "^4.1.5.1",
    "wpackagist-plugin/force-regenerate-thumbnails": "^2.1.4",
    "wpackagist-plugin/clean-image-filenames": "^1.5",
    "wpackagist-plugin/format-media-titles": "^1.0",
    "wpackagist-plugin/thumbnail-crop-position": "^1.3",
    "wpackagist-plugin/menu-icons": "^0.13.14",
    "wpackagist-plugin/rich-text-excerpts": "^1.3.4",
    "wpackagist-plugin/no-category-base-wpml": "^1.3",
    "wpackagist-plugin/vaultpress": "^3.0.0",
    "wpackagist-plugin/akismet": "^5.3.2",
    "wpackagist-plugin/redirection": "^5.4.2",
    "wpackagist-plugin/wordpress-importer": "^0.8.2",
    "wpackagist-plugin/disable-gutenberg": "^3.1.1",
    "wpackagist-plugin/amp": "^2.5.3",
    "johnbillion/extended-cpts": "^5.0.7",
    "wpackagist-plugin/wp-nested-pages": "^3.2.7",
    "wpackagist-plugin/relevanssi": "^4.22.2",
    "wpackagist-plugin/polldaddy": "^3.1.1",
    "wpackagist-plugin/jetpack": "^13.5",
    "wpackagist-plugin/better-search-replace": "^1.4.7",
    "wpackagist-plugin/simple-wp-maintenance-mode": "^1.0",
    "wpackagist-plugin/rvg-optimize-database": "^5.2.2"
  },
  "require-dev": {
    "squizlabs/php_codesniffer": "^3.7.2",
    "roave/security-advisories": "dev-latest"
  },
  "config": {
    "optimize-autoloader": true,
    "preferred-install": "dist",
    "allow-plugins": {
      "composer/installers": true,
      "roots/wordpress-core-installer": true
    }
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  "extra": {
    "installer-paths": {
      "web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
      "web/app/plugins/{$name}/": ["type:wordpress-plugin"],
      "web/app/themes/{$name}/": ["type:wordpress-theme"]
    },
    "wordpress-install-dir": "web/wp"
  },
  "scripts": {
    "post-root-package-install": [
      "php -r \"copy('.env.example', '.env');\""
    ],
    "test": [
      "phpcs"
    ]
  }
}

Also try a different command that is simpler, as wp core version.
Does that command work in current/web or current/web/wp?

Edit: By the way: Is there a wp-cli.yml (in current/)?

Without that, the docroot for WP CLI is not set from the default (CWD) - mystery solved!
The wp-cli.yml should be checked into the Bedrock site, it is necessary for the WP CLI command to work - at least in my tests. I strongly suspect this is also the case when Trellis deploys the site and invokes WP CLI.

The extra.wordpress-install-dir field in site composer.json only installs the files to a specific directory, WP CLI is not configured to use that directory relative from the CWD, for that wp-cli.yml has to be used to configure it.

wp core version works only in web/wp/

I have wp-cli.yml checked in and the contents match the repo.

There is no wp-cli.ymlon the vm in current/

I think that’s it, just re-running trellis provision development

It must be there in order for WP CLI to work from current/ though.
Can you manually add that file and check whether WP CLI works from current/ then?

The next question is why the wp-cli.yml is missing from current/.

Is it really on the repository that Trellis pulls from? Correct branch, tag/hash (if that is used)?

Yes, WP CLI now works from current/

wp-cli.yml is definitely in the repository.
I’ve just checked across all branches and it’s the same in each.

Is the cloning of project files working and happening during Trellis deploy?

The cloned git repository is located by default in shared/source/ of site directory (one directory above current/).
Invoke git log there and check whether really the current commit is there.

If I understand the config correctly, Trellis would then checkout from that local git repository (using git archive):
https://github.com/roots/trellis/blob/daf531f2fb94394ce658f5d441a7e48eaa14e20e/roles/deploy/tasks/prepare.yml#L33
Is this task also happening, and does it happen successfully, without errors?

There is nothing in shared/

But I can see changes to the theme repo (committed this morning) in current/web/app/themes/...

:thinking: Maybe your Trellis setup deploys the site differently.
Edit: Hm, this Trellis setup is on a staging/dev VM, right? Then deployments may be different.

Is there a wp-cli.yml in the site .gitignore (current/.gitignore as it should be also cloned there) by chance (do not confuse with wp-cli.local.yml which should actually be ignored!)?

Yes, this is just the dev vm atm.
No, wp-cli.yml in the repo .gitignore
There is no .gitignore in current/ on the vm though.

It’s tempting to delete this vm and run it all again from scratch.

When I correctly understand this config, the directories should already be mounted into Lima:

But when there is already a setup with Trellis CLI and Lima, this should be already correctly handled.

Are there any other files in current/, as phpcs.xml? When you create a dummy file, will this file also appear in current/?

No other files are in current/ except:

-rw-r--r--  1 julianweaver julianweaver   1157 Jun 12 09:13 .env
-rw-r--r--  1 julianweaver julianweaver   3701 Jun 11 14:35 composer.json
-rw-r--r--  1 julianweaver julianweaver 322353 Jun 11 14:21 composer.lock
drwxr-xr-x 33 julianweaver julianweaver   1056 Jun 12 09:13 vendor
drwxr-xr-x  4 julianweaver julianweaver    128 Jun 11 14:43 web
-rw-r--r--  1 julianweaver julianweaver     36 Jun 12 09:53 wp-cli.yml

wp-cli.yml I put there earlier.

The config does look like it should mount there, but nothing changes when I add files to the directory at AbsLocalPath

Can you pause/resume / restart the VM and check whether this makes the files appear in the current/ mount inside the VM?

In the interim, I went ahead and deleted the VM.
I created a new one and it provisioned all of the way through.
It is also syncing the current/ directory properly’

Thanks for taking me through those steps across trellis/ trellis-cli. I learnt a lot!