Overview
Dub is an open-source link attribution platform that can be self-hosted for greater control over your data and infrastructure. This guide will walk you through the complete process of setting up Dub on your own servers.Self-hosting Dub requires technical knowledge of deployment, database management, and infrastructure. Ensure you have the necessary expertise or support before proceeding.
Prerequisites
Before you begin, ensure you have:- Node.js v23.11.0 or higher
- pnpm 9.15.9 or higher
- MySQL 8.0 database
- Domain names for your Dub instance
- Access to required third-party services (see below)
Required Services
Dub requires several third-party services to function properly:Analytics & Monitoring
- Tinybird - Required for analytics and click tracking
- Upstash Redis - Required for caching and rate limiting
- Upstash QStash - Required for background jobs and queues
Infrastructure
- MySQL Database - PlanetScale or compatible MySQL 8.0+ database
- Vercel Domains API - Required for custom domain management
Email & Authentication
- Resend or SMTP - For email delivery and authentication
- NextAuth - Built-in authentication system
Optional Services
- Stripe - For subscriptions and payments
- Google OAuth - For Google login
- GitHub OAuth - For GitHub login
- Unsplash - For custom link preview images
- S3-compatible storage - For storing images and assets
- Axiom - For logging and monitoring
Installation Steps
Configure Environment Variables
Copy the example environment file and configure your variables:See the Environment Variables page for detailed configuration.
Set Up Database
Configure your MySQL database and run Prisma migrations:See Database Setup for detailed instructions.
Build the Application
Build the Next.js application:This will compile the application and prepare it for production.
Local Development Setup
For local development with Docker:Start Local Services
Use Docker Compose to start MySQL, PlanetScale proxy, and MailHog:This starts:
- MySQL 8.0 on port 3306
- PlanetScale HTTP proxy on port 3900
- MailHog SMTP server on port 1025 (UI on port 8025)
Run Development Server
Start the Next.js development server:The application will be available at
http://localhost:8888.Domain Configuration
Dub requires proper domain configuration:Required Domains
- Main Application Domain - Where your Dub instance will be hosted
- Short Link Domain - For your shortened links (e.g.,
dub.sh)
DNS Configuration
Point your domains to your server:- A Record: Point to your server’s IP address
- CNAME Record: For subdomains, point to your main domain
Post-Installation
After installation:Production Considerations
Security
- Use HTTPS for all domains
- Set strong
NEXTAUTH_SECRET(32+ characters) - Enable rate limiting with Edge Config
- Regularly update dependencies
- Implement proper backup procedures
Performance
- Use a CDN for static assets
- Configure Redis for optimal caching
- Set up horizontal scaling if needed
- Monitor database performance
- Enable analytics aggregation cron jobs
Cron Jobs
Dub requires several cron jobs for proper operation. When deploying outside Vercel, you’ll need to set these up manually:- Domain Verification - Hourly (
0 * * * *) - Email Domain Verification - Hourly (
0 * * * *) - Update Workspace Clicks - Every minute (
* * * * *) - Update Partner Stats - Every 2 minutes (
*/2 * * * *) - Usage Reporting - Daily at noon (
0 12 * * *) - Aggregate Clicks - Daily at midnight (
0 0 * * *)
Common Issues
Database Connection Issues
Build Failures
Delete generated files and rebuild:Missing Environment Variables
The application will fail to start if required environment variables are missing. Check the logs and ensure all required variables are set.Updating Your Instance
To update your self-hosted Dub instance:Support & Resources
- GitHub Repository
- Environment Variables Reference
- Database Setup Guide
- Deployment Guide
- Open an Issue
License Considerations
Dub is licensed under AGPLv3 for the core platform (99% of the codebase). The Enterprise Edition features in/ee require a commercial license for production use by larger organizations.
For more information, see the LICENSE file in the repository.