Deploying your Bolt application to a Virtual Private Server (VPS) gives you full control over your hosting environment and better performance than shared hosting. Ramnode offers reliable and affordable VPS solutions that are perfect for hosting Bolt applications. In this guide, we’ll walk through the entire process of setting up and deploying your Bolt app on a Ramnode VPS.
What You’ll Need
Before we start, make sure you have:
- A Ramnode VPS account and server
- A Bolt application ready for deployment
- Basic command line knowledge
- SSH access to your server
- A domain name (optional but recommended)
Initial Server Setup
Connect to Your Ramnode VPS
First, connect to your server via SSH. Ramnode will provide you with the server IP, username, and password.
ssh root@your-server-ip
Update the System
Once connected, update your server to ensure you have the latest packages:
apt update && apt upgrade -y
Create a Non-Root User
For security reasons, create a new user instead of using root:
adduser deployer
usermod -aG sudo deployer
su - deployer
Install Required Software
Install Node.js and npm
Bolt applications typically require Node.js. Install the latest LTS version:
# Install Node.js 18.x
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
# Verify installation
node --version
npm --version
Install PM2 Process Manager
PM2 will keep your Bolt app running and restart it if it crashes:
sudo npm install -g pm2
Install and Configure Nginx
Nginx will serve as a reverse proxy for your Bolt application:
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
Install Git
You’ll need Git to clone your repository:
sudo apt install git -y
Prepare Your Bolt Application
Clone Your Repository
Navigate to your home directory and clone your Bolt app:
cd ~
git clone https://github.com/yourusername/your-bolt-app.git
cd your-bolt-app
Install Dependencies
Install your application’s dependencies:
npm install
Configure Environment Variables
Create a production environment file:
cp .env.example .env
nano .env
Update your environment variables for production:
NODE_ENV=production
PORT=3000
# Add your database connection strings
# Add any API keys or secrets
# Configure your app-specific variables
Build Your Application
If your Bolt app requires a build step:
npm run build
Configure Nginx as Reverse Proxy
Create a new Nginx configuration file for your site:
sudo nano /etc/nginx/sites-available/your-bolt-app
Add the following configuration:
server {
listen 80;
server_name your-domain.com www.your-domain.com;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
Enable the site:
sudo ln -s /etc/nginx/sites-available/your-bolt-app /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
Deploy with PM2
Create PM2 Ecosystem File
Create a PM2 configuration file:
nano ecosystem.config.js
Add the following configuration:
module.exports = {
apps: [{
name: 'bolt-app',
script: './server.js', // or your main app file
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production',
PORT: 3000
}
}]
};
Start Your Application
Start your Bolt app with PM2:
pm2 start ecosystem.config.js
pm2 save
pm2 startup
Run the command that PM2 outputs to enable auto-start on system reboot.
Set Up SSL with Let’s Encrypt (Optional but Recommended)
Install Certbot
sudo apt install certbot python3-certbot-nginx -y
Obtain SSL Certificate
sudo certbot --nginx -d your-domain.com -d www.your-domain.com
Follow the prompts to complete the SSL setup.
Step 7: Configure Firewall
Set up UFW (Uncomplicated Firewall) to secure your server:
sudo ufw allow ssh
sudo ufw allow 'Nginx Full'
sudo ufw enable
Set Up Database (If Required)
For MongoDB
sudo apt install mongodb -y
sudo systemctl start mongodb
sudo systemctl enable mongodb
For PostgreSQL
sudo apt install postgresql postgresql-contrib -y
sudo systemctl start postgresql
sudo systemctl enable postgresql
# Create database and user
sudo -u postgres psql
CREATE DATABASE your_bolt_app;
CREATE USER bolt_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE your_bolt_app TO bolt_user;
\q
Step 9: Monitoring and Maintenance
View Application Logs
pm2 logs bolt-app
Monitor Application Status
pm2 status
pm2 monit
Restart Application
pm2 restart bolt-app
Update Your Application
When you need to update your app:
git pull origin main
npm install
npm run build # if needed
pm2 restart bolt-app
Troubleshooting Common Issues
Application Won’t Start
- Check PM2 logs:
pm2 logs
- Verify environment variables
- Check port conflicts
- Ensure all dependencies are installed
502 Bad Gateway Error
- Verify your app is running:
pm2 status
- Check Nginx configuration:
sudo nginx -t
- Ensure the proxy_pass port matches your app port
Permission Issues
- Check file ownership:
ls -la
- Fix permissions:
sudo chown -R deployer:deployer ~/your-bolt-app
SSL Certificate Issues
- Renew certificates:
sudo certbot renew
- Check certificate status:
sudo certbot certificates
Performance Optimization Tips
- Enable Gzip Compression in Nginx
- Use PM2 Cluster Mode for multi-core servers
- Implement Caching strategies
- Optimize Database queries and connections
- Monitor Resource Usage with tools like htop
- Set up Log Rotation to manage disk space
Security Best Practices
- Keep your system updated:
sudo apt update && sudo apt upgrade
- Use strong passwords and SSH keys
- Configure fail2ban for brute force protection
- Regularly backup your data
- Monitor system logs for suspicious activity
- Keep your Bolt app dependencies updated
Conclusion
You now have a fully deployed Bolt application running on your Ramnode VPS! This setup provides a robust, scalable foundation for your application with proper process management, reverse proxy configuration, and security measures.
Remember to monitor your application regularly, keep everything updated, and implement proper backup strategies. With this setup, you have full control over your hosting environment and can scale your application as needed.
For additional support, refer to the Ramnode documentation and the official Bolt framework documentation. Happy deploying!