{"id":3587,"date":"2017-05-26T12:47:00","date_gmt":"2017-05-26T10:47:00","guid":{"rendered":"https:\/\/florianbrinkmann.com\/en\/?p=3587"},"modified":"2020-02-09T10:59:50","modified_gmt":"2020-02-09T09:59:50","slug":"run-wp-cli-command-on-uberspace-from-local-server","status":"publish","type":"post","link":"https:\/\/florianbrinkmann.com\/en\/run-wp-cli-command-on-uberspace-from-local-server-3587\/","title":{"rendered":"Run WP-CLI command on Uberspace from local Server"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I wanted to run a WP-CLI command from GitLab CI (local server) on one of my Uberspaces. Since <a href=\"https:\/\/make.wordpress.org\/cli\/2016\/07\/27\/version-0-24-0\/\">version 0.24.0<\/a>, the WP-CLI provides the <code class=\"lang-bash\">--ssh<\/code> argument, which lets us do exactly that. It should be easy, but I come across one small problem.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">The usage of the <code class=\"lang-bash\">--ssh<\/code> looks like that (<code class=\"lang-bash\">parser<\/code> is no default WP-CLI command but comes from the <a href=\"https:\/\/github.com\/WordPress\/phpdoc-parser\">phpdoc-parser<\/a>):<\/p>\n\n\n<pre class=\"wp-block-code lang-bash\"><span><code class=\"hljs\">wp parser create wp-content\/themes-for-docblock-parser\/ --user=florian --url=example.com --allow-root --ssh=user@example.com\/path\/to\/wp\/install\/<\/code><\/span><\/pre>\n\n\n<p class=\"wp-block-paragraph\">The <code class=\"lang-bash\">--allow-root<\/code> 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 <code class=\"lang-bash\">--ssh<\/code> the remote server and path, where the command should be run. Of course, you need to make sure the SSH connection works \u2014 you can find an example for the GitLab CI in my post \u00bb<a href=\"https:\/\/florianbrinkmann.com\/en\/3473\/deployment-gitlab-ci\/\">Auto deployment to staging and production server with GitLab CI<\/a>\u00ab.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One more requirement is that you have WP-CLI installed on both servers and that it is reachable via the <code class=\"lang-bash\">wp<\/code> 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:<\/p>\n\n\n<pre class=\"wp-block-code lang-bash\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTTP\" data-shcb-language-slug=\"http\"><span><code class=\"hljs language-http\"><span class=\"hljs-attribute\">bash<\/span>: wp: command not found<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTTP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">http<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">I had no idea why, but got help from <a href=\"https:\/\/twitter.com\/2ndKauBoy\">Bernhard<\/a> and <a href=\"https:\/\/twitter.com\/schlessera\">Alain<\/a>. 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 <code class=\"lang-bash\">~\/.bashrc<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code lang-bash\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">export PATH=$PATH:$HOME\/bin<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">Of course, you need to modify the path to the directory you have installed the WP-CLI in.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"wpf_show_in_dewp_planet_feed":false,"flobn_post_versions":"","webmentions_disabled_pings":false,"webmentions_disabled":false,"lazy_load_responsive_images_disabled":false,"footnotes":""},"categories":[3,37],"tags":[],"class_list":["post-3587","post","type-post","status-publish","format-standard","hentry","category-tips","category-wordpress"],"wp-worthy-pixel":{"ignored":false,"public":null,"server":null,"url":null},"wp-worthy-type":"normal","_links":{"self":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/comments?post=3587"}],"version-history":[{"count":3,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3587\/revisions"}],"predecessor-version":[{"id":5886,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/posts\/3587\/revisions\/5886"}],"wp:attachment":[{"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/media?parent=3587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/categories?post=3587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/florianbrinkmann.com\/en\/wp-json\/wp\/v2\/tags?post=3587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}