Roots Discourse

Deploy fails at 'Wordpress Installed?'

My deploy has just started failing to my production server, but still works fine on staging. This is the error message i’m getting:

TASK [deploy : WordPress Installed?] *************************************************************************************************************
System info:
  Ansible 2.9.6; Darwin
  Trellis version (per changelog): "Improve handling of PHP versions and support PHP 8.0"
---------------------------------------------------
non-zero return code
fatal: [178.62.58.180]: FAILED! => {"changed": false, "cmd": ["wp", "core", "is-installed", "--skip-plugins", "--skip-themes", "--require=/srv/www/squaremilechurches.com/shared/tmp_multisite_constants.php"], "delta": "0:00:00.243627", "end": "2021-06-04 13:28:00.113050", "failed_when_result": true, "rc": 255, "start": "2021-06-04 13:27:59.869423", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

PLAY RECAP ***************************************************************************************************************************************
178.62.58.180              : ok=25   changed=9    unreachable=0    failed=1    skipped=33   rescued=0    ignored=0   
localhost                  : ok=0    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

It seemed to coincide with setting up wp-rocket, but that might just be a coincidence because it’s working on staging, and i’ve removed the stuff added for wp-rocket and it’s still doing this.

I was able to deploy fine this morning.

Any help appreciated!

Can you ssh into your server and run the wp cli command?

Running the trellis command with verbose output might also show you more information.

Thanks for the reply. I can ssh into the server, but not sure what command I should run?

Also, have you provisioned the server (don’t confuse with deploying a site!)?
Adding or modifying sites requires a (re-)provisioning of the server (ansible-playbook run).

Yep, i’ve provisioned it, and deployed to it several times previously. The site is live.

I’ve also re-provisioned both staging and production, deploys to staging work but not production.

The failing command is logged by ansible:

["wp", "core", "is-installed", "--skip-plugins", "--skip-themes", "--require=/srv/www/squaremilechurches.com/shared/tmp_multisite_constants.php"]

Which would be this raw

wp core is-installed --skip-plugins --skip-themes --require=/srv/www/squaremilechurches.com/shared/tmp_multisite_constants.php

Invoke this command directly on the production server, in the site directory (/srv/www/squaremilechurches.com/current).
What error do you get?

Also you could try to run the deploy command with debug flag (but this can be overwhelming).

Thanks for that, I get no error running that via ssh. It seemingly runs with no output.

If I try and deploy in verbose mode this is my error:
non-zero return code
fatal: [178.62.58.180]: FAILED! => {
“changed”: false,
“cmd”: [
“wp”,
“core”,
“is-installed”,
“–skip-plugins”,
“–skip-themes”,
“–require=/srv/www/squaremilechurches.com/shared/tmp_multisite_constants.php”
],
“delta”: “0:00:00.259695”,
“end”: “2021-06-04 15:36:34.329746”,
“failed_when_result”: true,
“invocation”: {
“module_args”: {
“_raw_params”: “wp core is-installed --skip-plugins --skip-themes --require=/srv/www/squaremilechurches.com/shared/tmp_multisite_constants.php”,
“_uses_shell”: false,
“argv”: null,
“chdir”: “/srv/www/squaremilechurches.com/releases/20210604153609”,
“creates”: null,
“executable”: null,
“removes”: null,
“stdin”: null,
“stdin_add_newline”: true,
“strip_empty_ends”: true,
“warn”: true
}
},
“rc”: 255,
“start”: “2021-06-04 15:36:34.070051”,
“stderr”: “”,
“stderr_lines”: [],
“stdout”: “”,
“stdout_lines”: []
}

Right, is-installed will terminate itself with an exit code that indicates whether it is installed or not.
Invoke that composer command, then use echo $? to print the exit code.

Have just done that:
web@squaremile : /srv/www/squaremilechurches.com/current $ wp core is-installed
web@squaremile : /srv/www/squaremilechurches.com/current $ echo $?
0

Alright, during deploy the current symlink is changed.
Try the composer command again in directory /srv/www/squaremilechurches.com/releases/20210604153609.

The symptoms indicate that WordPress core (roots wordpress package) wasn’t installed by composer, hence the CLI doesn’t deem the core to be installed.

Interesting, now I get an error code:
web@squaremile : /srv/www/squaremilechurches.com/releases/20210604153609 $ wp core is-installed --skip-plugins --skip-themes --require=/srv/www/squaremilechurches.com/shared/tmp_multisite_constants.php

web@squaremile : /srv/www/squaremilechurches.com/releases/20210604153609 $ echo $?

255

Wordpress core must have been installed by composer though, because I provisioned the server when I created it. Any ideas on how to fix this?

Provisioning the server doesn’t install composer core for the sites, this happens during deploy for a particular site.

Inside the directory /srv/www/squaremilechurches.com/releases/20210604153609, run composer install. Does it work, any errors or warnings?

Ahh yeah of course it does.

composer install worked without any errors.

But wp core is-installed --skip-plugins --skip-themes --require=/srv/www/squaremilechurches.com/shared/tmp_multisite_constants.php will still have a non-0 (e.g. 255) exit code?

Yep, still got error 255.

When I ran composer install it didn’t install WP, presumably because it is already installed… Is it worth me trying to to downgrade WP which might force it to install it again?

You can also remove (better rename it!) the web/wp folder from that particular release and re-run composer install. This is where there WordPress core files are.

Downgrading WP to force install didn’t fix it.

I tried renaming the wp folder to wp2 and then running composer install. It installed WP again, but then still returned a 255 message:
web@squaremile : /srv/www/squaremilechurches.com/releases/20210604153609 $ composer install

Installing dependencies from lock file (including require-dev)

Verifying lock file contents can be installed on current platform.

Package operations: 1 install, 0 updates, 0 removals

  • Installing roots/wordpress (5.7.2): Extracting archive

Package asm89/twig-cache-extension is abandoned, you should avoid using it. Use twig/cache-extension instead.

Package container-interop/container-interop is abandoned, you should avoid using it. Use psr/container instead.

Package http-interop/http-server-middleware is abandoned, you should avoid using it. Use psr/http-server-middleware instead.

Generating optimized autoload files

28 packages you are using are looking for funding.

Use the composer fund command to find out more!

Dumping package paths

82 package paths dumped

web@squaremile : /srv/www/squaremilechurches.com/releases/20210604153609 $ wp core is-installed --skip-plugins --skip-themes --require=/srv/www/squaremilechurches.com/shared/tmp_multisite_constants.php

web@squaremile : /srv/www/squaremilechurches.com/releases/20210604153609 $ echo $?

255

Could wp-cli be looking in the wrong place for WP?

The .env file in the release directory is critical for paths, secrets and database configuration.

This seems to be very relevant:



The SO discussion is interesting as the underlying reason was in that case missing, required PHP extensions.

The expected exit codes for is-installed are 0 and 1, 255 is not stated in the documentation:

I’ve figured what caused it to break - although no idea why it only affected staging and production. When I added wp-rocket I added two new env variables in /all/vault.yml. When it broke I removed all the other wp-rocket changes I made, but forgot about the env variables, i’ve just removed these and now it deploys again.

I’ve no idea why it broke the deploy - i’ve added those variables to other projects with no problems. I’ve also no idea why it only broke production…

At least I was able to get my release deployed now, i’ll try adding the variables again next week.

Thanks for your help. I’ll post back when I try to set the .env variables again next week, i’ll either need more help, or this might prove useful for someone else one day.

When I’m working with YAML files I find it’s useful to turn on “show invisible characters” (or whatever the IDE-appropriate setting is). YAML will sometimes produce bizarre results because you, say, used a tab instead of spaces–which you’ll never catch unless you look at what the exact characters are. Running YAML files through a validator can also be helpful.