> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.hodi.host/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How do I deploy from my terminal with the Hodifly CLI?

The Hodifly command line deploys your sites from your own terminal, from a script, or from your CI. It does everything the Hodifly page in cPanel does: create a project, deploy, roll back, read build logs.

It is one file with no dependencies. You need Node 18 or newer, and it runs on macOS, Linux and Windows.

## Install it

Use whichever package manager you already have:

- `pnpm add -g hodifly`
- `npm i -g hodifly`
- `yarn global add hodifly`

## Sign in

In cPanel, open **Hodifly** and click **API**. Press **Create an API token** and you are given a complete command to paste:

```
hodifly login --host server.example.com --user myaccount --token ...
```

That saves your credentials in `~/.hodifly/config.json`, readable only by you. You only do this once per hosting account.

The token is an ordinary cPanel API token. cPanel only issues full-access tokens, so it can do anything you can do in cPanel: keep it to yourself, and remove it under **Manage API Tokens** when you no longer need it.

If you would rather not paste a token on the command line, run `hodifly login` with no options and it will ask for the three values, without showing the token as you type.

## Everyday commands

| Command | What it does |
| ---- |
| `hodifly projects` | Your projects, and how the last build went |
| `hodifly deploy my-site` | Build and publish the current head of the branch |
| `hodifly ls my-site --prod` | The deployments you can roll back to |
| `hodifly rollback my-site <deployment>` | Point the site back at an earlier build |
| `hodifly logs my-site` | Build output, newest deployment by default |
| `hodifly remove my-site` | Delete the project (the files on disk are kept) |

A deployment is one build. `hodifly ls` gives you their ids, and a rollback takes one of them:

```
hodifly ls my-site --prod
hodifly rollback my-site 812308420affa006
```

A rollback is instant. The release is already on the server, so nothing is rebuilt.

## Create a project

```
hodifly projects add \
  --repo my-org/my-site \
  --domain example.com \
  --build-command "npm run build" \
  --output-directory dist
```

The repository has to be one you have already connected under **Manage GitHub** in the Hodifly page. Run `hodifly --help` to see every option.

If `--domain` names a subdomain of your main domain that does not exist yet, it is created for you before the first build, so there is no need to add it in cPanel first:

```
hodifly projects add --repo my-org/blog --domain blog.example.com
```

That applies to subdomains of your main domain only. Any other domain has to be registered and pointed at the server, so add it in cPanel > Domains first and then run the command.

## Change a setting on a project

`projects set` edits a project you already have, without opening cPanel:

```
hodifly projects set my-api --startup dist/main.js
hodifly projects set my-site --build-command "npm run build"
hodifly projects set my-site --branch production
```

It is a patch: only what you name changes, everything else stays as it is. Give a switch a value to turn it off (`--previews 0`), and an empty value to clear a field (`--build-command ""`). Nothing is rebuilt, so follow it with `hodifly deploy my-site` when the change should take effect now.

It takes the same options as `projects add`, plus `--autodeploy`, `--notify-success`, `--notify-failed`, `--notify-email` and `--persist`. What it will not change is what belongs to the hosting account rather than to the project: the domain, the folder on the account and the repository itself. Move a project to another domain by creating a second project.

Needs version 1.1 or newer: `npm i -g hodifly` to update, `hodifly --version` to check.

## If you have sites on more than one server

Each hosting account lives on its own server, so sign in to each one. Hodifly remembers which projects and domains belong to which account, and works out the rest from the name you type:

```
hodifly deploy blog.example.com
```

That finds the account, the server and the project on that domain. If a name exists on two of your accounts, Hodifly tells you rather than guessing, and you add `--profile`:

```
hodifly deploy my-site --profile work
```

| Command | What it does |
| ---- |
| `hodifly profiles` | The accounts you are signed in to |
| `hodifly use work` | Choose the default account |
| `hodifly refresh` | Re-read what each account has |
| `hodifly logout work` | Forget an account on this machine |

## In a script or in CI

Add `--json` to any command to get the raw response instead of a table. Credentials can come from the environment instead of the saved file, which is what you want on a build server:

```
export HODIFLY_HOST=server.example.com
export HODIFLY_USER=myaccount
export HODIFLY_TOKEN=...
hodifly deploy my-site --json
```

Keep the token in your CI provider's secret store, never in the repository.

## If something does not work

| Message | What to do |
| ---- |
| `could not reach ...` | The API is on port 2083. Some office and airport networks block it. |
| `the server rejected your credentials` | The token was removed, or the username is wrong. Create a new one from the API page and run `hodifly login` again. |
| `exists on more than one of your accounts` | Add `--profile` and the account name, as above. |
