Fixing Cloudway’s WP-Salt + WP-CLI Conflict

I discovered Cloudways hosting after seeing a client host a number of sites there, and enjoy the flexibility of their managed system as well as an extensive API to interact with and speed up both our StagingPilot integration as well as hosting a handful of my own sites.

One interesting quirk I’ve discovered is, they “offload” wp-config’s keys and salt constants to a separate file, wp-salt.php. This is fine, except that the require()statement in wp-config.php causes WP-CLI to throw a fatal error when run in any directory other than public_html/. Adding the directory magic constant __DIR__ to the file path (assuming you’re running PHP 5.3.0+ which… you truly have no excuse not to be) allows wp-config to read that salt file when called from anywhere, giving you free reign to work with WP-CLI wherever you need.

The following sed command will do the trick in one line.

sed -i "s|require('wp-salt.php')|require(__DIR__.'/wp-salt.php')|g" wp-config.php

Leave a comment

Your email address will not be published.