"Unable to run PHP in command line mode" error when running remote MODX upgrade
When running a remote MODX upgrade, you may encounter one of these errors:
- Unable to run PHP in command line mode, `php --version` returned version number "5.5.2" which is either invalid or below the minimum required to install MODX.
- Unable to run PHP in command line mode, `php --version` did not return valid output.
These are part of the pre-installation checks to make sure your server can execute PHP code in command line (CLI) mode. This is necessary as the final step of the remote upgrade is to run the MODX setup in said command line mode.
Both errors are caused by (invalid) configuration on the server, although the specific cause and fix for them are slightly different.
Invalid or too low PHP version
If this error does provide a PHP version number, it means SiteDash was successfully able to instruct your server to run PHP code in CLI mode, however the installed command line version of PHP is too low to continue.
This can happen if the PHP version for your front-end webserver is different from the one on the command line, and the latter hasn't been updated in a while. As MODX 2.x requires at least PHP 5.6 to run the installation successfully, we check the command line version of PHP before continuing with the setup.
To resolve this, we recommend talking to your host or server administrator. Mosts hosts are happy to resolve this, and in some cases we've also seen server control panels offer you the ability to change the "global" PHP version through a PHP version selector, which typically affects the command line version as well.
If the error message does not provide a PHP version number in the quotes, you've run into an edge case we didn't think was possible. Please get in touch with support, providing your site's domain name and/or site key so we can investigate further.
Did not return valid output
If the PHP version check did not return valid output, that means something else is afoot. Where we've seen this, typically the attempt to run PHP in command line mode is being interpreted by the server as a web request. That breaks the version check and will also prevent the setup from completing.
One reason this seems to happen is if the server is configured with PHP-FPM and "cgi-fcgi" for the webserver, and requires a different executable to be used on the command line. SiteDash will automatically identify the used executable for the web request and fail to recognise there's a different CLI version.
Note that this does not affect all PHP-FPM setups; remotely upgrading MODX on servers running nginx and PHP-FPM works fine for the vast majority of our users. The exact server configuration that causes this problem is, as of yet, unknown to us. The German hosting company Variomedia seems to be a common name that comes up in relation to this issue (and they offer some guidance here), though our sample size isn't big enough to definitely point in their direction and other hosting companies may use similar configurations.
To resolve this problem, you'll need to manually tell SiteDash the PHP executable to use.
Aside from asking the host or server administrator what the right PHP executable is, you can find out yourself in most cases by connecting to your server over SSH. If you get the expected version from running `
php --version`, run `
which php` and use the path provided.
Go to System > System Settings in your site, and search for sitedashclient.php_binary. Set its value to the full absolute path, including binary name, of the PHP executable that should be used. For example something like "/usr/local/bin/php74".