Deploy an app
Deploy long-running Node.js, Python and Go apps in a Dedicated Container, and manage PHP-FPM, PHP versions, extensions and php.ini.
This guide explains how to deploy a long-running Node.js, Python or Go app in a Dedicated Container, how to manage PHP-FPM, and how to switch PHP versions, install extensions and edit php.ini.
Runtimes
Every container comes with the following runtimes, available on the default PATH (node, npm, python3, go, java, ruby, php and so on):
| Runtime | Versions |
|---|---|
| PHP | 8.1 and 8.2, switchable from the console |
| Node.js, Python, Go, Java, Ruby | One version of each per image |
To see the exact versions, open the container's 配置管理 (Configuration) tab and look at the 运行时环境 (Runtime environment) card.
Deploying an app
The 应用管理 (App management) tab on the container page has four runtime cards: PHP-FPM, Node.js, Python and Golang. If no app has been deployed yet, the Node.js, Python and Golang cards show a 部署应用 (Deploy app) button.
Step 1: Upload your code
Your code must sit in /var/www/html inside the container, or in a subdirectory of it. In the 文件管理 (Files) tab, the root / is the container's /var/www/html. You can upload an archive and extract it in place, or use 远程下载 (Remote download) to fetch it from a URL. See Files and scheduled tasks.
If your app needs dependencies (for example from npm install or pip install), build it locally and upload the directory with the dependencies included.
Step 2: Enter the start settings
Open the container page and switch to the 应用管理 (App management) tab.
On the runtime card you need, click 部署应用 (Deploy app).
Fill in the dialog:
Field Description 启动命令 (Start command) The full command that starts your app, e.g. node app.js,npm start,python app.py,gunicorn app:app -b 0.0.0.0:$PORTor./app工作目录 (Working directory) The directory the command runs in. Defaults to /var/www/html监听端口 (Listen port) The port your app listens on inside the container. Defaults to 3000; range 1–65535Click 部署并启动 (Deploy and start). When you see "应用已部署并启动" (App deployed and started), the card status changes to 运行中 (Running).
The port you enter is passed to your process as the PORT environment variable. Read PORT in your code (for example process.env.PORT in Node.js) so the port isn't hard-coded.
How the start command runs
- The command runs through
/bin/sh -c, so you can pass arguments, expand environment variables (such as$PORT) and use simple shell syntax. - The app runs as the container's
wwwuser. Make sure that user can read your code files and write to any directories your app writes to. - A process manager inside the container supervises the app. It starts the app when the container starts and restarts it automatically if it exits unexpectedly.
- For Go, compile a Linux binary locally, upload it, then use a command such as
./app.
One app per runtime
Each runtime card manages one app process. For example, the Node.js card can run one Node.js app. Once an app is deployed, the card's 部署应用 (Deploy app) button is replaced by 启动 (Start), 停止 (Stop), 重启 (Restart) and 日志 (Logs).
Managing a running app
In the 应用管理 (App management) tab:
- 启动 / 停止 / 重启 (Start / Stop / Restart) control the app process.
- 日志 (Logs) shows the last 200 lines of the app's stdout and stderr. Click 刷新 (Refresh) in the dialog to reload them.
- 刷新状态 (Refresh status) reloads all runtime cards. Each card shows the version, PID and uptime when they're available.
If no app has been deployed for a runtime, its card shows 已停止 (Stopped) with a 部署应用 (Deploy app) button. Clicking Start at this point tells you to deploy an app first.
PHP-FPM
PHP-FPM runs by default in every container, so you don't need to deploy it. The PHP-FPM card lets you stop, start or restart it and view its logs.
Switching the PHP version
- Click 切换PHP版本 (Switch PHP version). The button is in 快捷操作 (Quick actions) on the 概览 (Overview) tab, and on the PHP配置 (PHP) card in the 配置管理 (Configuration) tab.
- Choose PHP 8.1 or PHP 8.2 and click 确认切换 (Confirm).
PHP-FPM restarts automatically after the switch, and every piece of code that uses the default PHP is affected. Check that your code works with the target version before you switch.
Extensions and php.ini
Open the PHP 配置 (PHP configuration) tab:
- PHP 扩展 (PHP extensions): loaded extensions appear as green tags. Click a tag to disable that extension, but be careful with core extensions. To install one, type its name (e.g.
redis,imap,soap,gmp) and click 安装 (Install). Extensions are installed from the official Alpine packages. - php.ini: edit the full php.ini of the active PHP version in the browser. When you save, PHP-FPM hot-restarts automatically.
Extensions and php.ini apply only to the active PHP version. After switching versions, click 刷新 (Refresh) to load that version's configuration.
Monitoring and container actions
- The 概览 (Overview) tab shows CPU usage, memory usage, disk usage and network traffic, plus the container's CPU, memory and disk limits.
- The buttons at the top 启动 (Start), 停止 (Stop) and 重启 (Restart) the container. While the container is stopped, none of its apps are available.
- You can 删除 (Delete) a container from the Dedicated Containers list. Deleting a container permanently erases all of its data, and it can't be recovered.
Deploying through the API
The endpoints the console uses can also be called directly. Send your login token in the Authorization: Bearer <token> header. container_id is the id returned by the container list.
# List containers
curl -H "Authorization: Bearer $TOKEN" \
https://api.yeap.cloud/api/user/host/containers
# Deploy a Node.js app
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
https://api.yeap.cloud/api/user/host/apps/create \
-d '{"container_id": 123, "type": "nodejs", "config": "node app.js", "working_dir": "/var/www/html", "port": 3000}'
# App status and recent logs
curl -H "Authorization: Bearer $TOKEN" \
"https://api.yeap.cloud/api/user/host/apps/status?container_id=123&type=nodejs"
curl -H "Authorization: Bearer $TOKEN" \
"https://api.yeap.cloud/api/user/host/apps/logs?container_id=123&type=nodejs&lines=200"type can be nodejs, python or golang. To start, stop or restart, call POST /api/user/host/apps/start, /stop or /restart with the body {"container_id": 123, "type": "nodejs"}.