Deploying a YOURLS App
Introduction
YOURLS is a lightweight self-hosted URL shortener. This guide shows how to containerize YOURLS with a Dockerfile, connect it to MySQL, persist uploads/config, and deploy it to Klutch.sh over HTTP.
Prerequisites
- GitHub repository containing your Dockerfile.
- MySQL database (managed or deployed separately).
- Klutch.sh project ready in klutch.sh/app.
Project structure
.└── DockerfileSample Dockerfile
FROM yourls:latest
# Default YOURLS portENV YOURLS_PORT=80EXPOSE 80Required environment variables
YOURLS_SITE– public URL, e.g.,https://example-app.klutch.shYOURLS_USER– admin userYOURLS_PASS– admin passwordYOURLS_DB_HOST– MySQL host and portYOURLS_DB_USERYOURLS_DB_PASSYOURLS_DB_NAMEYOURLS_PORT=80
Optional environment variables
YOURLS_DB_PREFIX=yourls_YOURLS_HOURS_OFFSET=0YOURLS_PRIVATE=trueto restrict access
Persistence
Persist configuration and data:
- Mount path:
/var/www/html/user - Size: minimal unless storing large plugins/assets
Networking
- Protocol: HTTP
- Internal port:
80 - Users reach
https://example-app.klutch.shwhile Klutch.sh routes to port80inside the container.
Health check (recommended)
curl -I http://localhostDeployment on Klutch.sh
- Push your Dockerfile to GitHub.
- In klutch.sh/app, create a new app and select GitHub as the source.
- Klutch.sh automatically detects the Dockerfile in the repository root.
- Select HTTP traffic and set the internal port to
80. - Add environment variables for
YOURLS_SITE, admin credentials, and database settings. Mark secrets as sensitive. - Attach a persistent volume at
/var/www/html/userfor plugins/config. - Deploy. After first boot, log in to the YOURLS admin to add short links.
Verification
-
UI: open
https://example-app.klutch.sh/adminand sign in. -
Quick check:
Terminal window curl -I https://example-app.klutch.sh
Next steps
- Configure HTTPS at the edge and set
YOURLS_SITEaccordingly. - Enable backups for MySQL and the
/var/www/html/uservolume. - Add custom domain mappings and plugins to extend functionality.