From Zero to Deployed: Setting Up a Web App on a VPS

Deploying a web application on a VPS might seem intimidating at first, but once you break it down, it’s a straightforward process that gives you full control over your environment. Whether you’re launching a personal project, startup MVP, or client site, this guide walks you through everything from spinning up your VPS to serving your app to the world.

Step 1: Choose Your VPS and Stack

Start by choosing a VPS provider. Look for reliable uptime, SSD storage, decent RAM (at least 1–2GB for small apps), and data centers close to your target audience. Providers like DigitalOcean, Linode, Vultr, or Hetzner are popular for good reason.

Then, choose your tech stack. For example:

  • Node.js for real-time apps

  • Python (Django/Flask) for API-driven services

  • PHP (Laravel) for traditional web apps

  • Ruby on Rails for full-stack MVC apps

Pick a stack you’re comfortable with or one that suits the app’s needs.

Step 2: Connect to Your VPS and Set Up Basics

After launching your VPS, you’ll receive an IP address and root login. Connect via SSH:

ssh root@your_vps_ip

Update the system:

apt update && apt upgrade -y

Create a new user to avoid running as root:

adduser deployer
usermod -aG sudo deployer

Log in as your new user:

su - deployer

Install essential packages:

sudo apt install git curl ufw unzip -y

Set up a firewall:

sudo ufw allow OpenSSH
sudo ufw allow http
sudo ufw allow https
sudo ufw enable

Step 3: Install Your Runtime Environment

Based on your app, install the required runtime:

  • Node.js: curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && sudo apt install -y nodejs

  • Python: sudo apt install python3-pip python3-venv -y

  • PHP: sudo apt install php php-cli php-mbstring php-xml php-curl unzip -y

  • Ruby: Use RVM or rbenv to manage versions

Also install your database if needed:

sudo apt install postgresql postgresql-contrib  # For PostgreSQL
sudo apt install mysql-server                   # For MySQL

Secure your database, create a user, and set up your app’s database.

Step 4: Clone and Set Up Your App

Clone your app repository:

git clone https://github.com/yourname/yourapp.git
cd yourapp

Install dependencies:

  • Node.js: npm install

  • Python: python3 -m venv venv && source venv/bin/activate && pip install -r requirements.txt

  • PHP: composer install

Create your .env file and configure database credentials, secret keys, ports, etc.

Run database migrations and seed data if needed.


Step 5: Set Up a Process Manager

Keep your app running even after logout or reboot. Use a process manager:

  • Node.js: pm2 → npm install -g pm2

  • Python: gunicorn → pip install gunicorn

  • Ruby: puma or unicorn

Start the app:

pm2 start app.js         # Node.js
pm2 save && pm2 startup

Set up automatic restarts on failure and after VPS reboot.

Step 6: Configure a Web Server and Reverse Proxy

Install NGINX:

sudo apt install nginx -y

Create a new config in /etc/nginx/sites-available/yourapp:

server {
    listen 80;
    server_name yourdomain.com;

    location / {
        proxy_pass http://localhost:3000;  # Adjust for your app’s port
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Enable your site:

sudo ln -s /etc/nginx/sites-available/yourapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Step 7: Add HTTPS with Let’s Encrypt

Install Certbot:

sudo apt install certbot python3-certbot-nginx -y

Run it:

sudo certbot --nginx -d yourdomain.com

Set auto-renew:

sudo certbot renew --dry-run

Now your app runs over HTTPS, which boosts SEO, security, and trust.

Step 8: Test Everything

Visit your domain or IP and make sure your app is live. Test all routes, form submissions, APIs, and database actions. Check your logs:

pm2 logs    # Node.js
journalctl -u nginx

Monitor CPU, RAM, and disk usage using htop or top. Fix anything that looks off.

Step 9: Keep It Secure and Maintained

  • Disable root SSH access

  • Use SSH keys

  • Keep your stack and dependencies updated

  • Use UFW and fail2ban to protect against brute-force attacks

  • Set up automatic backups