This guide covers different deployment options for Plants vs Zombies - Redis Edition.
- Node.js 14+ and npm 6+
- Redis 6+ server
- Linux/macOS (recommended) or Windows with WSL
# Clone and setup
git clone <repository-url>
cd plants-vs-zombies-redis
# Run cleanup and start
./deploy-cleanup.sh
./start.sh# Single container (includes Redis)
docker build -t pvz-redis .
docker run -p 3001:3001 pvz-redis
# Multi-container (recommended)
docker-compose up -d# Install dependencies
sudo apt-get update
sudo apt-get install nodejs npm redis-server
# Setup application
git clone <repository-url>
cd plants-vs-zombies-redis
npm install --production
# Configure environment
cp .env.example .env
# Edit .env with your settings
# Start services
sudo systemctl start redis
./start.shCopy .env.example to .env and configure:
# Server
NODE_ENV=production
PORT=3001
HOST=0.0.0.0
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
# Game Settings
MAX_PLAYERS_PER_GAME=4
GAME_TIMEOUT=3600000For production, configure Redis with:
# /etc/redis/redis.conf
maxmemory 512mb
maxmemory-policy allkeys-lru
appendonly yes
save 900 1
save 300 10
save 60 10000server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
# WebSocket support
location /socket.io/ {
proxy_pass http://localhost:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}# Application health
curl http://localhost:3001/api/health
# Redis health
redis-cli ping
# System monitoring
npm run logs- Health:
/api/health - Statistics:
/api/stats - Leaderboard:
/api/leaderboard/high_scores
# Allow HTTP/HTTPS
sudo ufw allow 80
sudo ufw allow 443
# Allow application port (if direct access needed)
sudo ufw allow 3001
# Redis (only if external access needed)
sudo ufw allow from trusted_ip to any port 6379Use Let's Encrypt with Certbot:
sudo apt-get install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com# Install PM2
npm install -g pm2
# Create ecosystem file
cat > ecosystem.config.js << EOF
module.exports = {
apps: [{
name: 'plants-vs-zombies',
script: 'server.js',
instances: 1,
exec_mode: 'fork',
env: {
NODE_ENV: 'production',
PORT: 3001
},
error_file: 'logs/error.log',
out_file: 'logs/out.log',
log_file: 'logs/combined.log',
time: true
}]
};
EOF
# Start application
pm2 start ecosystem.config.js
pm2 save
pm2 startup# Create service file
sudo tee /etc/systemd/system/plants-vs-zombies.service << EOF
[Unit]
Description=Plants vs Zombies Redis Edition
After=network.target redis.service
[Service]
Type=simple
User=www-data
WorkingDirectory=/path/to/plants-vs-zombies-redis
ExecStart=/usr/bin/node server.js
Restart=always
RestartSec=10
Environment=NODE_ENV=production
Environment=PORT=3001
[Install]
WantedBy=multi-user.target
EOF
# Enable and start
sudo systemctl enable plants-vs-zombies
sudo systemctl start plants-vs-zombies# Create backup script
cat > backup.sh << 'EOF'
#!/bin/bash
DATE=$(date +%Y%m%d-%H%M%S)
mkdir -p backups
redis-cli --rdb backups/redis-backup-$DATE.rdb
find backups -name "*.rdb" -mtime +7 -delete
EOF
chmod +x backup.sh
# Add to crontab
echo "0 2 * * * /path/to/backup.sh" | crontab -Redis Connection Failed
# Check Redis status
sudo systemctl status redis
redis-cli ping
# Restart Redis
sudo systemctl restart redisPort Already in Use
# Find process using port
sudo lsof -i :3001
sudo kill -9 <PID>Memory Issues
# Check memory usage
free -h
redis-cli info memory
# Configure Redis memory limit
redis-cli config set maxmemory 256mb# Application logs
tail -f logs/server.log
# System logs
sudo journalctl -u plants-vs-zombies -f
# Redis logs
sudo tail -f /var/log/redis/redis-server.log# Redis configuration for production
echo "maxmemory 512mb" >> /etc/redis/redis.conf
echo "maxmemory-policy allkeys-lru" >> /etc/redis/redis.conf
echo "tcp-keepalive 60" >> /etc/redis/redis.conf# Set Node.js memory limit
export NODE_OPTIONS="--max-old-space-size=512"
# Enable production optimizations
export NODE_ENV=production# Backup current version
cp -r /path/to/app /path/to/app-backup
# Pull updates
git pull origin main
# Install dependencies
npm install --production
# Restart application
pm2 restart plants-vs-zombies# Enable maintenance mode (nginx)
touch /var/www/maintenance.flag
# Disable maintenance mode
rm /var/www/maintenance.flagFor deployment issues:
- Check logs:
npm run logs - Verify health:
curl http://localhost:3001/api/health - Test Redis:
redis-cli ping - Review configuration files
- Check firewall and network settings
After deployment, your game will be available at:
- Game:
http://your-domain.com - API:
http://your-domain.com/api - Health:
http://your-domain.com/api/health - Stats:
http://your-domain.com/api/stats
Enjoy your Plants vs Zombies - Redis Edition deployment! π»π§ββοΈ