LogoMkSaaS Docs
LogoMkSaaS Docs
HomepageIntroductionCodebaseVideo TutorialsGetting StartedEnvironment Setup
Configuration

Integrations

DatabaseAuthenticationEmailNewsletterStoragePaymentCreditsCron JobsAIAnalyticsNotificationCaptchaChatboxAffiliates

Customization

MetadataFontsThemesImagesi18nBlogDocsComponentsCustom PagesLanding PageUser Management

Codebase

IDE SetupProject StructureFormatting & LintingUpdating the Codebase
X (Twitter)

Environment Setup

Configure environment variables for your MkSaaS application

MkSaaS requires several environment variables to function properly, and this guide explains how to set them up.

Create a .env file in the root directory of your project, and never commit it to version control.

You can copy the example file as a starting point:

cp env.example .env

Environment Variables

Core Configuration

VariableDescription
NEXT_PUBLIC_BASE_URLThe public URL of your site, e.g.
http://localhost:3000 for development,
https://=YOUR-DOMAIN.com for production

Database

Learn how to set up a database in the Database Setup guide.

VariableDescription
DATABASE_URLDatabase connection URL

Authentication

Learn how to set up authentication in the Authentication Setup guide.

VariableDescription
BETTER_AUTH_SECRETA random string used to hash tokens and sign cookies
GOOGLE_CLIENT_IDGoogle OAuth client ID (optional)
GOOGLE_CLIENT_SECRETGoogle OAuth client secret (optional)
GITHUB_CLIENT_IDGitHub OAuth client ID (optional)
GITHUB_CLIENT_SECRETGitHub OAuth client secret (optional)

Email

Learn how to set up email in the Email Setup guide.

VariableDescription
RESEND_API_KEYAPI key for Resend email service

Newsletter

Learn how to set up newsletter in the Newsletter Setup guide.

VariableDescription
RESEND_API_KEYAPI key for Resend email service

Storage

Learn how to set up storage in the Storage Setup guide.

VariableDescription
STORAGE_REGIONRegion for the storage bucket
STORAGE_BUCKET_NAMEName of the storage bucket
STORAGE_ACCESS_KEY_IDAccess key ID for the storage bucket
STORAGE_SECRET_ACCESS_KEYSecret access key for the storage bucket
STORAGE_ENDPOINTEndpoint for the storage bucket
STORAGE_PUBLIC_URLPublic URL for the storage bucket

Payment

Learn how to set up payments in the Payment Setup guide.

VariableDescription
STRIPE_SECRET_KEYStripe secret key
STRIPE_WEBHOOK_SECRETStripe webhook signing secret
NEXT_PUBLIC_STRIPE_PRICE_PRO_MONTHLYStripe price ID for pro monthly subscription
NEXT_PUBLIC_STRIPE_PRICE_PRO_YEARLYStripe price ID for pro yearly subscription
NEXT_PUBLIC_STRIPE_PRICE_LIFETIMEStripe price ID for lifetime subscription

Credits

Learn how to set up credits in the Credits Setup guide.

VariableDescription
NEXT_PUBLIC_STRIPE_PRICE_CREDITS_BASICStripe price ID for basic credit package (optional)
NEXT_PUBLIC_STRIPE_PRICE_CREDITS_STANDARDStripe price ID for standard credit package (optional)
NEXT_PUBLIC_STRIPE_PRICE_CREDITS_PREMIUMStripe price ID for premium credit package (optional)
NEXT_PUBLIC_STRIPE_PRICE_CREDITS_ENTERPRISEStripe price ID for enterprise credit package (optional)

Cron Jobs

Learn how to set up cron jobs in the Cron Jobs Setup guide.

VariableDescription
CRON_JOBS_USERNAMEUsername for basic authentication to trigger cron jobs
CRON_JOBS_PASSWORDPassword for basic authentication to trigger cron jobs

AI Features

Learn how to set up AI features in the AI Setup guide.

VariableDescription
OPENAI_API_KEYAPI key for OpenAI
FAL_API_KEYAPI key for FAL
FIREWORKS_API_KEYAPI key for Fireworks
REPLICATE_API_TOKENAPI key for Replicate
GOOGLE_GENERATIVE_AI_API_KEYAPI key for Google Generative AI
DEEPSEEK_API_KEYAPI key for DeepSeek
OPENROUTER_API_KEYAPI key for OpenRouter

Analytics

Learn how to set up analytics in the Analytics Setup guide.

VariableDescription
NEXT_PUBLIC_GOOGLE_ANALYTICS_IDGoogle Analytics ID
NEXT_PUBLIC_UMAMI_WEBSITE_IDUmami Analytics website ID
NEXT_PUBLIC_UMAMI_SCRIPTUmami Analytics script URL
NEXT_PUBLIC_PLAUSIBLE_DOMAINPlausible Analytics domain
NEXT_PUBLIC_PLAUSIBLE_SCRIPTPlausible Analytics script URL
NEXT_PUBLIC_DATAFAST_WEBSITE_IDDataFast Analytics ID
NEXT_PUBLIC_DATAFAST_DOMAINDataFast Analytics domain
NEXT_PUBLIC_POSTHOG_KEYPostHog Analytics key
NEXT_PUBLIC_POSTHOG_HOSTPostHog Analytics host
NEXT_PUBLIC_AHREFS_WEBSITE_IDAhrefs Analytics website ID
NEXT_PUBLIC_Seline_TOKENSeline Analytics token
NEXT_PUBLIC_OPENPANEL_CLIENT_IDOpenPanel Analytics client ID
NEXT_PUBLIC_CLARITY_PROJECT_IDClarity Analytics project ID

Notification

Learn how to set up notification in the Notification Setup guide.

VariableDescription
DISCORD_WEBHOOK_URLDiscord webhook URL for receiving notifications of successful payments
FEISHU_WEBHOOK_URLFeishu webhook URL for receiving notifications of successful payments

Captcha

Learn how to set up captcha in the Captcha Setup guide.

VariableDescription
NEXT_PUBLIC_TURNSTILE_SITE_KEYTurnstile site key
TURNSTILE_SECRET_KEYTurnstile secret key

Chatbox

Learn how to set up chatbox in the Chatbox Setup guide.

VariableDescription
NEXT_PUBLIC_CRISP_WEBSITE_IDCrisp website ID for chat features

Affiliates

Learn how to set up affiliates in the Affiliates Setup guide.

VariableDescription
NEXT_PUBLIC_AFFILIATE_AFFONSO_IDAffonso affiliate ID
NEXT_PUBLIC_AFFILIATE_PROMOTEKIT_IDPromotekit affiliate ID

Other Configurations

Some other configurations are also available in the .env file, you may need to set them up depending on your needs.

VariableDescription
DISABLE_IMAGE_OPTIMIZATIONDisable image optimization, if you deploy your website to Vercel, image optimization is enabled by default, and may cost you more money
NEXT_PUBLIC_DEMO_WEBSITERun this website as demo website, I use this for MkSaaS demo website. In most cases, you should not set this or leave it to false

Verifying Environment Variables

To verify that your environment variables are correctly set up, run:

pnpm run dev
npm run dev
yarn dev
bun run dev

If everything is configured correctly, your application should start and run normally without any environment-related errors.

Video Tutorial

Next Steps

Now that your environment is set up, explore these related topics:

Configuration

Configure website settings

Getting Started

Set up and run your MkSaaS website

Database Setup

Configure database

IDE Setup

Configure your development environment

Table of Contents

Environment Variables
Core Configuration
Database
Authentication
Email
Newsletter
Storage
Payment
Credits
Cron Jobs
AI Features
Analytics
Notification
Captcha
Chatbox
Affiliates
Other Configurations
Verifying Environment Variables
Video Tutorial
Next Steps