Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

🛠️ VPS Interactive Setup Script Documentation

Overview

This script is designed to fully configure a fresh VPS server with essential tools like Node.js (via NVM), PM2, Nginx, and project-specific deployment for Node.js, React, Static, Laravel, or Python apps. It includes interactive prompts, robust error handling, retry/revert mechanisms, and clean user experience.


📋 Script Features

  • Interactive CLI prompts
  • NVM-based Node.js installation (LTS or manual)
  • PM2 setup for background process management
  • Nginx installation and project-specific configuration
  • Multi-project directory support
  • Rollback support for failed steps
  • Safe system updates and user creation
  • PM2 startup configuration for boot persistence
  • Modular and retry-safe

🚀 Step-by-Step Implementation

1. 🔄 System Update

  • Updates package list and upgrades packages.
  • Prompts user for confirmation.
  • Retries on error or skips if declined.

2. 👤 Create a New User

  • Prompts: "Do you want to create a new sudo user?"
  • Adds user and sets password.
  • Adds user to sudo group.
  • Gracefully skips or retries on error.

3. 🧰 Install Essential Packages

Installs:

  • curl
  • git
  • build-essential
  • ufw
  • unzip
  • software-properties-common
  • And others...

4. ⚙️ Install NVM and Node.js

  • Installs NVM using official script.
  • Prompts:
    • “Use latest LTS version?” or
    • “Manually enter Node.js version”
  • Validates entered version against nvm ls-remote
  • Retries on invalid version.
  • Sets installed version as default.

5. 🔁 Install PM2 Globally

  • Installs PM2 using npm install -g pm2
  • Confirms successful installation
  • Retries if needed

6. 🌐 Install and Configure Nginx

  • Installs Nginx via apt
  • Checks status with systemctl
  • Prompts to retry or fix if service doesn't start

7. 📁 Create Project Directories

  • Loop:
    • Asks: “Create a new project directory?”
    • Prompts for directory name (e.g., my-app)
    • Creates under /var/www/
  • Repeats until user opts out

8. 🏗️ Configure a Project

  • Prompts:
    • Which directory to configure
    • Type of project:
      • node
      • react
      • static
      • laravel
      • python
  • Based on type:
    • Node.js → prompt port number
    • React/Static → configure to serve index.html
    • Laravel → serve from public/ folder
    • Python → prompt for gunicorn port/command
  • Auto-generate Nginx config
  • Prompt: “Apply this config now?”

9. 🔍 Test and Reload Nginx

  • Runs nginx -t
  • On failure:
    • Prompt to retry or revert changes
  • On success:
    • Reloads Nginx config

10. ⚡ Setup PM2 for a Project

  • Prompt: “Do you want to setup PM2 for a project?”
  • Asks:
    • Directory to run from
    • PM2 start command (e.g., npm run start, gunicorn app:app)
  • Starts process via PM2
  • Optionally creates ecosystem file

11. ♻️ Enable PM2 Startup

  • Run pm2 startup to generate startup command
  • Runs pm2 save to persist current processes
  • Ensures processes restart on server boot

12. ✅ Final Summary

Displays:

  • Created user info
  • Installed tools
  • Project directories
  • Nginx and PM2 configuration status
  • Next steps or access URLs if applicable

🔄 Error Handling & Rollback

  • Every step checks success
  • If a step fails:
    • Prompt: Retry / Revert / Skip
  • Rollback:
    • Removes files/configs created in the step
    • Reverts packages if required (e.g., uninstall Nginx)

📦 Optional Add-Ons (Future Modules)

  • SSL via Let’s Encrypt (certbot)
  • Firewall setup with ufw
  • Fail2ban for brute-force protection
  • Docker and Docker Compose
  • Database setup (MySQL, PostgreSQL)

🧪 Example Prompt Flow

➤ Do you want to install Node.js via NVM? [Y/n]
➤ Use LTS version or enter a specific version? [lts/manual]
➤ Enter Node.js version (e.g., 18.18.0): 17.2.1
⛔ Version not found. Try again.
...
➤ Create a new project directory? [Y/n]
➤ Enter project directory name: my-app
...
➤ Which project type is this? [node/react/static/laravel/python]
➤ Enter port number to forward for Node.js: 3000
...
➤ Nginx config successful. Reload now? [Y/n]

✅ Requirements

  • Ubuntu 22.04 or compatible Debian-based distro
  • Root SSH access (or sudo user)

About

This script is designed to fully configure a fresh VPS server with essential tools like Node.js (via NVM), PM2, Nginx, and project-specific deployment for Node.js, React, Static, Laravel, or Python apps. It includes interactive prompts, robust error handling, retry/revert mechanisms, and clean user experience.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages