> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# Laravel Cloud - GitHub Copilot SDK for Laravel

> 介绍在 Laravel Cloud 上运行 Laravel Copilot SDK 所需的 Copilot CLI 安装、环境变量以及 stdio/TCP 模式的运维要点。

## 在 Laravel Cloud 中使用

## 安装

在 **Settings > Deployments > Build commands** 中添加以下内容并部署。

```shell theme={null}
export PATH="$PATH:/var/www/.local/bin"
curl -fsSL https://gh.io/copilot-install | bash
/var/www/.local/bin/copilot --version
```

由于 CLI 的路径是 `/var/www/.local/bin/copilot`，请在 **Custom environment variables** 中设置以下内容。

```dotenv theme={null}
COPILOT_CLI_PATH=/var/www/.local/bin/copilot
COPILOT_GITHUB_TOKEN=
```

`COPILOT_GITHUB_TOKEN` 可以使用 `GH_TOKEN` 或 `GITHUB_TOKEN` 等 Copilot CLI 支持的认证方式。

如果使用默认的 stdio 模式，仅这一步安装就足够了。

## 以 TCP 模式运行

在 **App cluster > Background processes > Custom worker** 中设置 `/var/www/.local/bin/copilot --headless --port 12345`。
它会作为后台进程持续运行，并在部署时自动重启。

端口号可以任意。

在 **Custom environment variables** 中设置 `COPILOT_URL`。

```dotenv theme={null}
COPILOT_URL=tcp://127.0.0.1:12345
# COPILOT_CLI_PATH 在 TCP 模式下不需要。两者都存在时 TCP 模式优先。
```

由于常时运行，内存占用较高，可能需要 2 GiB RAM 或以上的服务器。
在 HTTP 请求内使用时容易在 60 秒内无法完成而失败，因此推荐通过队列执行。

在 Laravel Cloud 上 TCP 模式的实用性并不高，因此推荐 stdio 模式。

上位套餐的 Worker cluster 也可以使用。当你想避免 App cluster 的内存不足时会有帮助。

## 注意事项

* 低价服务器容易内存不足。
* 默认的 HTTP 超时是 20 秒。失败较多时请延长到最多 60 秒。

<Info>
  最新信息请参考 [GitHub 仓库](https://github.com/invokable/laravel-copilot-sdk)。
</Info>


## Related topics

- [GitHub Copilot SDK for Laravel](/zh/packages/laravel-copilot-sdk/index.md)
- [GitHub Actions - GitHub Copilot SDK for Laravel](/zh/packages/laravel-copilot-sdk/github-actions.md)
- [测试 - GitHub Copilot SDK for Laravel](/zh/packages/laravel-copilot-sdk/fake.md)
- [认证 - GitHub Copilot SDK for Laravel](/zh/packages/laravel-copilot-sdk/auth.md)
- [快速开始 - GitHub Copilot SDK for Laravel](/zh/packages/laravel-copilot-sdk/getting-started.md)
