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.
- 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
- Updates package list and upgrades packages.
- Prompts user for confirmation.
- Retries on error or skips if declined.
- 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.
Installs:
curlgitbuild-essentialufwunzipsoftware-properties-common- And others...
- 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.
- Installs PM2 using
npm install -g pm2 - Confirms successful installation
- Retries if needed
- Installs Nginx via
apt - Checks status with
systemctl - Prompts to retry or fix if service doesn't start
- Loop:
- Asks: “Create a new project directory?”
- Prompts for directory name (e.g.,
my-app) - Creates under
/var/www/
- Repeats until user opts out
- Prompts:
- Which directory to configure
- Type of project:
nodereactstaticlaravelpython
- 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?”
- Runs
nginx -t - On failure:
- Prompt to retry or revert changes
- On success:
- Reloads Nginx config
- 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
- Run
pm2 startupto generate startup command - Runs
pm2 saveto persist current processes - Ensures processes restart on server boot
Displays:
- Created user info
- Installed tools
- Project directories
- Nginx and PM2 configuration status
- Next steps or access URLs if applicable
- 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)
- SSL via Let’s Encrypt (
certbot) - Firewall setup with
ufw - Fail2ban for brute-force protection
- Docker and Docker Compose
- Database setup (MySQL, PostgreSQL)
➤ 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]
- Ubuntu 22.04 or compatible Debian-based distro
- Root SSH access (or sudo user)