deploy-to-hosting
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDeploy to hosting
部署到托管服务
Ship a project that already exists — on disk or in a Git repository — to a Hostinger website. Building a new site from a prompt (design, store, blog) is the skill; this one takes code as it is.
hostinger-headless将已经存在的项目——位于磁盘上或 Git 仓库中——发布到 Hostinger 网站。通过提示词(设计、商店、博客)构建新网站应使用 skill;本 skill 直接使用现有代码。
hostinger-headlessCalling the operations
调用操作
- Read the that
inputSchemareturns before the first call of each operation. If a name below is rejected as unknown,searchfor what the step does (e.g. "deploy static").search - Batch reads with ; values pass between steps as
multi-execute. Batches chain operations from one server only — the Hostinger Connector runs$steps.<i>.<path>,hostingandwordpressas separate servers.agency-hosting - Every deploy overwrites the website's current contents. Confirm the target domain with the user before the first deploy to a site that already has content.
- 在首次调用每个操作前,读取 返回的
search。如果下述名称被判定为未知,请使用inputSchema搜索该步骤的功能(例如 "deploy static")。search - 使用 批量读取;值通过
multi-execute在步骤之间传递。一个批次只能串联来自同一服务器的操作——Hostinger Connector 将$steps.<i>.<path>、hosting和wordpress作为独立服务器运行。agency-hosting - 每次部署都会覆盖网站当前的内容。首次部署到已有内容的网站前,必须向用户确认目标域名。
1. Pick the target website
1. 选择目标网站
- in the project: reuse its
.hostinger/site.jsonanddomain(orusername).website_uid - Otherwise look the domain up with (Shared and Cloud; substring match — take the exact entry) and
hosting_websites_list(Agency; keepagency-hosting_websites_list-plan).details.uid - No website yet:
- Shared and Cloud: take a domain (the user's own, or ) and an
hosting_domains_generate-free-subdomainfromorder_id, thenhosting_orders_list.hosting_websites_createis needed only for the first website on a new plan (first entry ofdatacenter_code). Pollhosting_datacenters_listwithhosting_websites_list-setupsevery 10–15 s untildomain— uploads and deploys return 404 or 409 before that.status: completed - Agency: with
agency-hosting_website-setups_create(plusflavor: "php-fpm"for built frontends),type: "node-static"fromsettings.php.versionandagency-hosting_php_list-versions-for-orderfromdatacenter_code. Pollagency-hosting_datacenters_listuntilagency-hosting_website-setups_status; it returns thecompleted.website_uid
- Shared and Cloud: take a domain (the user's own, or
- Node.js apps run on Business and Cloud plans (,
hostinger_business_*incloud_*). On other plans, build locally and deploy the output as a static site.hosting_orders_list
- 项目中的 :复用其中的
.hostinger/site.json和domain(或username)。website_uid - 否则,使用 (Shared 和 Cloud;子字符串匹配——选择完全匹配的条目)以及
hosting_websites_list(Agency;保留agency-hosting_websites_list-plan)查找域名。details.uid - 尚无网站:
- Shared 和 Cloud:从 获取一个域名(用户自有域名,或通过
hosting_orders_list生成)和一个hosting_domains_generate-free-subdomain,然后调用order_id。仅当新套餐中的首个网站需要hosting_websites_create(即datacenter_code的第一项)。使用hosting_datacenters_list每 10–15 秒轮询domain,直至hosting_websites_list-setups——在此之前,上传和部署操作会返回 404 或 409。status: completed - Agency:调用 并设置
agency-hosting_website-setups_create(对于已构建的前端项目,还需设置flavor: "php-fpm"),type: "node-static"取自settings.php.version,agency-hosting_php_list-versions-for-order取自datacenter_code。轮询agency-hosting_datacenters_list直至agency-hosting_website-setups_status;它会返回completed。website_uid
- Shared 和 Cloud:从
- Node.js 应用仅在 Business 和 Cloud 套餐上运行(在 中为
hosting_orders_list、hosting_business_*)。在其他套餐上,请在本地构建并将产物作为静态站点部署。cloud_*
2. Choose the deploy
2. 选择部署方式
Shared and Cloud, on the local server: one operation does every deploy — with and either (a directory on this machine) or . Given a directory it detects what the project is, packs it itself (it skips , and files, listing the ones as so you can set their values with ; it does not read , so keep build output out of the directory) and does the upload, build and Git setup. Do not archive the directory or call upload and build operations by hand.
hostinger-api-mcphosting_deploydomainpathgit: { repository: "owner/name", branch }node_modules.git.env.envskippedFileshosting_nodejs_replace-environment-variables.gitignore| Project | |
|---|---|
| Plain HTML/CSS/JS, or a framework's static build output | |
| |
| PHP code, no build step | |
WordPress plugin folder (a | |
| A whole WordPress site from elsewhere | |
- Pass to override detection. It is required for an archive (an archive cannot be inspected) and when a directory matches more than one WordPress type, which
typerejects as ambiguous.hosting_deploy - Node.js build settings come from the project; detection covers the framework and the build script. Set ,
appType,outputDirectory,buildScript,entryFile(default 22),nodeVersionorrootDirectorywhen it is wrong. A TypeScript or other compiled server app always needspackageManagerset to the built file (for exampleentryFile): detection only guesses a root-level file, and the build fails with "Entry file not found". The entry file is relative to the root directory for express, fastify, hono, react-router and other, and to the output directory for nest, nuxt, nitro, astro and svelte-kit (dist/server.js, notmain.js); Next.js ignores it. Per-framework values are in the Hostinger docs under Node.js (Supported Frameworks, Build Settings).dist/main.js - Static, PHP, plugin and theme deploys are live when the call returns. A WordPress site import only starts () and finishes extracting a few minutes later; do not report it complete or verify it before then. Node.js builds run on the server: see step 3.
status: import_started
Agency: the website's type decides (): sites created as take , which runs the build when the project has one; every other site takes , which extracts the archive as-is. They deploy archives, synchronously: the site is live when the call returns. WordPress plugins and themes on Agency sites are installed from wp-admin.
agency-hosting_websites_getnode-staticagency-hosting_deploy-node-static-websiteagency-hosting_deploy-php-applicationArchive rules for Agency (name archives ) and for archives you build yourself:
name_YYYYMMDD_HHMMSS.zip- Static: build locally first. must be at the archive root, not inside a folder:
index.htmlcd dist && zip -r ../site_20260101_120000.zip . - Node.js source: no , no build output (
node_modules/,dist/,.next/), nobuild/, nothing matched by.env*; 50 MB at most..gitignoreproduces exactly the committed files — mention that uncommitted changes are left out.git archive --format=zip -o app_20260101_120000.zip HEAD
hosting_deployagency-hosting_deploy-*mcp.hostinger.comsearchShared 和 Cloud,在本地 服务器上: 一个操作即可完成所有部署——,传入 ,以及 (本机上的目录)或 。给定目录后,它会检测项目类型、自行打包(跳过 、 和 文件,并将跳过的 文件列为 ,以便通过 设置其值;它不会读取 ,因此请确保目录中不包含构建产物),然后完成上传、构建和 Git 设置。不要手动压缩目录,也不要分别调用上传和构建操作。
hostinger-api-mcphosting_deploydomainpathgit: { repository: "owner/name", branch }node_modules.git.env.envskippedFileshosting_nodejs_replace-environment-variables.gitignore| 项目 | |
|---|---|
| 普通 HTML/CSS/JS,或框架的静态构建输出 | |
包含构建脚本、启动脚本或服务器依赖项的 | |
| 无构建步骤的 PHP 代码 | |
WordPress 插件目录(包含 | |
| 从其他地方迁移的完整 WordPress 站点 | |
- 传入 可以覆盖检测结果。对于压缩包(无法检查其内容),以及一个目录同时匹配多种 WordPress 类型的情况,必须传入
type;后一种情况会被type判定为歧义并拒绝。hosting_deploy - Node.js 构建设置来自项目;检测范围涵盖框架和构建脚本。检测结果不正确时,请设置 、
appType、outputDirectory、buildScript、entryFile(默认 22)、nodeVersion或rootDirectory。TypeScript 或其他编译型服务器应用始终需要将packageManager设置为构建后的文件(例如entryFile):检测只会猜测根目录下的文件,且构建会因 "Entry file not found" 而失败。对于 express、fastify、hono、react-router 等,入口文件相对于根目录;对于 nest、nuxt、nitro、astro 和 svelte-kit,则相对于输出目录(dist/server.js,而不是main.js);Next.js 会忽略该设置。各框架对应的值位于 Hostinger 文档的 Node.js(Supported Frameworks、Build Settings)章节中。dist/main.js - 静态、PHP、插件和主题部署在调用返回时即已上线。WordPress 站点导入只会启动(),并在几分钟后完成解压;在此之前不要报告部署完成,也不要进行验证。Node.js 构建在服务器上运行:参见步骤 3。
status: import_started
Agency: 网站类型决定使用哪个操作():以 创建的网站使用 ,如果项目包含构建步骤,该操作会执行构建;其他所有网站使用 ,原样解压归档。它们同步部署归档:调用返回时网站即已上线。Agency 网站上的 WordPress 插件和主题需从 wp-admin 安装。
agency-hosting_websites_getnode-staticagency-hosting_deploy-node-static-websiteagency-hosting_deploy-php-applicationAgency 归档以及自行构建归档时须遵循以下规则(归档命名为 ):
name_YYYYMMDD_HHMMSS.zip- 静态: 请先在本地构建。必须位于归档根目录,而不能放在某个文件夹内:
index.htmlcd dist && zip -r ../site_20260101_120000.zip . - Node.js 源码: 不含 、构建输出(
node_modules/、dist/、.next/)、build/或任何与.env*匹配的内容;最大 50 MB。.gitignore会生成仅包含已提交文件的归档——请说明未提交的更改不会被包含。git archive --format=zip -o app_20260101_120000.zip HEAD
hosting_deployagency-hosting_deploy-*mcp.hostinger.comsearchWithout the local deploy operations (hosted server; on the local server only for Agency)
无本地部署操作时(托管服务器;Agency 则仅在本地服务器上)
- Get upload credentials: (
hosting_files_generate-upload-url,username); Agency:domain(agency-hosting_files_generate-upload-url). Both returnwebsite_uid,urlandauth_key, which authenticate the upload instead of the API token.rest_auth_key - Upload each file with TUS, where is its path in the website's storage:
DEST
bash
SIZE=$(wc -c < "$FILE" | tr -d ' ')
curl -sS -X POST "$URL/$DEST?override=true" -H "X-Auth: $AUTH_KEY" -H "X-Auth-Rest: $REST_AUTH_KEY" -H "Tus-Resumable: 1.0.0" -H "Upload-Length: $SIZE" -H "Upload-Offset: 0"
curl -sS -X PATCH "$URL/$DEST?override=true" -H "X-Auth: $AUTH_KEY" -H "X-Auth-Rest: $REST_AUTH_KEY" -H "Tus-Resumable: 1.0.0" -H "Content-Type: application/offset+octet-stream" -H "Upload-Offset: 0" --data-binary "@$FILE"The first call returns , the second with an header equal to the file size. makes a retry safe.
3. Deploy from the uploaded files ( is any fresh 8-character string, e.g. ):
201204Upload-Offsetoverride=trueRANDOM8$(LC_ALL=C tr -dc 'a-z0-9' < /dev/urandom | head -c 8)| Project | | Then |
|---|---|---|
| Static or PHP | | |
| Node.js | | |
| WordPress plugin | every file, as | |
| WordPress theme | every file, as | |
| Agency, extracted as-is | | |
Agency | | |
- 获取上传凭据:(
hosting_files_generate-upload-url、username);Agency:domain(agency-hosting_files_generate-upload-url)。两者都会返回website_uid、url和auth_key,这些凭据用于上传认证,而不是 API token。rest_auth_key - 使用 TUS 上传每个文件,其中 是文件在网站存储中的路径:
DEST
bash
SIZE=$(wc -c < "$FILE" | tr -d ' ')
curl -sS -X POST "$URL/$DEST?override=true" -H "X-Auth: $AUTH_KEY" -H "X-Auth-Rest: $REST_AUTH_KEY" -H "Tus-Resumable: 1.0.0" -H "Upload-Length: $SIZE" -H "Upload-Offset: 0"
curl -sS -X PATCH "$URL/$DEST?override=true" -H "X-Auth: $AUTH_KEY" -H "X-Auth-Rest: $REST_AUTH_KEY" -H "Tus-Resumable: 1.0.0" -H "Content-Type: application/offset+octet-stream" -H "Upload-Offset: 0" --data-binary "@$FILE"第一个调用返回 ,第二个返回 ,且 请求头的值等于文件大小。 可使重试安全。
3. 从已上传的文件进行部署( 是任意新的 8 字符字符串,例如 ):
201204Upload-Offsetoverride=trueRANDOM8$(LC_ALL=C tr -dc 'a-z0-9' < /dev/urandom | head -c 8)| 项目 | | 然后 |
|---|---|---|
| 静态或 PHP | | 使用 |
| Node.js | | 使用 |
| WordPress 插件 | 每个文件,路径为 | 使用 |
| WordPress 主题 | 每个文件,路径为 | 使用 |
| Agency,原样解压 | | 使用 |
Agency | | 使用 |
3. Node.js builds
3. Node.js 构建
hosting_deploybuildUuidhosting_get-deploymentdomainbuildUuidbuild.statecompletedfailedlogs.linesfromLine- Failed build: the response already carries (fetched once per build; the API allows 5 a minute).
analysis - Wrong detection (framework, , or an entry file inside the build output, such as
output_directoryfor a compiled app): deploy again withdist/server.js,appType,outputDirectoryorbuildScriptset. An archive deploy sends its settings with the request and leaves the stored ones alone; a Git deploy also stores these values, so later pushes build with them.entryFile
On the hosted server, which has no or :
hosting_deployhosting_get-deployment- After the upload steps below, start the build and track it with and
hosting_nodejs_list-builds(byhosting_nodejs_build), polling every 10–20 s.uuid - Failed build: once per build (5 calls a minute), then
hosting_nodejs_analyse-failed-buildif the analysis is empty.hosting_nodejs_build-logs - Wrong detection: run with explicit values,
hosting_nodejs_start-buildandsource_type: "archive"set to the archive's file name in the document root (check it is there withsource_options.archive_path). Store the same values withhosting_files_list-website-and-directories.hosting_nodejs_update-build-settings - To review detected settings before any build: upload the archive with (the TUS steps are in its description), then
hosting_files_generate-upload-url.hosting_nodejs_build-settings-from-archive
hosting_deploybuildUuidhosting_get-deploymentdomainbuildUuidbuild.statecompletedfailedlogs.linesfromLine- 构建失败:响应中已经包含 (每次构建只获取一次;API 允许每分钟调用 5 次)。
analysis - 检测错误(框架、,或入口文件位于构建输出目录内,例如编译型应用的
output_directory):使用dist/server.js、appType、outputDirectory或buildScript重新部署。归档部署会随请求发送这些设置,而不会修改已保存的设置;Git 部署也会保存这些值,因此后续推送将使用它们进行构建。entryFile
在托管服务器上,由于没有 或 :
hosting_deployhosting_get-deployment- 完成下述上传步骤后,使用 和
hosting_nodejs_list-builds(按hosting_nodejs_build)启动构建并进行跟踪,每 10–20 秒轮询一次。uuid - 构建失败:每次构建调用一次 (每分钟 5 次),如果分析结果为空,再调用
hosting_nodejs_analyse-failed-build。hosting_nodejs_build-logs - 检测错误:使用显式值、和
source_type: "archive"调用source_options.archive_path,并将hosting_nodejs_start-build设置为文档根目录中的归档文件名(使用source_options.archive_path检查文件是否位于该处)。使用hosting_files_list-website-and-directories保存相同的值。hosting_nodejs_update-build-settings - 若要在构建前查看检测到的设置:先使用 上传归档(其描述中包含 TUS 步骤),然后使用
hosting_files_generate-upload-url。hosting_nodejs_build-settings-from-archive
4. Auto-deploy from Git
4. 从 Git 自动部署
On the local server, with does all of it: it finds the Git installation that can reach the repository and deploys it as the you give. Always pass or unless the site already runs a Node.js app (or you pass Node.js settings such as ): a new site is not detected as Node.js, and a Node.js repository deployed as static would publish its source. Then:
hosting_deploygit: { repository: "owner/name", branch }typetype: "static""nodejs"appType- PHP and static sites: saves the auto-deployment settings, which deploys the branch immediately and again on every push;
- Node.js sites: starts a build of the branch with the stored build settings; later pushes build the same way. A Git deploy has nothing to detect from, so when none are stored pass and
appType(fromnodeVersioninengines), pluspackage.jsonandoutputDirectoryif the app has a build step; they are stored for those pushes.buildScript
With no active installation it stops and says so: the user connects GitHub or GitLab once in hPanel under Websites → Manage → Advanced → Git; there is no API for that step. Confirm with , which returns the stored .
hosting_get-deploymentgitAutoDeploymentOn the hosted server, by hand:
- . With no
hosting_git_list-installationsinstallation (checkactiveandstatus: "pending"too), the user connects GitHub or GitLab once in hPanel, as above."suspended" - with the installation
hosting_git_list-installation-repositoriesgivesuuid,ownerandname(10 calls a minute).default_branch - with
hosting_git_update-auto-deployment-settings,installation_uuid,owner,repositoryand optionalbranch.directory- PHP and static sites deploy the branch immediately and again on every push.
- Node.js sites clone nothing on save: start the first build with ,
hosting_nodejs_start-buildand the samesource_type: "git". Later pushes build with the stored settings, so keepsource_optionscorrect.hosting_nodejs_update-build-settings
- Confirm with .
hosting_git_auto-deployment-settings
Agency Plan sites have no Git operations; deploy archives.
在本地服务器上, 配合 可完成全部工作:它会找到能够访问该仓库的 Git 安装,并按指定的 进行部署。除非网站已经运行 Node.js 应用(或传入 等 Node.js 设置),否则始终传入 或 :新网站不会被检测为 Node.js,而将 Node.js 仓库作为静态站点部署会发布其源代码。然后:
hosting_deploygit: { repository: "owner/name", branch }typeappTypetype: "static""nodejs"- PHP 和静态站点: 保存自动部署设置,立即部署该分支,并在每次推送时再次部署;
- Node.js 网站: 使用已保存的构建设置启动该分支的构建;后续推送会以相同方式进行构建。Git 部署没有可供检测的内容,因此如果尚未保存任何设置,请传入 和
appType(取自nodeVersion的package.json),并在应用有构建步骤时传入engines和outputDirectory;这些设置会被保存并用于后续推送。buildScript
如果没有有效的安装,该操作会停止并给出提示:用户需要在 hPanel 的 Websites → Manage → Advanced → Git 中一次性连接 GitHub 或 GitLab;此步骤没有对应的 API。使用 进行确认,它会返回已保存的 。
hosting_get-deploymentgitAutoDeployment在托管服务器上手动操作:
- 。如果没有
hosting_git_list-installations安装(也要检查active和status: "pending"),用户需要按上述方式在 hPanel 中一次性连接 GitHub 或 GitLab。"suspended" - 使用安装的 调用
uuid,获取hosting_git_list-installation-repositories、owner和name(每分钟 10 次调用)。default_branch - 使用 、
installation_uuid、owner、repository和可选的branch调用directory。hosting_git_update-auto-deployment-settings- PHP 和静态站点会立即部署该分支,并在每次推送时再次部署。
- Node.js 网站在保存设置时不会克隆任何内容:使用 、
hosting_nodejs_start-build和相同的source_type: "git"启动首次构建。后续推送将使用已保存的设置进行构建,因此必须确保source_options中的设置正确。hosting_nodejs_update-build-settings
- 使用 进行确认。
hosting_git_auto-deployment-settings
Agency Plan 站点不支持 Git 操作;请部署归档。
5. Environment variables (Node.js)
5. 环境变量(Node.js)
hosting_nodejs_replace-environment-variables- for the current keys. Values come back as
hosting_nodejs_list-environment-variables; never send those back.******** - Build the full set: every current key plus the new ones, with real values from the project's or the user. When the real value of an existing key is unknown, ask — do not drop it.
.env - Send it once; the app restarts. Values baked in at build time (Next.js , Vite
NEXT_PUBLIC_*) need a newVITE_*.hosting_nodejs_start-build
Keys use uppercase letters, digits and underscores. Never commit files or repeat secret values back to the user.
.envhosting_nodejs_replace-environment-variables- 使用 获取当前变量名。值以
hosting_nodejs_list-environment-variables返回;切勿将这些值发回。******** - 构建完整集合:保留所有当前变量名并添加新变量名,值取自项目的 或由用户提供。当某个现有变量的真实值未知时,应询问用户——切勿将其丢弃。
.env - 一次性发送完整集合;应用随即重启。在构建时固化到产物中的值(Next.js 、Vite
NEXT_PUBLIC_*)需要重新调用VITE_*。hosting_nodejs_start-build
变量名使用大写字母、数字和下划线。切勿提交 文件,也不要向用户重复返回密钥值。
.env6. Database
6. 数据库
- Node.js: creates a MySQL database and writes
hosting_databases_setup-website,DB_HOST,DB_PORT,DB_NAME,DB_USERandDB_PASSWORDinto the environment, then restarts the app. The password is generated and never returned. It fails with 422 when any of those keys exists — remove them first with the step 5 replace.DATABASE_URL - PHP: with
hosting_databases_create,name, a strong generateduserandpassword; read the prefixed full name back fromwebsite_domain. The app reads credentials from a config file on the server that stays out of Git, and connects tohosting_databases_listorlocalhost.127.0.0.1 - Agency: ; the app connects to
agency-hosting_databases_create-website.localhost - The host from
srvNNNN.hstgr.iois only for connections from outside Hostinger — never put it in the deployed app.hosting_databases_list
- Node.js: 创建 MySQL 数据库,并将
hosting_databases_setup-website、DB_HOST、DB_PORT、DB_NAME、DB_USER和DB_PASSWORD写入环境变量,然后重启应用。密码由系统生成,且不会返回。当其中任一变量已存在时,该操作会返回 422——先使用步骤 5 的替换操作将其移除。DATABASE_URL - PHP: 使用 、
name、系统生成的强密码和user调用website_domain;通过hosting_databases_create读取带前缀的完整名称。应用从服务器上的配置文件中读取凭据,该文件不会进入 Git,并连接hosting_databases_list或localhost。127.0.0.1 - Agency: 使用 ;应用连接
agency-hosting_databases_create-website。localhost - 返回的
hosting_databases_list主机仅用于从 Hostinger 外部连接——切勿将其写入已部署的应用。srvNNNN.hstgr.io
7. Verify and record
7. 验证并记录
bash
curl -s -o /dev/null -w "%{http_code}\n" https://DOMAIN/
curl -s https://DOMAIN/ | grep -o "TEXT THE PROJECT RENDERS"A alone can be a placeholder page; match real copy. A new site may serve a default page briefly — clear it with and retry before calling the deploy failed.
200hosting_cache_clear-websiteWrite in the project so later runs reuse the target: , keeping any fields already there.
.hostinger/site.json{ "domain", "username" or "website_uid", "type": "static" | "nodejs" | "php" }bash
curl -s -o /dev/null -w "%{http_code}\n" https://DOMAIN/
curl -s https://DOMAIN/ | grep -o "TEXT THE PROJECT RENDERS"仅有 可能说明返回的只是占位页面;应匹配真实文案。新网站可能短暂提供默认页面——先使用 清除缓存并重试,再判定部署失败。
200hosting_cache_clear-website在项目中写入 ,以便后续运行复用目标:,并保留其中已有的所有字段。
.hostinger/site.json{ "domain", "username" or "website_uid", "type": "static" | "nodejs" | "php" }