Skip to content

WP-CLI with custom path and ssh connection #5219

Description

@PomzedCommunication

Hello,

I need to define $PATH variable with a custom path, because my server is shared and my wp-cli installation is not on default dir.

I used this function but it doesn't works for me:
https://danielbachhuber.com/tip/wp-ssh-custom-path/

I put pre-ssh.php on my Bedrock (https://roots.io/bedrock/) project root and I require it in my wp-cli.yml file.

./wp-config.yml

require:
  - scripts/pre-ssh.php
@staging:
  ssh: [email protected]
  path: path/to/my/uploads/web/app/uploads/

./scripts/pre-ssh.php

WP_CLI::add_hook( 'before_ssh', function() {
    $host = WP_CLI\Utils\parse_ssh_url( WP_CLI::get_runner()->config['ssh'], PHP_URL_HOST );
    switch( $host ) {
        case 'mydomain.ch':
            putenv( 'WP_CLI_SSH_PRE_CMD=export PATH=/path/to/my/wpcli/installation/bin:$PATH' );
            break;
    }
});

When I execute wp @staging from my client he say me /bin/bash: wp: command not found.

But wp works on my server (I configure .bashrc file for define my $PATH variable).

I tried other solutions finded here: https://make.wordpress.org/cli/handbook/running-commands-remotely/#making-wp-cli-accessible-on-a-remote-server
but doesn't work either.

What did I wrong ?

Could you help me ?

I remain available for any further informations.

Activity

  1. ehausen commented on May 24, 2019

    @ehausen

    Any luck?

    I also get bash: wp: command not found when trying to run wp --ssh=... to a remote, even though wp command works when I log in with ssh manually.

    I also have to have wp-cli in non-standard location and use an alias to get the wp command working

  2. danielbachhuber commented on Nov 10, 2022

    @danielbachhuber
    Member

    @PomzedCommunication @ehausen Were either of you able to sort this out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions