Roots Discourse

WP Rocket failed deploy production

I get through below instruction

and it caused error on deploy production

TASK [deploy : WordPress Installed?] *******************************************
System info:
  Ansible 2.10.12; Darwin
  Trellis 1.8.0: February 12th, 2021
---------------------------------------------------
non-zero return code
fatal: [IP]: FAILED! => {"changed": false, "cmd": ["wp", "core", "is-installed", "--skip-plugins", "--skip-themes", "--require=/srv/www/my_url/shared/tmp_multisite_constants.php"], "delta": "0:00:00.388019", "end": "2021-08-09 18:49:20.760810", "failed_when_result": true, "rc": 255, "start": "2021-08-09 18:49:20.372791", "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": []}

PLAY RECAP *********************************************************************
IP             : 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

I’ve had similar issues with setting constants in Bedrock’s config/application.php – are you using the plain define()-method or Config::define()? The latter has caused issues for me with certain constants and resulted in the exact same error…

Please share your config/application.php and/or config/environments/xyz.php

my production.php looks exactly as they’ve suggested, which is

<?php
if ( env( 'WP_ROCKET_KEY' ) ) {
define( 'WP_ROCKET_KEY', env( 'WP_ROCKET_KEY' ) );
}
// Your email, the one you used for the purchase.
if ( env( 'WP_ROCKET_EMAIL' ) ) {
define( 'WP_ROCKET_EMAIL', env( 'WP_ROCKET_EMAIL' ) );
}
define('WP_CACHE', true);

application.php like

<?php
/**
 * Your base production configuration goes in this file. Environment-specific
 * overrides go in their respective config/environments/{{WP_ENV}}.php file.
 *
 * A good default policy is to deviate from the production config as little as
 * possible. Try to define as much of your configuration in this file as you
 * can.
 */

use Roots\WPConfig\Config;
use function Env\env;

/**
 * Directory containing all of the site's files
 *
 * @var string
 */
$root_dir = dirname(__DIR__);

/**
 * Document Root
 *
 * @var string
 */
$webroot_dir = $root_dir . '/web';

/**
 * Use Dotenv to set required environment variables and load .env file in root
 * .env.local will override .env if it exists
 */
$env_files = file_exists($root_dir . '/.env.local')
    ? ['.env', '.env.local']
    : ['.env'];

$dotenv = Dotenv\Dotenv::createUnsafeImmutable($root_dir, $env_files, false);
if (file_exists($root_dir . '/.env')) {
    $dotenv->load();
    $dotenv->required(['WP_HOME', 'WP_SITEURL']);
    if (!env('DATABASE_URL')) {
        $dotenv->required(['DB_NAME', 'DB_USER', 'DB_PASSWORD']);
    }
}

/**
 * Set up our global environment constant and load its config first
 * Default: production
 */
define('WP_ENV', env('WP_ENV') ?: 'production');

/**
 * URLs
 */
Config::define('WP_HOME', env('WP_HOME'));
Config::define('WP_SITEURL', env('WP_SITEURL'));

/**
 * Custom Content Directory
 */
Config::define('CONTENT_DIR', '/app');
Config::define('WP_CONTENT_DIR', $webroot_dir . Config::get('CONTENT_DIR'));
Config::define('WP_CONTENT_URL', Config::get('WP_HOME') . Config::get('CONTENT_DIR'));

/**
 * DB settings
 */
Config::define('DB_NAME', env('DB_NAME'));
Config::define('DB_USER', env('DB_USER'));
Config::define('DB_PASSWORD', env('DB_PASSWORD'));
Config::define('DB_HOST', env('DB_HOST') ?: 'localhost');
Config::define('DB_CHARSET', 'utf8mb4');
Config::define('DB_COLLATE', '');
$table_prefix = env('DB_PREFIX') ?: 'wp_';

if (env('DATABASE_URL')) {
    $dsn = (object) parse_url(env('DATABASE_URL'));

    Config::define('DB_NAME', substr($dsn->path, 1));
    Config::define('DB_USER', $dsn->user);
    Config::define('DB_PASSWORD', isset($dsn->pass) ? $dsn->pass : null);
    Config::define('DB_HOST', isset($dsn->port) ? "{$dsn->host}:{$dsn->port}" : $dsn->host);
}

/**
 * Authentication Unique Keys and Salts
 */
Config::define('AUTH_KEY', env('AUTH_KEY'));
Config::define('SECURE_AUTH_KEY', env('SECURE_AUTH_KEY'));
Config::define('LOGGED_IN_KEY', env('LOGGED_IN_KEY'));
Config::define('NONCE_KEY', env('NONCE_KEY'));
Config::define('AUTH_SALT', env('AUTH_SALT'));
Config::define('SECURE_AUTH_SALT', env('SECURE_AUTH_SALT'));
Config::define('LOGGED_IN_SALT', env('LOGGED_IN_SALT'));
Config::define('NONCE_SALT', env('NONCE_SALT'));

/**
 * Custom Settings
 */
Config::define('AUTOMATIC_UPDATER_DISABLED', true);
Config::define('DISABLE_WP_CRON', env('DISABLE_WP_CRON') ?: false);
// Disable the plugin and theme file editor in the admin
Config::define('DISALLOW_FILE_EDIT', true);
// Disable plugin and theme updates and installation from the admin
Config::define('DISALLOW_FILE_MODS', true);
// Limit the number of post revisions that Wordpress stores (true (default WP): store every revision)
Config::define('WP_POST_REVISIONS', env('WP_POST_REVISIONS') ?: true);

/**
 * Debugging Settings
 */
Config::define('WP_DEBUG_DISPLAY', false);
Config::define('WP_DEBUG_LOG', false);
Config::define('SCRIPT_DEBUG', false);
ini_set('display_errors', '0');

/**
 * Allow WordPress to detect HTTPS when used behind a reverse proxy or a load balancer
 * See https://codex.wordpress.org/Function_Reference/is_ssl#Notes
 */
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $_SERVER['HTTPS'] = 'on';
}

$env_config = __DIR__ . '/environments/' . WP_ENV . '.php';

if (file_exists($env_config)) {
    require_once $env_config;
}

Config::apply();

/**
 * Bootstrap WordPress
 */
if (!defined('ABSPATH')) {
    define('ABSPATH', $webroot_dir . '/wp/');
}

and production/vault.yml

db_password: generatedpwdontusethis
wp_rocket_key: {insert_wp_rocket_key_here}
wp_rocket_email: {insert_wp_rocket_email_here}

OK, that all looks fine from here… application.php hasn’t been modified at all, so let’s disregard that.

  • Did you re-provision the remote server?
  • And the error definitely goes away when commenting / removing the production.php?

yes, I re-proviosed remote server
The problem only get away when I’ve removed everything from the instruction inc. composer update when I took out require value from composer.json

A non-zero exit code for that WP CLI command can indicate that WordPress core is not installed for that site yet (on that Trellis server). But it can also be caused by an internal server (PHP) error.

Invoke the WP CLI command manually (on your workstation):

wp @production core is-installed --skip-plugins --skip-themes --require=/srv/www/my_url/shared/tmp_multisite_constants.php

I assume that you have WP CLI installed and set up for that site and server (production alias).
You can then see what exactly caused the non-zero exit code.

Alternatively you can run the ansible provisioning again, but with higher verbosity (-v or more v) to see the output of the command.

Also check the PHP error logs when the WP CLI is used (either by ansible or manually as suggested).

I have found similar issue here https://github.com/roots/trellis/issues/1025 I tried to comment two lines at roles/deploy/files/tmp_multisite_constants.php reprovision development, committed changes to repository and then reprovision and deploy production.

It did not solve the problem :frowning: Any idea what could I try next?

Have you checked what the wp @production core is-installed command above returns as the reason?
The exit code alone is non-zero, but it doesn’t convey the reason for why it failed.

OK, @lukasz-gorski helped me to fix this problem.

SOLUTION:
do not create this file
/site/config/environments/production.php

instead add

if ( env( 'WP_ROCKET_KEY' ) ) {
define( 'WP_ROCKET_KEY', env( 'WP_ROCKET_KEY' ) );
}
// Your email, the one you used for the purchase.
if ( env( 'WP_ROCKET_EMAIL' ) ) {
define( 'WP_ROCKET_EMAIL', env( 'WP_ROCKET_EMAIL' ) );
}
define('WP_CACHE', true);

to the bottom of /site/config/application.php

then add

wp_rocket_key: {insert_wp_rocket_key_here}
wp_rocket_email: {insert_wp_rocket_email_here}

to group_vars/all/vault.yml

this will allow you to deploy production with wp-rocket

1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.