Coolify Deployment Guide
A step-by-step guide to deploy your MERN stack application using Coolify on a VPS
Install Coolify on VPS
SSH into your VPS and install Coolify using the official script.
Access Coolify Web Interface
Once Coolify is installed, it provides public IPv4 and IPv6 links. Click on one to complete the initial setup.
During the configuration process:
- Choose 'Self-host' option
- Select 'localhost' for deployment
Note: The installation process might take a few minutes. Keep the terminal window open until it completes.
Connect Your Domain
Go to your domain registrar's DNS settings and add the following A records:
Type | Name | Points to | TTL |
A | @ | your VPS IP | 60 |
A | * | your VPS IP | 60 |
Tip: DNS propagation can take time. You can check the status using online tools like whatsmydns.net
Configure Coolify Domain
In Coolify's administration panel:
- Navigate to Settings → Configuration
- Update the 'Instance Domain' field with your custom domain
- Example:
coolify.codewithnepal.com
Note: After changing the domain, Coolify will need to be restarted and you'll need to access it via the new domain.
Optional DNS Settings for Local Network
If you experience access issues, adjust your PC's DNS settings:
- Go to your PC's Wi-Fi or Ethernet DNS settings
- Switch to manual configuration
- Set Preferred DNS: 1.1.1.1
- Set Alternate DNS: 1.0.0.1
Note: This step is optional and only necessary if you encounter domain resolution issues.
Create a New Project in Coolify
Now let's set up your project structure:
- Navigate to the Projects section in the Coolify dashboard
- Click New Project
- Assign a meaningful name to your project (e.g.,
mern-app
)
Tip: Choose a descriptive project name that helps you identify the app easily, especially if you plan to host multiple applications.
Add MongoDB Database
Add a MongoDB database to your project:
- Within your project, click Add Resource
- Select Database
- Choose MongoDB from the options
- This creates a Docker container running MongoDB
- Click Deploy and Start to make it live
Note: Coolify automatically generates connection credentials. Save these credentials safely for connecting your application.
Connect to GitHub
Connect your GitHub repository to Coolify:
- Back in your project, click Add Resource
- Select Private GitHub Repo with GitHub App
- Follow the prompts to connect your repository via the GitHub App
- Register the webhook when prompted
Tip: This setup enables automatic deployments whenever you push to your repository's main branch.
Add the Repository as a Resource
Configure your repository as a deployable resource:
- Click Add Resource again
- Choose the connected GitHub repo from the list
- Select Nixpacks as the build pack
- Nixpacks will automatically detect your Node.js app and configure the build process
Note: Nixpacks is a smart build system that detects your project structure and requirements automatically.
Configure Application Deployment
Set up the deployment configuration:
- Set your custom domain for the application
- Add necessary environment variables (database connection, API keys, etc.)
- Configure build and start commands:
Tip: Environment variables are crucial for connecting your application to the PostgreSQL instance. Make sure to include PostgreSQL_URI
pointing to the PostgreSQL resource you created earlier.
Deploy Your Application
Complete the deployment process:
- Review all configuration settings
- Click Deploy to start the deployment process
- Monitor the deployment logs for any issues
- Once complete, your MERN stack app will be live on your specified domain
Success: Congratulations! Your MERN stack application is now deployed with Coolify. Any future changes pushed to your repository will trigger automatic deployments.