Run WP-CLI command on Uberspace from local Server

I wanted to run a WP-CLI command from GitLab CI (local server) on one of my Uberspaces. Since version 0.24.0, the WP-CLI provides the --ssh argument, which lets us do exactly that. It should be easy, but I come across one small problem.

The usage of the --ssh looks like that (parser is no default WP-CLI command but comes from the phpdoc-parser):

wp parser create wp-content/themes-for-docblock-parser/ --user=florian --allow-root

The --allow-root is only necessary if the command is run by a root user (which is the case on GitLab CI). At first, there come the common command arguments, and at the end with --ssh the remote server and path, where the command should be run. Of course, you need to make sure the SSH connection works — you can find an example for the GitLab CI in my post »Auto deployment to staging and production server with GitLab CI«.

One more requirement is that you have WP-CLI installed on both servers and that it is reachable via the wp command. And here comes the problem: The CLI was installed on both servers, but after running the command from above on the CI I get:

bash: wp: command not found

I had no idea why, but got help from Bernhard and Alain. The problem is that the Uberspace does not set a PATH variable for the CLI script if there is a connection via the WP-CLI --ssh, so the script can only be run in the directory it lives. The solution (likely only one of many) on Uberspace is the following line at the end of ~/.bashrc:

export PATH=$PATH:$HOME/bin

Of course, you need to modify the path to the directory you have installed the WP-CLI in.

Related posts

Leave a Comment

Your email address will not be published. Required fields are marked *