An end-to-end guide on how to self-host Dub – the open-source link attribution platform.
acme.com
as a placeholder for your custom domain, and ac.me
as a placeholder for your custom short domain.
Clone the repo
Install dependencies
Remove unnecessary files
apps/web/vercel.json
file since cron jobs are not required for the self-hosted version:Set up environment variables
.env.example
file to .env
. You can start filling in the first few environment variables:Create Tinybird Workspace
admin
Auth Token. Paste this token as the TINYBIRD_API_KEY
environment variable in your .env
file.Install Tinybird CLI and authenticate
packages/tinybird
directory.Install the Tinybird CLI with pip install tinybird-cli
(requires Python >= 3.8).Run tb auth
and paste your admin
Auth Token.Publish Tinybird datasource and endpoints
tb push
to publish the datasource and endpoints in the packages/tinybird
directory. You should see the following output (truncated for brevity):Set up Tinybird API base URL
TINYBIRD_API_URL
environment variable in your .env
file.Create Upstash database
Set up Upstash environment variables
UPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
from the REST API section into your .env
file.QSTASH_TOKEN
, QSTASH_CURRENT_SIGNING_KEY
, and QSTASH_NEXT_SIGNING_KEY
from the Request Builder section into your .env
file.Create PlanetScale database
Set up PlanetScale environment variables
DATABASE_URL
into your .env
file.Generate Prisma client and create database tables
apps/web/prisma/schema.prisma
and replace all the columns in the DefaultDomains
model to the normalized version of your custom short domain (removing the .
character).For example, if your custom short domain is ac.me
, your DefaultDomains
model should look like this:apps/web
directory and run the following command to generate the Prisma client:https://app.acme.com/api/auth/callback/github
http://localhost:8888/api/auth/callback/github
for local development.Client ID
and Client Secret
into your .env
file as the GITHUB_CLIENT_ID
and GITHUB_CLIENT_SECRET
environment variables.
Create R2 bucket
dubassets
) and leaving the remaining settings as is.Set up access to R2
Access Key ID
and Secret Access Key
values – you’ll need them in the next step.Set up R2 environment variables
.env
file:Set up R2 domain
STORAGE_BASE_URL
in your .env
file to the domain you chose..env
file as the RESEND_API_KEY
environment variable.UNSPLASH_ACCESS_KEY
env var.
Deploy code to GitHub
Create a new Vercel project
apps/web
..env
file by copying all of them and pasting it into the first input field. A few notes:PROJECT_ID_VERCEL
environment variable for now since we will only get the project ID after deploying the project.NEXTAUTH_URL
environment variable with the app domain that you will be using (e.g. https://app.acme.com
).No Output Directory called "public" was found after the build completed
error, make sure that your Vercel deployment
settings to make sure that they match the following:Add required environment variables
PROJECT_ID_VERCEL
environment variable – both in your .env
file and in your newly created Vercel project’s settings (under Settings > Environment Variables)Add both the NEXT_PUBLIC_APP_DOMAIN
and NEXT_PUBLIC_APP_SHORT_DOMAIN
as domains in your Vercel project’s settings (under Settings > Domains). You can follow this guide to learn how to set up a custom domain on Vercel.Redeploy your Vercel project
https://app.acme.com
) and see the following login page: