Overview
Deploying to a Virtual Private Server (VPS) enables true 24/7 automation without keeping your personal computer running. This is the recommended option for:
Production YouTube channels
Consistent daily uploads
Multiple channels management
Professional operations
VPS deployment costs approximately $5-20/month depending on your provider and resource needs.
VPS Provider Recommendations
DigitalOcean $6/month - 1 GB RAM, 1 vCPU
Easy to use
Great documentation
1-click deployments
Linode (Akamai) $5/month - 1 GB RAM, 1 vCPU
Excellent performance
Strong network
Developer-friendly
Vultr $6/month - 1 GB RAM, 1 vCPU
Global locations
High-frequency CPU options
Competitive pricing
Hetzner €4.15/month - 2 GB RAM, 1 vCPU
Best price/performance
European datacenters
Excellent value
Server Requirements
Minimum Specifications
Component Minimum Recommended CPU 1 vCPU 2 vCPUs RAM 1 GB 2 GB Storage 10 GB SSD 25 GB SSD Bandwidth 500 GB/month 1 TB/month OS Ubuntu 20.04+ Ubuntu 22.04 LTS
Estimated Costs
Basic Setup
Professional Setup
Multi-Channel Setup
$6-8/month total
VPS: $5-6/month
Google Gemini API: Free
1-2 videos per day
Perfect for starting out
$15-25/month total
VPS: $12-15/month (2GB RAM)
OpenAI API: $10/month
3-5 videos per day
Better performance
$30-50/month total
VPS: $20-30/month (4GB RAM)
OpenAI API: $20/month
Multiple channels
High volume production
Deployment Steps
Create VPS Instance
Choose your provider and create a new droplet/instance: DigitalOcean Example:
Sign up at digitalocean.com
Click “Create” → “Droplets”
Choose Ubuntu 22.04 LTS
Select Basic plan ($6/month)
Choose datacenter region (closest to your target audience)
Add SSH key for secure access
Click “Create Droplet”
Save your server’s IP address - you’ll need it for SSH access
Connect via SSH
Connect to your VPS: For Windows users, use PuTTY or Windows Terminal.
Update System Packages
apt update && apt upgrade -y
Install Node.js 18+
Install Node.js using NodeSource: curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
apt install -y nodejs
Verify installation: node --version # Should show v18.x.x or higher
npm --version
Install PM2 Process Manager
PM2 keeps your application running and restarts it if it crashes:
Create Application User
For security, don’t run as root: adduser youtube-agent
usermod -aG sudo youtube-agent
su - youtube-agent
Clone Repository
cd ~
git clone https://github.com/darkzOGx/youtube-automation-agent.git
cd youtube-automation-agent
Install Dependencies
The --production flag skips dev dependencies, saving disk space.
Configure Environment
Create and edit the environment file: cp .env.example .env
nano .env
Update with your credentials: NODE_ENV=production
PORT=3456
LOG_LEVEL=info
# AI Provider
OPENAI_API_KEY=your-openai-key
# OR
GEMINI_API_KEY=your-gemini-key
# Channel Settings
CHANNEL_NAME=Your Channel Name
DEFAULT_AUTHOR=Your Name
TARGET_AUDIENCE=Your target audience
# YouTube Settings
YOUTUBE_REGION=US
DEFAULT_PRIVACY_STATUS=public
# Security
JWT_SECRET=generate-secure-random-string-here
Save with Ctrl+X, then Y, then Enter
Upload YouTube Credentials
Transfer your credentials.json file from local machine to VPS: From your local machine: scp config/credentials.json youtube-agent@your-server-ip:~/youtube-automation-agent/config/
Or create it directly on the VPS: nano config/credentials.json
# Paste your credentials JSON
# Save with Ctrl+X, Y, Enter
Run Initial Setup
This initializes the database and verifies your configuration.
Start with PM2
Start the application with PM2: pm2 start index.js --name youtube-agent
Also start the scheduler: pm2 start schedules/daily-automation.js --name youtube-scheduler
Save the PM2 configuration:
Configure Auto-Start on Boot
Make PM2 restart on server reboot: Copy and run the command that PM2 outputs.
Configure Firewall
Allow necessary ports: # Switch back to root
exit
# Configure UFW firewall
ufw allow 22/tcp # SSH
ufw allow 3456/tcp # Application port
ufw enable
Make sure to allow SSH (port 22) before enabling the firewall, or you’ll lock yourself out!
Setting Up Nginx Reverse Proxy (Optional)
For production deployments, use Nginx as a reverse proxy:
Configure Nginx
Create a new site configuration: nano /etc/nginx/sites-available/youtube-agent
Add this configuration: server {
listen 80 ;
server_name your-domain.com; # Or use server IP
location / {
proxy_pass http://localhost:3456;
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 ;
proxy_set_header X-Real-IP $ remote_addr ;
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for ;
}
}
Enable Site
ln -s /etc/nginx/sites-available/youtube-agent /etc/nginx/sites-enabled/
nginx -t # Test configuration
systemctl restart nginx
Update Firewall
ufw allow 'Nginx Full'
ufw delete allow 3456/tcp # No longer needed
SSL/HTTPS Setup with Let’s Encrypt (Optional)
Secure your dashboard with HTTPS:
# Install Certbot
apt install -y certbot python3-certbot-nginx
# Obtain certificate
certbot --nginx -d your-domain.com
# Auto-renewal is configured automatically
Management Commands
PM2 Commands
# View status
pm2 status
# View logs
pm2 logs youtube-agent
pm2 logs youtube-scheduler
# Restart application
pm2 restart youtube-agent
# Stop application
pm2 stop youtube-agent
# Monitor resources
pm2 monit
# View detailed info
pm2 info youtube-agent
System Monitoring
# Check disk usage
df -h
# Check memory usage
free -h
# Check CPU and processes
top
# Or use htop (install with: apt install htop)
htop
# Check network connections
netstat -tulpn | grep 3456
Database Backups
Automate database backups:
Create Backup Script
nano ~/backup-youtube-agent.sh
Add: #!/bin/bash
BACKUP_DIR = " $HOME /backups"
DATE = $( date +%Y%m%d_%H%M%S )
mkdir -p $BACKUP_DIR
# Backup database and config
cd ~/youtube-automation-agent
tar -czf $BACKUP_DIR /youtube-agent- $DATE .tar.gz \
data/ config/ .env
# Keep only last 7 days of backups
find $BACKUP_DIR -name "youtube-agent-*.tar.gz" -mtime +7 -delete
echo "Backup completed: youtube-agent- $DATE .tar.gz"
Make executable: chmod +x ~/backup-youtube-agent.sh
Schedule with Cron
Add daily backup at 3 AM: 0 3 * * * /home/youtube-agent/backup-youtube-agent.sh >> /home/youtube-agent/backup.log 2>&1
Updating the Application
# Navigate to app directory
cd ~/youtube-automation-agent
# Stop the application
pm2 stop all
# Backup current version
tar -czf ~/youtube-agent-backup-pre-update.tar.gz .
# Pull latest changes
git pull origin main
# Install any new dependencies
npm install --production
# Restart application
pm2 restart all
# Check logs for errors
pm2 logs
Monitoring and Alerts
Set Up Email Alerts
Install and configure system mail:
apt install -y mailutils
# Test email
echo "Test from YouTube Agent VPS" | mail -s "Test" your@email.com
PM2 Monitoring
PM2 can send alerts on crashes:
# Install PM2 notification module
pm2 install pm2-slack # For Slack notifications
# Or
pm2 install pm2-discord # For Discord notifications
Troubleshooting
Application Won’t Start
# Check PM2 logs
pm2 logs youtube-agent --lines 100
# Check system logs
journalctl -u youtube-agent -n 50
# Verify Node.js version
node --version
# Check for port conflicts
sudo netstat -tulpn | grep 3456
High Memory Usage
# Check memory
free -h
# Restart application to clear memory
pm2 restart youtube-agent
# Consider upgrading to 2GB RAM if consistently high
Database Locked Errors
# Stop all processes
pm2 stop all
# Remove lock files
rm -f data/ * .db-shm data/ * .db-wal
# Restart
pm2 restart all
YouTube API Authentication Issues
# Remove old tokens
rm -f data/youtube-oauth-token.json
# Re-authenticate
npm run credentials:setup
# Restart application
pm2 restart youtube-agent
Security Best Practices
Keep System Updated
# Set up automatic security updates
apt install -y unattended-upgrades
dpkg-reconfigure --priority=low unattended-upgrades
Use SSH Keys Only
Disable password authentication: nano /etc/ssh/sshd_config
Set: PasswordAuthentication no
PermitRootLogin no
Restart SSH:
Install Fail2Ban
Protect against brute force attacks: apt install -y fail2ban
systemctl enable fail2ban
systemctl start fail2ban
Restrict File Permissions
chmod 600 .env
chmod 600 config/credentials.json
chmod 700 data/
Enable Node.js Production Mode
Already set in .env:
Optimize PM2 Settings
pm2 start index.js --name youtube-agent \
--max-memory-restart 500M \
--log-date-format= "YYYY-MM-DD HH:mm:ss Z"
Database Optimization
# Run VACUUM on SQLite database monthly
sqlite3 data/youtube-automation.db "VACUUM;"
Cost Optimization Tips
Use Gemini API Free tier handles most workloads
Smaller VPS 1GB RAM sufficient for 1-2 videos/day
Reserved Instances Some providers offer discounts for annual payment
Optimize Schedules Reduce frequency if hitting API limits
Next Steps
Cloud Deployment Scale to cloud platforms for enterprise needs
Monitoring Set up advanced monitoring and analytics
Configuration Fine-tune your deployment
API Reference Integrate with your custom tools