Use WP-CLI remotely over SSH on web host Strato

Strato half-secretly has decent SSH access even for its cheap plans, but it comes with quirks. To use WP-CLI comfortably,  I jumped through these hoops:

  1. I recommend we set up key-based, password-less login
    # or
    mkdir -m 700 ~/.ssh
    touch ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys
    vim ~/.ssh/authorized_keys # paste your ~/.ssh/ here
  2. I recommend we create an SSH alias
    # local ~/.ssh/config
    Host strato
    ServerAliveInterval 30
  3. Install remote wp-cli (make sure we have it locally, too)
    ssh strato
    mkdir bin && cd bin
    # check for up-to-date command!!
    #curl -O
  4. Create the “wp” alias on the remote machine
    Find php-cli
    /usr/bin/php -v
    # PHP 7.2.17 (cgi-fcgi) # wrong!
    /opt/RZphp72/bin/php-cli -v
    # PHP 7.2.17 (cli) # here we go!

    Check the remote’s default shell & $HOME
    echo $SHELL
    # /bin/tcsh in my case!
    echo $HOME
    # /mnt/webr/01/23/456789ab/htdocs

    Set up the alias
    alias wp /opt/RZphp72/bin/php-cli /mnt/webr/01/23/456789ab/htdocs/bin/wp-cli.phar
    set path = ($path /usr/local/bin $HOME/bin .) # can be handy!
    alias wp='/opt/RZphp72/bin/php-cli /mnt/webr/01/23/456789ab/htdocs/bin/wp-cli.phar'
    PATH=${PATH}:${HOME}/bin # can be handy!
  5. I recommend we set up a local WP-CLI alias:
    ssh: strato/mnt/webr/01/23/456789ab/htdocs/path-to-your-wp
  6. Test!
    wp @strato
    wp @strato --info
    wp @strato post list
    # go back? debug?
    wp --ssh=strato/mnt/…
    ssh strato wp
    ssh strato /opt/RZphp72/bin/php-cli /mnt/webr/01/23/456789ab/htdocs/bin/wp-cli.phar