Deploying a 2FAuth App
Introduction
2FAuth is an open-source two-factor authentication manager with a web UI. This guide shows how to containerize 2FAuth with a Dockerfile, connect it to PostgreSQL or MySQL, persist encrypted secrets, and deploy it to Klutch.sh over HTTP.
Prerequisites
- GitHub repository containing your Dockerfile.
- PostgreSQL or MySQL database (managed or deployed separately).
- Klutch.sh project ready in klutch.sh/app.
Project structure
.└── DockerfileSample Dockerfile
FROM 2fauth/2fauth:latest
# Default portENV PORT=8000EXPOSE 8000Required environment variables
APP_URL– public URL, e.g.,https://example-app.klutch.shAPP_KEY– strong secret key (php artisan key:generatevalue)DB_CONNECTION–pgsqlormysqlDB_HOST,DB_PORT,DB_DATABASE,DB_USERNAME,DB_PASSWORDPORT=8000
Optional environment variables
LOG_CHANNEL=singleAPP_DEBUG=falseMAIL_MAILERand SMTP settings if you enable emailSESSION_LIFETIMEto adjust session duration
Persistence
2FAuth stores data in the database. To keep local storage for sessions/cache, attach a volume:
- Mount path:
/var/www/html/storage - Size: minimal; primarily for cache and compiled assets
Networking
- Protocol: HTTP
- Internal port:
8000 - Users reach
https://example-app.klutch.shwhile Klutch.sh routes to port8000inside the container.
Health check (recommended)
curl -I http://localhost:8000Deployment 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
8000. - Add environment variables for
APP_URL,APP_KEY, database connection, and any mail or debug settings. Mark secrets as sensitive. - Attach a persistent volume at
/var/www/html/storageif you need to persist cache/session storage. - Deploy. After the app starts, create your admin account and begin adding 2FA secrets.
Verification
-
UI: open
https://example-app.klutch.shand confirm the login/signup page loads. -
Quick check:
Terminal window curl -I https://example-app.klutch.sh
Next steps
- Enforce HTTPS at the edge and rotate the
APP_KEYonly during re-installs. - Configure database backups and, if used, storage volume snapshots.
- Set up email for account recovery and notifications.