<p>You need to execute the command inside the proeject root. The <code>craft</code> executable isn't available in your <code>$PATH</code> since it's not a globally installed tool, but just a <a href="https://github.com/craftcms/craft/blob/main/craft" rel="nofollow noreferrer">PHP file that's located in the project root</a>.</p>
<p>Those two commands are just two ways to call this executable:</p>
<ul>
<li><code>php craft</code> runs the <code>craft</code> file with PHP (the version that's linked on the CLI). The <code>craft</code> in this command in just a relative file path in this case.</li>
<li><code>./craft</code> executes the <code>craft</code> binary directly, the OS knows to execute it with PHP due to the <a href="https://github.com/craftcms/craft/blob/main/craft#L1" rel="nofollow noreferrer">shebang</a>. The <code>./craft</code> is a relative path to the file.</li>
</ul>
<p>Due to the way those commands work, they will only function correctly when executed in the project root.</p>
<p>Github actions are executed in the project root by default, but the SSH connection will go to the home directory of the user you're connecting to. This probably isn't the project root, so you either need to use absolute paths or change the working directory as the first command in your action:</p>
<pre class="lang-bash prettyprint-override"><code>cd /path/to/project/root
</code></pre>
<p>Put this command as the first part of your <code>script</code>, then it should work correctly.</p>

CC BY-SA 4.0
2022-02-07T15:04:58.987Z
Nice. In that case I just use `cd ${{ secrets.SERVER_LIVE_PATH }}`.
Thank you
KSPR
CC BY-SA 4.0
2022-02-07T14:25:48.060Z
2022-02-07T14:25:48.060Z
MoritzLost
<p>This is how I want to trigger certain actions with the craft terminal.</p>
<p>It does not work:</p>
<pre><code># execute Craft commands on remote server
  - name: Execute SSH Craft Commands on remote server
    uses: appleboy/ssh-action@master
    with:
      host: ${{ secrets.SSH_HOST }}
      username: ${{ secrets.SSH_USER }}
      key: ${{ secrets.SSH_KEY }}
      script: |
        ./craft project-config/apply
      
</code></pre>
<blockquote>
<p>err: bash: ./craft: No such file or directory</p>
</blockquote>
<p>If I try</p>
<pre><code>craft project-config/apply
</code></pre>
<p>or (as written in some tutorials)</p>
<pre><code>php craft project-config/apply
</code></pre>
<p>I get:</p>
<blockquote>
<p>out: Could not open input file: craft</p>
</blockquote>
<p>What's the correct syntax here? If I do <code>./craft</code> manually on the server it works just fine.</p>

<deployment>
How to use Craft commands in Github Actions
# How to use Craft commands in Github Actions

(Asked by: username_0 on 2022-02-07)

This is how I want to trigger certain actions with the craft terminal.
It does not work:
# execute Craft commands on remote server
  - name: Execute SSH Craft Commands on remote server
    uses: appleboy/ssh-action@master
    with:
      host: ${{ secrets.SSH_HOST }}
      username: ${{ secrets.SSH_USER }}
      key: ${{ secrets.SSH_KEY }}
      script: |
        ./craft project-config/apply
      


err: bash: ./craft: No such file or directory

If I try
craft project-config/apply

or (as written in some tutorials)
php craft project-config/apply

I get:

out: Could not open input file: craft

What's the correct syntax here? If I do ./craft manually on the server it works just fine.

**Tags:** deployment


---

## 1 answers

### Answer by username_1 on 2022-02-07. Score: 1 | Accepted answer

You need to execute the command inside the proeject root. The craft executable isn't available in your $PATH since it's not a globally installed tool, but just a PHP file that's located in the project root.
Those two commands are just two ways to call this executable:

php craft runs the craft file with PHP (the version that's linked on the CLI). The craft in this command in just a relative file path in this case.
./craft executes the craft binary directly, the OS knows to execute it with PHP due to the shebang. The ./craft is a relative path to the file.

Due to the way those commands work, they will only function correctly when executed in the project root.
Github actions are executed in the project root by default, but the SSH connection will go to the home directory of the user you're connecting to. This probably isn't the project root, so you either need to use absolute paths or change the working directory as the first command in your action:
cd /path/to/project/root

Put this command as the first part of your script, then it should work correctly.

> **Comments:**
> **username_0**: Nice. In that case I just use `cd ${{ secrets.SERVER_LIVE_PATH }}`. Thank you  

---

