Deployment
phpbotgram ships ready-made deployment templates under deploy/: nginx + systemd + Docker compose. Pick the shape you want.
Long-polling bot (systemd)
Best for low-traffic bots running on a single VM.
- Install
deploy/systemd/phpbotgram-polling.serviceto/etc/systemd/system/. - Edit the
User,WorkingDirectory,EnvironmentFile,ExecStartpaths. systemctl daemon-reload && systemctl enable --now phpbotgram-polling.
The unit drops capabilities, applies SystemCallFilter
, and uses ProtectSystem=strict
. Read deploy/README.md for hardening notes (e.g. the MemoryDenyWriteExecute
+ PHP JIT interaction).
Webhook bot (nginx + amphp/http-server)
Best for higher traffic or when you want subsecond latency.
- Install
deploy/systemd/phpbotgram-webhook.serviceto/etc/systemd/system/. It runsexamples/echo_bot_webhook.phpon127.0.0.1:8080. Webhook mode needs the suggested dependency:composer require amphp/http-server. systemctl daemon-reload && systemctl enable --now phpbotgram-webhook.- Install
deploy/nginx/phpbotgram-webhook.confto/etc/nginx/sites-available/and link fromsites-enabled/. - Provision a TLS cert (Let's Encrypt). The provided config terminates TLS and proxies to the loopback.
- Register the webhook with Telegram via
setWebhook(the framework'sSetup::register()helper handles this).
The nginx config restricts inbound to Telegram's CIDR ranges. The framework's IpFilter middleware can repeat the check in defense-in-depth; wire it via AmphpServer::run(..., ipFilter: IpFilter::default())
.
Docker
deploy/docker/Dockerfile
+ deploy/docker/compose.yaml
ship a multi-stage build producing a php:8.5-cli-alpine
runtime with vendor/
+ src/
+ examples/
.
BOT_TOKEN=… docker compose -f deploy/docker/compose.yaml up --build
The image runs as UID 65532. For webhook mode in a container, change host: '127.0.0.1'
to '0.0.0.0'
in examples/echo_bot_webhook.php
so docker run -p 8080:8080
can reach it.
What's next
Browse the cookbook for task-oriented recipes or the concepts pages for the architectural deep dive.