Deploying Formbricks
Introduction
Formbricks is a powerful open-source experience management platform that enables developers and product teams to collect qualitative user feedback through in-app surveys, link surveys, and website surveys. Built with modern technologies like Next.js, React, and PostgreSQL, Formbricks provides an alternative to proprietary tools like Typeform and Qualtrics, giving you full control over your data and user insights.
Whether you’re building a SaaS product and need to understand user behavior, running customer research, or collecting feedback at scale, Formbricks offers a flexible, self-hosted solution. Deploying Formbricks on Klutch.sh gives you a production-ready infrastructure with automatic deployments from GitHub, persistent storage for your data, and the ability to scale as your user base grows.
This comprehensive guide walks you through deploying Formbricks on Klutch.sh using a Dockerfile, from initial setup and installation to production configuration, database management, and scaling strategies.
Prerequisites
Before you begin deploying Formbricks on Klutch.sh, ensure you have:
- A Klutch.sh account with access to the dashboard
- A GitHub account with a repository for your Formbricks deployment
- Basic familiarity with Docker, environment variables, and PostgreSQL
- (Recommended) A PostgreSQL database instance for production use
Understanding Formbricks Architecture
Formbricks consists of several key components:
- Web Application: A Next.js application that serves the dashboard and admin interface
- API Server: RESTful API for managing surveys, responses, and integrations
- Database: PostgreSQL database for storing survey data, user information, and responses
- File Storage: Storage for uploaded files, images, and other assets
When deploying on Klutch.sh, you’ll configure these components using environment variables and persistent volumes to ensure your data persists across deployments.
Getting Started: Sample Formbricks Application
Let’s create a basic Formbricks deployment setup that you can customize for your needs.
Step 1: Create Your Project Structure
Create a new directory for your Formbricks deployment:
mkdir formbricks-deploymentcd formbricks-deploymentStep 2: Create a Dockerfile
Create a Dockerfile in your project root. This Dockerfile will set up Formbricks with all necessary dependencies:
# Use Node.js LTS version as base imageFROM node:20-alpine AS base
# Install dependencies only when neededFROM base AS depsRUN apk add --no-cache libc6-compat opensslWORKDIR /app
# Install dependencies based on the preferred package managerCOPY package.json package-lock.json* ./RUN npm ci
# Rebuild the source code only when neededFROM base AS builderWORKDIR /appCOPY --from=deps /app/node_modules ./node_modulesCOPY . .
# Set environment variables for buildENV NEXT_TELEMETRY_DISABLED=1ENV NODE_ENV=production
# Build the applicationRUN npm run build
# Production image, copy all the files and run the appFROM base AS runnerWORKDIR /app
ENV NODE_ENV=productionENV NEXT_TELEMETRY_DISABLED=1
RUN addgroup --system --gid 1001 nodejsRUN adduser --system --uid 1001 nextjs
# Copy built applicationCOPY --from=builder /app/public ./publicCOPY --from=builder /app/.next/standalone ./COPY --from=builder /app/.next/static ./.next/static
# Set correct permissionsRUN chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
ENV PORT=3000ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]Step 3: Alternative - Using Official Formbricks Image
If you prefer to use the official Formbricks Docker image, create a simpler Dockerfile:
FROM formbricks/formbricks:latest
# Set working directoryWORKDIR /app
# The official image already includes all necessary configurations# You can add custom scripts or configurations here if needed
EXPOSE 3000
# The entrypoint is already configured in the base imageStep 4: Create Environment Configuration Template
Create a .env.example file to document required environment variables:
# Database ConfigurationDATABASE_URL=postgresql://user:password@host:5432/formbricks
# Application SettingsWEBAPP_URL=https://example-app.klutch.shNEXTAUTH_SECRET=your-secure-random-string-hereNEXTAUTH_URL=https://example-app.klutch.sh
# Email Configuration (Optional)MAIL_FROM=noreply@yourdomain.comSMTP_HOST=smtp.sendgrid.netSMTP_PORT=587SMTP_SECURE_ENABLED=0SMTP_USER=apikeySMTP_PASSWORD=your-sendgrid-api-key
# Storage Configuration (Optional)# For file uploads - use S3-compatible storage or persistent volumes# S3_ACCESS_KEY=your-access-key# S3_SECRET_KEY=your-secret-key# S3_REGION=us-east-1# S3_BUCKET_NAME=formbricks-uploads
# Other SettingsCRON_SECRET=your-cron-secretENCRYPTION_KEY=your-encryption-keyStep 5: Initialize Git Repository
Initialize a Git repository and push to GitHub:
git initgit add .git commit -m "Initial Formbricks deployment setup"git remote add origin https://github.com/your-username/formbricks-deployment.gitgit push -u origin mainDeploying to Klutch.sh
Now that you have your Formbricks application prepared, let’s deploy it to Klutch.sh. Klutch.sh will automatically detect the Dockerfile in your repository root and use it to build your application.
Deployment Steps
-
Create a New Project
Log in to the Klutch.sh dashboard and create a new project. Give your project a descriptive name like “Formbricks Production”.
-
Set Up PostgreSQL Database
Before deploying the app, you’ll need a PostgreSQL database. You can either:
- Use a managed PostgreSQL service like Supabase, Neon, or AWS RDS
- Deploy PostgreSQL on Klutch.sh (see database deployment guides)
Note your database connection string in the format:
postgresql://username:password@hostname:5432/database_name -
Create Persistent Volume
Create a persistent volume in Klutch.sh for storing uploaded files and application data:
- Navigate to your project in the Klutch.sh dashboard
- Go to the Volumes section
- Create a new volume with a mount path of
/app/uploads - Set the size based on your expected storage needs (start with 10GB minimum)
This ensures that user uploads and generated files persist across deployments. For more details, see the Volumes documentation.
-
Create New App
Create a new app within your project:
- Name: Give your app a name like “formbricks-app”
- Repository: Select your GitHub repository containing the Dockerfile
- Branch: Choose your main branch (typically
mainormaster) - Traffic Type: Select HTTP (Formbricks is a web application)
- Internal Port: Set to 3000 (this is the port Formbricks listens on inside the container)
- Region: Choose the region closest to your users
- Compute: Start with a medium instance (2GB RAM, 1 vCPU minimum recommended)
- Instances: Start with 1 instance, scale up as needed
-
Configure Environment Variables
Add the following environment variables in your app settings. These are critical for Formbricks to function properly:
Required Variables:
DATABASE_URL: Your PostgreSQL connection stringNEXTAUTH_SECRET: Generate a secure random string (useopenssl rand -base64 32)NEXTAUTH_URL: Your app’s public URL (e.g.,https://example-app.klutch.sh)WEBAPP_URL: Same as NEXTAUTH_URLCRON_SECRET: Another secure random string for scheduled tasksENCRYPTION_KEY: Secure string for encrypting sensitive data (useopenssl rand -hex 32)
Optional but Recommended:
MAIL_FROM: Email address for sending notificationsSMTP_HOST: SMTP server hostnameSMTP_PORT: SMTP server portSMTP_USER: SMTP usernameSMTP_PASSWORD: SMTP password (mark as secret)
Mark sensitive values like passwords and keys as “secret” to prevent them from appearing in logs.
-
Attach Persistent Volume
In your app settings, attach the volume you created earlier:
- Mount path:
/app/uploads - Select the volume you created in step 3
This ensures uploaded files and generated content persist across deployments.
- Mount path:
-
Deploy Your Application
Click Create to start the deployment. Klutch.sh will:
- Clone your GitHub repository
- Detect the Dockerfile automatically
- Build the Docker image
- Deploy your container with the configured settings
- Expose your app at a URL like
example-app.klutch.sh
-
Monitor Deployment
Watch the build logs to ensure everything deploys successfully. The initial build may take 5-10 minutes depending on your dependencies.
-
Access Your Formbricks Instance
Once deployed, visit your app’s URL (e.g.,
https://example-app.klutch.sh). You should see the Formbricks setup wizard on first launch. Follow the on-screen instructions to:- Create your admin account
- Configure your organization
- Set up your first survey
Database Configuration
Formbricks requires PostgreSQL 12 or higher. Here’s how to properly configure your database:
Database Connection
Your DATABASE_URL should follow this format:
postgresql://username:password@hostname:5432/database_name?sslmode=requireImportant considerations:
- Use SSL connections in production (
?sslmode=require) - Create a dedicated database user for Formbricks with appropriate permissions
- Enable connection pooling if using a connection pooler like PgBouncer
- Set appropriate connection limits based on your instance size
Database Initialization
On first deployment, Formbricks will automatically:
- Run database migrations to create necessary tables
- Set up initial schema
- Create default configurations
You can verify this in your deployment logs. Look for messages like:
[Database] Running migrations...[Database] Migrations completed successfullyDatabase Best Practices
- Backups: Set up automated daily backups of your PostgreSQL database
- Performance: Monitor query performance and add indexes as your data grows
- Scaling: Consider read replicas if you have high traffic
- Security: Never expose your database port publicly; keep it in a private network
Persistent Storage Configuration
Formbricks needs persistent storage for:
- User-uploaded files (images, documents)
- Generated reports and exports
- Cached assets
- Log files
Using Klutch.sh Volumes
Attach a persistent volume to your app at /app/uploads:
- In your app settings, create or attach a volume
- Set the mount path to
/app/uploads - Choose an appropriate size (recommended: 10GB minimum, scale based on usage)
Using S3-Compatible Storage (Alternative)
For larger deployments or better scalability, use S3-compatible storage:
Add these environment variables:
S3_ACCESS_KEY=your-access-keyS3_SECRET_KEY=your-secret-keyS3_REGION=us-east-1S3_BUCKET_NAME=formbricks-uploadsS3_ENDPOINT_URL=https://s3.amazonaws.com # Optional, for S3-compatible servicesThis offloads file storage to object storage, reducing container disk usage.
Environment Variables Reference
Here’s a comprehensive list of environment variables you can configure:
Core Application Settings
| Variable | Required | Description |
|---|---|---|
DATABASE_URL | Yes | PostgreSQL connection string |
NEXTAUTH_SECRET | Yes | Secret for NextAuth.js session encryption |
NEXTAUTH_URL | Yes | Full URL where your app is hosted |
WEBAPP_URL | Yes | Same as NEXTAUTH_URL |
CRON_SECRET | Yes | Secret for securing cron job endpoints |
ENCRYPTION_KEY | Yes | Key for encrypting sensitive data |
Email Configuration
| Variable | Required | Description |
|---|---|---|
MAIL_FROM | No | Sender email address |
SMTP_HOST | No | SMTP server hostname |
SMTP_PORT | No | SMTP server port (typically 587 or 465) |
SMTP_SECURE_ENABLED | No | Set to 1 for SSL/TLS |
SMTP_USER | No | SMTP authentication username |
SMTP_PASSWORD | No | SMTP authentication password |
Storage Configuration
| Variable | Required | Description |
|---|---|---|
S3_ACCESS_KEY | No | S3 or compatible service access key |
S3_SECRET_KEY | No | S3 or compatible service secret key |
S3_REGION | No | AWS region or compatible service region |
S3_BUCKET_NAME | No | Bucket name for file storage |
S3_ENDPOINT_URL | No | Custom endpoint for S3-compatible services |
Optional Settings
| Variable | Required | Description |
|---|---|---|
PRIVACY_URL | No | Link to your privacy policy |
TERMS_URL | No | Link to your terms of service |
IMPRINT_URL | No | Link to your imprint/legal notice |
GITHUB_AUTH_ENABLED | No | Enable GitHub OAuth (0 or 1) |
GOOGLE_AUTH_ENABLED | No | Enable Google OAuth (0 or 1) |
SIGNUP_DISABLED | No | Disable public signups (0 or 1) |
INVITE_DISABLED | No | Disable team invites (0 or 1) |
Custom Domain Configuration
To use your own domain with Formbricks:
-
Add Custom Domain in Klutch.sh
- Navigate to your app in the Klutch.sh dashboard
- Go to the Domains section
- Add your custom domain (e.g.,
surveys.yourdomain.com) - Klutch.sh will provide DNS configuration instructions
-
Update DNS Records
In your domain provider’s DNS settings:
- Add an A record or CNAME record as instructed by Klutch.sh
- Wait for DNS propagation (typically 5-60 minutes)
-
Update Environment Variables
Update these variables to reflect your custom domain:
Terminal window NEXTAUTH_URL=https://surveys.yourdomain.comWEBAPP_URL=https://surveys.yourdomain.com -
Redeploy Application
Trigger a redeploy for the changes to take effect.
Klutch.sh automatically provisions and manages SSL/TLS certificates for your custom domain, ensuring secure HTTPS connections.
For detailed instructions, see the Custom Domains documentation.
Scaling and Performance Optimization
As your Formbricks usage grows, consider these scaling strategies:
Vertical Scaling
Increase your instance size in the Klutch.sh dashboard:
- Monitor CPU and memory usage
- Upgrade to larger instance types as needed
- Recommended minimum: 2GB RAM, 1 vCPU for production
Horizontal Scaling
For high-traffic deployments:
- Increase the number of instances in your app settings
- Klutch.sh automatically load balances between instances
- Ensure your database can handle multiple connections
- Use Redis for session storage across multiple instances
Database Optimization
- Enable connection pooling (use PgBouncer)
- Monitor slow queries and add indexes
- Consider read replicas for heavy read workloads
- Regular VACUUM operations to maintain performance
Caching Strategies
- Enable Next.js caching features
- Use Redis for application caching
- Configure CDN for static assets
- Implement API response caching where appropriate
Performance Monitoring
Monitor these key metrics:
- Response time: API and page load times
- Database performance: Query execution times
- Memory usage: Container memory consumption
- CPU usage: Processing load
- Error rates: Application errors and failed requests
Use Klutch.sh’s built-in monitoring or integrate external tools like Datadog, New Relic, or Sentry.
Security Best Practices
Ensure your Formbricks deployment is secure:
Environment Security
-
Use Strong Secrets: Generate cryptographically secure random strings for all secret variables
Terminal window openssl rand -base64 32 # For NEXTAUTH_SECRETopenssl rand -hex 32 # For ENCRYPTION_KEY -
Mark Secrets Properly: In Klutch.sh, mark all sensitive environment variables as “secret”
-
Rotate Credentials: Regularly rotate database passwords, API keys, and secrets
Database Security
- Use SSL/TLS for database connections
- Restrict database access to your app’s network
- Create dedicated database users with minimal required permissions
- Enable database audit logging
Application Security
- Keep Formbricks updated to the latest version
- Enable 2FA for admin accounts
- Configure CORS properly for your domains
- Set up rate limiting to prevent abuse
- Review and limit API access
Network Security
- Use HTTPS only (Klutch.sh provides this automatically)
- Configure proper Content Security Policy (CSP) headers
- Disable unnecessary ports and services
- Use private networks for internal services
Backup and Recovery
- Automate daily database backups
- Test backup restoration procedures regularly
- Keep backups in a separate region or service
- Document your disaster recovery plan
Troubleshooting Common Issues
Database Connection Errors
Symptom: App fails to start with “Database connection failed”
Solutions:
- Verify
DATABASE_URLformat is correct - Ensure database server is accessible from Klutch.sh
- Check database credentials are correct
- Verify database accepts SSL connections
- Check database connection limits aren’t exceeded
Build Failures
Symptom: Docker build fails during deployment
Solutions:
- Review build logs in Klutch.sh dashboard
- Ensure all dependencies are specified correctly
- Verify Node.js version compatibility
- Check for syntax errors in Dockerfile
- Ensure sufficient memory for build process
Application Crashes
Symptom: App starts but crashes shortly after
Solutions:
- Check application logs for error messages
- Verify all required environment variables are set
- Ensure database migrations completed successfully
- Check memory limits aren’t being exceeded
- Verify persistent volumes are mounted correctly
File Upload Issues
Symptom: Users can’t upload files
Solutions:
- Verify persistent volume is attached correctly
- Check volume has sufficient free space
- Ensure app has write permissions to upload directory
- If using S3, verify credentials and bucket permissions
- Check file size limits in your configuration
Email Sending Problems
Symptom: Email notifications don’t send
Solutions:
- Verify SMTP settings are correct
- Test SMTP credentials with a mail client
- Check if your SMTP provider requires allowlisting
- Verify firewall allows outbound SMTP connections
- Review email logs for specific error messages
Performance Issues
Symptom: Slow response times or timeouts
Solutions:
- Monitor resource usage (CPU, memory)
- Check database query performance
- Review application logs for bottlenecks
- Consider scaling up instance size
- Optimize database queries and add indexes
- Enable caching where appropriate
Monitoring and Maintenance
Regular Maintenance Tasks
Perform these tasks regularly to keep your Formbricks deployment healthy:
Daily:
- Monitor application logs for errors
- Check resource usage (CPU, memory, disk)
- Verify automated backups completed successfully
Weekly:
- Review database performance metrics
- Check for Formbricks updates
- Monitor storage usage and growth trends
- Review access logs for suspicious activity
Monthly:
- Test backup restoration procedures
- Review and rotate credentials
- Update dependencies and security patches
- Analyze usage patterns and plan scaling
Logging
Configure logging for better observability:
- Application Logs: Available in Klutch.sh dashboard
- Database Logs: Enable query logging for troubleshooting
- Access Logs: Monitor HTTP requests and responses
- Error Tracking: Consider integrating Sentry or similar
Alerts
Set up alerts for critical issues:
- High error rates
- Memory or CPU threshold breaches
- Database connection failures
- Disk space running low
- SSL certificate expiration
Upgrading Formbricks
To upgrade to a new version of Formbricks:
-
Review Changelog: Check the Formbricks releases for breaking changes
-
Backup Database: Create a database backup before upgrading
-
Update Docker Image:
- If using official image: Update version in Dockerfile
- If building from source: Pull latest code
-
Test Locally: Test the upgrade in a development environment first
-
Deploy Update:
- Push changes to GitHub
- Klutch.sh will automatically rebuild and deploy
-
Run Migrations: Formbricks will automatically run database migrations on startup
-
Verify Deployment: Check logs and test functionality after upgrade
Example Production Configuration
Here’s a complete example of a production-ready Formbricks deployment:
Dockerfile (using official image):
FROM formbricks/formbricks:latest
# Production-ready configurationWORKDIR /app
# Health checkHEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD node healthcheck.js || exit 1
EXPOSE 3000
# Use non-root userUSER nodeEnvironment Variables (production):
# Core SettingsDATABASE_URL=postgresql://formbricks:secure_password@postgres.internal:5432/formbricks?sslmode=requireNEXTAUTH_SECRET=your-production-secret-here-min-32-charsNEXTAUTH_URL=https://surveys.yourdomain.comWEBAPP_URL=https://surveys.yourdomain.comCRON_SECRET=another-secure-production-secretENCRYPTION_KEY=your-hex-encryption-key-64-chars
# Email ConfigurationMAIL_FROM=surveys@yourdomain.comSMTP_HOST=smtp.sendgrid.netSMTP_PORT=587SMTP_SECURE_ENABLED=0SMTP_USER=apikeySMTP_PASSWORD=your-sendgrid-api-key
# Storage (S3)S3_ACCESS_KEY=your-s3-access-keyS3_SECRET_KEY=your-s3-secret-keyS3_REGION=us-east-1S3_BUCKET_NAME=formbricks-prod-uploads
# SecuritySIGNUP_DISABLED=1INVITE_DISABLED=0
# URLsPRIVACY_URL=https://yourdomain.com/privacyTERMS_URL=https://yourdomain.com/termsVolume Configuration:
- Mount path:
/app/uploads - Size: 50GB
- Backup: Daily automated backups
Instance Configuration:
- Instance type: 4GB RAM, 2 vCPU
- Number of instances: 2 (for high availability)
- Region: Closest to your user base
- Auto-scaling: Enabled
Resources and Further Reading
- Formbricks Official Documentation
- Formbricks GitHub Repository
- Formbricks Community
- Klutch.sh Quick Start Guide
- Klutch.sh Volumes Documentation
- Klutch.sh Deployment Concepts
- Klutch.sh Custom Domains
Conclusion
Deploying Formbricks on Klutch.sh provides you with a robust, scalable platform for collecting and managing user feedback. With automatic deployments from GitHub, persistent storage, and easy scaling options, you can focus on building great surveys and gathering insights rather than managing infrastructure.
This guide covered everything from basic deployment to production-ready configurations. Start with a simple setup and gradually add features like custom domains, S3 storage, and horizontal scaling as your needs grow. Remember to follow security best practices, maintain regular backups, and keep your Formbricks instance updated.
For additional support or questions, refer to the resources above or reach out to the Klutch.sh community. Happy surveying!