# 🚀 Laca City Website - VPS Deployment Guide This guide will help you deploy your Laca City website to a VPS with a custom domain using a single script. ## 📋 Prerequisites ### VPS Requirements - **OS**: Ubuntu 20.04+ or Debian 11+ - **RAM**: Minimum 2GB (4GB recommended) - **Storage**: Minimum 20GB SSD - **CPU**: 2+ cores recommended - **Root/Sudo access**: Required ### Domain Requirements - Domain name pointed to your VPS IP address - DNS A record: `yourdomain.com` → `your-vps-ip` - DNS A record: `www.yourdomain.com` → `your-vps-ip` ### Before You Start - [ ] VPS is running Ubuntu/Debian - [ ] You have SSH access to your VPS - [ ] Domain DNS is properly configured - [ ] You have a valid email address for SSL certificate ## 🎯 Quick Deployment ### Step 1: Upload Files to VPS ```bash # Option 1: Using SCP scp -r /path/to/your/project your-user@your-vps-ip:/home/your-user/ # Option 2: Using rsync rsync -avz --progress /path/to/your/project/ your-user@your-vps-ip:/home/your-user/project/ # Option 3: Using Git (if your project is on GitHub) git clone https://github.com/your-username/your-repo.git ``` ### Step 2: Run the Deployment Script ```bash # SSH into your VPS ssh your-user@your-vps-ip # Navigate to your project directory cd /path/to/your/project # Run the deployment script ./vps-deploy.sh ``` ### Step 3: Follow the Interactive Setup The script will ask you for: - **Domain name**: e.g., `lacacity.com` - **Email**: For SSL certificate (e.g., `admin@lacacity.com`) - **Database password**: Leave empty to auto-generate ## 🛠️ What the Script Does ### System Setup - ✅ Updates Ubuntu/Debian packages - ✅ Installs Node.js 18.x and npm - ✅ Installs PM2 process manager - ✅ Configures UFW firewall - ✅ Installs and configures Nginx - ✅ Sets up Let's Encrypt SSL certificates ### Database Setup - ✅ Installs and configures PostgreSQL - ✅ Creates database and user - ✅ Installs and configures Redis ### Application Deployment - ✅ Installs frontend and backend dependencies - ✅ Creates production environment files - ✅ Builds Next.js frontend and NestJS backend - ✅ Configures PM2 for process management - ✅ Sets up Nginx reverse proxy ### Monitoring & Maintenance - ✅ Sets up log rotation - ✅ Creates automated backup scripts - ✅ Configures SSL auto-renewal - ✅ Creates deployment update scripts ## 🔧 Post-Deployment Commands ### Check Application Status ```bash # View PM2 processes pm2 list pm2 monit # View application logs pm2 logs # Check Nginx status sudo systemctl status nginx # Check database status sudo systemctl status postgresql ``` ### Application Management ```bash # Restart applications pm2 restart all # Stop applications pm2 stop all # Reload Nginx configuration sudo systemctl reload nginx # View SSL certificate info sudo certbot certificates ``` ### Maintenance ```bash # Manual backup sudo /usr/local/bin/backup-laca-city # Deploy updates (after uploading new code) ./deploy-update.sh # View system resources htop ``` ## 🌐 Accessing Your Website After successful deployment: - **Website**: `https://yourdomain.com` - **API**: `https://yourdomain.com/api` - **SSL**: Automatically configured with Let's Encrypt ## 📁 Important File Locations ``` /var/www/laca-city/ # Main application directory ├── frontend/ # Next.js frontend ├── backend/ # NestJS backend ├── ecosystem.config.js # PM2 configuration └── deploy-update.sh # Update deployment script /etc/nginx/sites-available/laca-city # Nginx configuration /var/log/pm2/ # Application logs /var/backups/laca-city/ # Backup directory ``` ## 🔒 Security Features - ✅ HTTPS with automatic SSL renewal - ✅ Firewall configured (UFW) - ✅ Security headers in Nginx - ✅ Database with encrypted password - ✅ Environment variables for sensitive data ## 🚨 Troubleshooting ### Common Issues **Domain not accessible:** ```bash # Check DNS nslookup yourdomain.com # Check Nginx sudo nginx -t sudo systemctl status nginx # Check SSL sudo certbot certificates ``` **Applications not running:** ```bash # Check PM2 status pm2 list pm2 logs # Restart applications pm2 restart all ``` **Database connection issues:** ```bash # Check PostgreSQL sudo systemctl status postgresql # Test database connection sudo -u postgres psql -d laca_city_db ``` ### Getting Help If you encounter issues: 1. Check the logs: `pm2 logs` 2. Verify all services are running 3. Check firewall settings: `sudo ufw status` 4. Verify DNS configuration ## 🔄 Updating Your Website To deploy updates to your website: 1. Upload new files to VPS 2. Run the update script: `./deploy-update.sh` The update script will: - Create a backup - Install new dependencies - Rebuild applications - Restart services - Reload Nginx ## 💾 Backup & Recovery ### Automated Backups - Daily backups at 2 AM - Keeps 7 days of backups - Location: `/var/backups/laca-city/` ### Manual Backup ```bash sudo /usr/local/bin/backup-laca-city ``` ### Restore from Backup ```bash # Extract backup cd /var/backups/laca-city tar -xzf backup_YYYYMMDD_HHMMSS.tar.gz # Restore database sudo -u postgres psql -d laca_city_db < backup_YYYYMMDD_HHMMSS/database.sql ``` ## 📞 Support For additional support or questions about the deployment process, please check: - Application logs: `pm2 logs` - System logs: `sudo journalctl -f` - Nginx logs: `sudo tail -f /var/log/nginx/error.log` --- **🎉 Congratulations! Your Laca City website is now live and running on your VPS with a custom domain and SSL certificate!**