Skip to content

Latest commit

Β 

History

History
1040 lines (782 loc) Β· 24.6 KB

File metadata and controls

1040 lines (782 loc) Β· 24.6 KB

πŸ’‘ PUQcloud Script Usage Examples

Practical examples and usage scenarios for PUQcloud installation and management scripts.

🎯 Basic Usage Scenarios

1. πŸš€ Fresh Server Installation

For a completely new server:

#!/bin/bash
# Fresh installation script

# Download all scripts
wget https://raw.githubusercontent.com/puqcloud/PUQcloud-Scripts/main/Debian_Ubuntu/install.sh
wget https://raw.githubusercontent.com/puqcloud/PUQcloud-Scripts/main/Debian_Ubuntu/phpmyadmin.sh
wget https://raw.githubusercontent.com/puqcloud/PUQcloud-Scripts/main/Debian_Ubuntu/delete_and_clear_databases.sh

# Make executable
chmod +x *.sh

# Install PUQcloud
sudo ./install.sh example.com admin@example.com SecurePass123 "John Admin"

# Install phpMyAdmin (optional)
sudo ./phpmyadmin.sh

echo "βœ… Fresh installation completed!"
echo "🌐 Web interface: https://example.com"
echo "πŸ—„οΈ phpMyAdmin: https://phpmyadmin.example.com"

2. πŸ”„ Update Existing Installation

Update PUQcloud to the latest version:

#!/bin/bash
# Update script

echo "πŸ”„ Starting PUQcloud update..."

# Run update
sudo ./install.sh
# Choose "update" when prompted

echo "βœ… Update completed!"

# Check status
cd /var/www/puqcloud
php artisan --version
php artisan horizon:status

3. 🧹 Complete System Reset

Full cleanup and reinstallation:

#!/bin/bash
# Complete reset script

echo "⚠️  WARNING: This will delete ALL databases!"
read -p "Continue? Type 'YES' to confirm: " confirm

if [ "$confirm" = "YES" ]; then
    echo "🧹 Cleaning databases..."
    sudo ./delete_and_clear_databases.sh
    
    echo "πŸš€ Installing PUQcloud..."
    sudo ./install.sh production.example.com admin@example.com NewPass123 "System Admin"
    
    echo "πŸ—„οΈ Installing phpMyAdmin..."
    sudo ./phpmyadmin.sh
    
    echo "βœ… Complete reset finished!"
else
    echo "❌ Operation cancelled"
fi

🏒 Production Scenarios

4. πŸ“Š Production Server Deployment

Enterprise-grade installation with monitoring:

#!/bin/bash
# Production deployment script

LOG_FILE="/var/log/puqcloud_deployment_$(date +%Y%m%d_%H%M%S).log"
DOMAIN="app.company.com"
ADMIN_EMAIL="admin@company.com"
ADMIN_PASS="$(openssl rand -base64 32)"
ADMIN_NAME="System Administrator"

{
    echo "=== PUQcloud Production Deployment ==="
    echo "Started: $(date)"
    echo "Domain: $DOMAIN"
    echo "Admin Email: $ADMIN_EMAIL"
    echo "Generated Password: $ADMIN_PASS"
    echo ""
    
    # Update system
    echo "πŸ“¦ Updating system packages..."
    apt update && apt upgrade -y
    
    # Install PUQcloud
    echo "πŸš€ Installing PUQcloud..."
    ./install.sh "$DOMAIN" "$ADMIN_EMAIL" "$ADMIN_PASS" "$ADMIN_NAME"
    
    # Install phpMyAdmin
    echo "πŸ—„οΈ Installing phpMyAdmin..."
    ./phpmyadmin.sh
    
    # Security hardening
    echo "πŸ”’ Applying security settings..."
    
    # Disable password authentication for SSH
    sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
    systemctl restart sshd
    
    # Configure firewall
    ufw --force enable
    ufw allow ssh
    ufw allow http
    ufw allow https
    
    # Set up monitoring
    echo "πŸ“Š Setting up monitoring..."
    
    # Install log rotation
    cat > /etc/logrotate.d/puqcloud << 'EOF'
/var/www/puqcloud/storage/logs/*.log {
    daily
    missingok
    rotate 30
    compress
    notifempty
    create 644 www-data www-data
}
EOF
    
    echo "βœ… Production deployment completed!"
    echo "Admin password: $ADMIN_PASS"
    
} 2>&1 | tee "$LOG_FILE"

echo ""
echo "πŸ“‹ Deployment log saved to: $LOG_FILE"
echo "πŸ”‘ IMPORTANT: Save the admin password securely!"

5. πŸš€ Multi-Server Deployment

Deploy PUQcloud on multiple servers:

#!/bin/bash
# Multi-server deployment script

SERVERS=(
    "server1.example.com:app1.example.com"
    "server2.example.com:app2.example.com"
    "server3.example.com:app3.example.com"
)

ADMIN_EMAIL="admin@example.com"
ADMIN_NAME="Multi-Server Admin"

for server_config in "${SERVERS[@]}"; do
    IFS=':' read -r server_ip domain <<< "$server_config"
    
    echo "πŸš€ Deploying to $server_ip ($domain)..."
    
    # Generate unique password for each server
    password=$(openssl rand -base64 16)
    
    # Copy scripts to server
    scp install.sh phpmyadmin.sh root@$server_ip:/tmp/
    
    # Run installation
    ssh root@$server_ip << EOF
        cd /tmp
        chmod +x *.sh
        ./install.sh "$domain" "$ADMIN_EMAIL" "$password" "$ADMIN_NAME"
        ./phpmyadmin.sh
EOF
    
    echo "βœ… $domain deployed successfully"
    echo "Password: $password"
    echo ""
done

echo "πŸŽ‰ Multi-server deployment completed!"

πŸ§ͺ Development Scenarios

6. πŸ’» Development Environment Setup

Quick setup for development:

#!/bin/bash
# Development environment script

DEV_DOMAIN="puqcloud.local"
DEV_EMAIL="dev@localhost"
DEV_PASS="dev123"
DEV_NAME="Developer"

echo "πŸ› οΈ Setting up development environment..."

# Add domain to hosts file
echo "127.0.0.1 $DEV_DOMAIN" >> /etc/hosts
echo "127.0.0.1 phpmyadmin.$DEV_DOMAIN" >> /etc/hosts

# Install with development settings
sudo ./install.sh "$DEV_DOMAIN" "$DEV_EMAIL" "$DEV_PASS" "$DEV_NAME"

# Enable debug mode
cd /var/www/puqcloud
sed -i 's/APP_DEBUG=.*/APP_DEBUG=true/' .env
sed -i 's/APP_ENV=.*/APP_ENV=local/' .env

# Install development dependencies
composer install --dev
npm install --dev

# Install phpMyAdmin
sudo ./phpmyadmin.sh

echo "βœ… Development environment ready!"
echo "🌐 Application: http://$DEV_DOMAIN"
echo "πŸ—„οΈ phpMyAdmin: http://phpmyadmin.$DEV_DOMAIN"
echo "πŸ”‘ Login: $DEV_EMAIL / $DEV_PASS"

7. πŸ”„ Testing Environment Reset

Reset testing environment daily:

#!/bin/bash
# Daily testing reset script (for cron)

BACKUP_DIR="/backups/puqcloud"
DATE=$(date +%Y%m%d)
TEST_DOMAIN="test.puqcloud.local"

echo "πŸ”„ Daily testing environment reset - $DATE"

# Create backup of current state
mkdir -p "$BACKUP_DIR"
mysqldump --all-databases > "$BACKUP_DIR/test_backup_$DATE.sql"
tar -czf "$BACKUP_DIR/files_backup_$DATE.tar.gz" /var/www/puqcloud

# Reset databases
./delete_and_clear_databases.sh << 'EOF'
root_password
EOF

# Fresh installation
./install.sh "$TEST_DOMAIN" "test@localhost" "test123" "Test Admin"

# Load test data
cd /var/www/puqcloud
php artisan db:seed --class=TestDataSeeder

echo "βœ… Testing environment reset completed!"

# Clean old backups (keep last 7 days)
find "$BACKUP_DIR" -name "*backup*" -mtime +7 -delete

🐳 Docker and Containerization

8. 🐳 Docker-based Deployment

Create containerized PUQcloud:

#!/bin/bash
# Docker deployment script

# Create Dockerfile
cat > Dockerfile << 'EOF'
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get update && apt-get install -y \
    curl wget git sudo \
    && rm -rf /var/lib/apt/lists/*

# Copy scripts
COPY install.sh phpmyadmin.sh /opt/puqcloud/
WORKDIR /opt/puqcloud

# Make scripts executable
RUN chmod +x *.sh

# Install PUQcloud
RUN ./install.sh container.local admin@container.local admin123 "Container Admin"

# Expose ports
EXPOSE 80 443

# Start services
CMD service mysql start && \
    service redis-server start && \
    service php8.2-fpm start && \
    service nginx start && \
    service supervisor start && \
    tail -f /var/log/nginx/access.log
EOF

# Build and run container
docker build -t puqcloud:latest .
docker run -d -p 8080:80 -p 8443:443 --name puqcloud-container puqcloud:latest

echo "βœ… PUQcloud container deployed!"
echo "🌐 Access at: http://localhost:8080"

πŸ€– Automation and CI/CD

9. πŸ”„ GitHub Actions Deployment

Automated deployment via GitHub Actions:

# .github/workflows/deploy.yml
name: Deploy PUQcloud

on:
  push:
    branches: [ main ]
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest
    
    steps:
    - uses: actions/checkout@v3
    
    - name: Deploy to server
      uses: appleboy/ssh-action@v0.1.5
      with:
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USERNAME }}
        key: ${{ secrets.SSH_KEY }}
        script: |
          cd /opt/puqcloud-scripts
          git pull origin main
          
          # Run update
          sudo ./install.sh
          
          # Check status
          cd /var/www/puqcloud
          php artisan horizon:status
          
          # Send notification
          curl -X POST -H 'Content-type: application/json' \
            --data '{"text":"PUQcloud deployment completed successfully!"}' \
            ${{ secrets.SLACK_WEBHOOK }}

10. πŸ“Š Automated Testing and Monitoring

Comprehensive testing script:

#!/bin/bash
# Automated testing script

TEST_LOG="/var/log/puqcloud_test_$(date +%Y%m%d_%H%M%S).log"

{
    echo "=== PUQcloud Automated Tests ==="
    echo "Started: $(date)"
    echo ""
    
    # Test 1: Service Status
    echo "πŸ” Test 1: Service Status"
    services=(nginx php8.2-fpm mariadb redis-server supervisor)
    for service in "${services[@]}"; do
        if systemctl is-active --quiet "$service"; then
            echo "βœ… $service: Running"
        else
            echo "❌ $service: Not running"
        fi
    done
    echo ""
    
    # Test 2: Web Response
    echo "πŸ” Test 2: Web Server Response"
    response=$(curl -s -o /dev/null -w "%{http_code}" http://localhost)
    if [ "$response" = "200" ]; then
        echo "βœ… Web server: Responding (HTTP $response)"
    else
        echo "❌ Web server: Not responding (HTTP $response)"
    fi
    echo ""
    
    # Test 3: Database Connection
    echo "πŸ” Test 3: Database Connection"
    if mysql -e "SELECT 1" &>/dev/null; then
        echo "βœ… Database: Connected"
    else
        echo "❌ Database: Connection failed"
    fi
    echo ""
    
    # Test 4: Laravel Application
    echo "πŸ” Test 4: Laravel Application"
    cd /var/www/puqcloud
    if php artisan about &>/dev/null; then
        echo "βœ… Laravel: Application working"
    else
        echo "❌ Laravel: Application error"
    fi
    echo ""
    
    # Test 5: Horizon Status
    echo "πŸ” Test 5: Horizon Queue System"
    horizon_status=$(php artisan horizon:status 2>/dev/null)
    if echo "$horizon_status" | grep -q "running"; then
        echo "βœ… Horizon: Running"
    else
        echo "❌ Horizon: Not running"
    fi
    echo ""
    
    # Test 6: SSL Certificate
    echo "πŸ” Test 6: SSL Certificate"
    if [ -f /etc/letsencrypt/live/*/fullchain.pem ]; then
        cert_exp=$(openssl x509 -enddate -noout -in /etc/letsencrypt/live/*/fullchain.pem | cut -d= -f2)
        echo "βœ… SSL: Certificate found (expires: $cert_exp)"
    else
        echo "⚠️  SSL: No Let's Encrypt certificate found"
    fi
    echo ""
    
    echo "=== Test Summary ==="
    echo "Completed: $(date)"
    
} 2>&1 | tee "$TEST_LOG"

echo "πŸ“‹ Test log saved to: $TEST_LOG"

# Send results to monitoring system (optional)
# curl -X POST -H "Content-Type: application/json" \
#   -d @"$TEST_LOG" \
#   https://monitoring.example.com/api/test-results

πŸ”§ Maintenance and Backup

11. πŸ’Ύ Automated Backup Script

Complete backup solution:

#!/bin/bash
# Automated backup script

BACKUP_DIR="/backups/puqcloud"
DATE=$(date +%Y%m%d_%H%M%S)
RETENTION_DAYS=30

echo "πŸ’Ύ Starting PUQcloud backup - $DATE"

# Create backup directory
mkdir -p "$BACKUP_DIR"

# Database backup
echo "πŸ“Š Backing up databases..."
mysqldump --all-databases --single-transaction --routines --triggers > "$BACKUP_DIR/databases_$DATE.sql"

# Files backup
echo "πŸ“ Backing up files..."
tar -czf "$BACKUP_DIR/files_$DATE.tar.gz" \
    /var/www/puqcloud \
    /etc/nginx/sites-available \
    /etc/php/8.2 \
    /etc/letsencrypt

# Configuration backup
echo "βš™οΈ Backing up configurations..."
{
    echo "=== System Information ==="
    hostnamectl
    echo ""
    
    echo "=== Service Status ==="
    systemctl status nginx php8.2-fpm mariadb redis-server supervisor --no-pager
    echo ""
    
    echo "=== PUQcloud Version ==="
    cd /var/www/puqcloud && php artisan --version
    echo ""
    
    echo "=== Installed Packages ==="
    dpkg -l | grep -E "(nginx|php|mysql|redis)"
    
} > "$BACKUP_DIR/system_info_$DATE.txt"

# Compress everything
echo "πŸ—œοΈ Compressing backup..."
cd "$BACKUP_DIR"
tar -czf "puqcloud_complete_backup_$DATE.tar.gz" \
    "databases_$DATE.sql" \
    "files_$DATE.tar.gz" \
    "system_info_$DATE.txt"

# Remove individual files
rm "databases_$DATE.sql" "files_$DATE.tar.gz" "system_info_$DATE.txt"

# Clean old backups
echo "🧹 Cleaning old backups..."
find "$BACKUP_DIR" -name "puqcloud_complete_backup_*.tar.gz" -mtime +$RETENTION_DAYS -delete

# Calculate backup size
backup_size=$(du -h "$BACKUP_DIR/puqcloud_complete_backup_$DATE.tar.gz" | cut -f1)

echo "βœ… Backup completed!"
echo "πŸ“¦ Backup file: puqcloud_complete_backup_$DATE.tar.gz"
echo "πŸ“ Backup size: $backup_size"

# Optional: Upload to cloud storage
# aws s3 cp "$BACKUP_DIR/puqcloud_complete_backup_$DATE.tar.gz" s3://your-backup-bucket/

12. πŸ”„ System Maintenance Script

Regular maintenance tasks:

#!/bin/bash
# System maintenance script

echo "πŸ”§ Starting PUQcloud maintenance..."

# Update system packages
echo "πŸ“¦ Updating system packages..."
apt update && apt upgrade -y

# Clean package cache
apt autoremove -y && apt autoclean

# Optimize database
echo "πŸ—„οΈ Optimizing databases..."
cd /var/www/puqcloud
php artisan optimize
mysqlcheck --optimize --all-databases

# Clear application cache
echo "🧹 Clearing application cache..."
php artisan cache:clear
php artisan config:clear
php artisan view:clear
php artisan route:clear

# Restart services
echo "πŸ”„ Restarting services..."
systemctl restart php8.2-fpm nginx supervisor

# Clean old logs
echo "πŸ“ Cleaning old logs..."
find /var/log -name "*.log" -mtime +7 -delete
find /var/www/puqcloud/storage/logs -name "*.log" -mtime +7 -delete

# Check disk space
echo "πŸ’½ Checking disk space..."
df -h

# Security updates
echo "πŸ”’ Checking security updates..."
unattended-upgrade --dry-run

echo "βœ… Maintenance completed!"

πŸ“Š Monitoring and Alerting

13. πŸ“ˆ Health Check Script

Comprehensive health monitoring:

#!/bin/bash
# Health check script for monitoring

# Configuration
WEBHOOK_URL="https://hooks.slack.com/your/webhook/url"
EMAIL_ALERTS="admin@example.com"
DOMAIN="example.com"

# Check functions
check_service() {
    local service=$1
    if systemctl is-active --quiet "$service"; then
        return 0
    else
        return 1
    fi
}

check_http() {
    local url=$1
    local expected_code=${2:-200}
    local response=$(curl -s -o /dev/null -w "%{http_code}" "$url")
    if [ "$response" = "$expected_code" ]; then
        return 0
    else
        return 1
    fi
}

send_alert() {
    local message=$1
    local level=${2:-warning}
    
    # Send to Slack
    curl -X POST -H 'Content-type: application/json' \
        --data "{\"text\":\"[$level] PUQcloud Alert: $message\"}" \
        "$WEBHOOK_URL"
    
    # Send email
    echo "$message" | mail -s "PUQcloud Alert" "$EMAIL_ALERTS"
}

# Health checks
echo "πŸ₯ Running health checks..."

# Check services
critical_services=(nginx php8.2-fpm mariadb redis-server supervisor)
for service in "${critical_services[@]}"; do
    if ! check_service "$service"; then
        send_alert "$service is not running on $(hostname)" "critical"
    fi
done

# Check web response
if ! check_http "https://$DOMAIN"; then
    send_alert "Website $DOMAIN is not responding" "critical"
fi

# Check phpMyAdmin
if ! check_http "https://phpmyadmin.$DOMAIN"; then
    send_alert "phpMyAdmin is not accessible" "warning"
fi

# Check database connection
if ! mysql -e "SELECT 1" &>/dev/null; then
    send_alert "Database connection failed" "critical"
fi

# Check disk space
disk_usage=$(df / | tail -1 | awk '{print $5}' | sed 's/%//')
if [ "$disk_usage" -gt 85 ]; then
    send_alert "Disk usage is at $disk_usage%" "warning"
fi

# Check memory usage
memory_usage=$(free | grep Mem | awk '{printf("%.2f", $3/$2 * 100.0)}')
if (( $(echo "$memory_usage > 90" | bc -l) )); then
    send_alert "Memory usage is at $memory_usage%" "warning"
fi

# Check Horizon
cd /var/www/puqcloud
if ! php artisan horizon:status | grep -q "running"; then
    send_alert "Horizon queue system is not running" "critical"
fi

# Check SSL certificate expiry
if [ -f /etc/letsencrypt/live/*/fullchain.pem ]; then
    cert_exp_date=$(openssl x509 -enddate -noout -in /etc/letsencrypt/live/*/fullchain.pem | cut -d= -f2)
    cert_exp_timestamp=$(date -d "$cert_exp_date" +%s)
    current_timestamp=$(date +%s)
    days_until_exp=$(( (cert_exp_timestamp - current_timestamp) / 86400 ))
    
    if [ "$days_until_exp" -lt 30 ]; then
        send_alert "SSL certificate expires in $days_until_exp days" "warning"
    fi
fi

echo "βœ… Health checks completed!"

πŸ”— Integration Examples

14. πŸ”Œ API Integration Setup

Set up PUQcloud with external APIs:

#!/bin/bash
# API integration setup

cd /var/www/puqcloud

echo "πŸ”Œ Setting up API integrations..."

# Payment gateways
echo "πŸ’³ Configuring payment gateways..."
php artisan config:set services.stripe.key "$STRIPE_KEY"
php artisan config:set services.stripe.secret "$STRIPE_SECRET"
php artisan config:set services.paypal.client_id "$PAYPAL_CLIENT_ID"
php artisan config:set services.paypal.secret "$PAYPAL_SECRET"

# Email services
echo "πŸ“§ Configuring email services..."
php artisan config:set mail.driver smtp
php artisan config:set mail.host smtp.mailgun.org
php artisan config:set mail.username "$MAILGUN_USERNAME"
php artisan config:set mail.password "$MAILGUN_PASSWORD"

# Cloud storage
echo "☁️ Configuring cloud storage..."
php artisan config:set filesystems.disks.s3.key "$AWS_ACCESS_KEY"
php artisan config:set filesystems.disks.s3.secret "$AWS_SECRET_KEY"
php artisan config:set filesystems.disks.s3.region "$AWS_REGION"
php artisan config:set filesystems.disks.s3.bucket "$AWS_BUCKET"

# SMS services
echo "πŸ“± Configuring SMS services..."
php artisan config:set services.twilio.sid "$TWILIO_SID"
php artisan config:set services.twilio.token "$TWILIO_TOKEN"

# Clear cache
php artisan config:clear
php artisan cache:clear

echo "βœ… API integrations configured!"

15. 🌐 Multi-Domain Setup

Configure multiple domains for PUQcloud:

#!/bin/bash
# Multi-domain setup script

DOMAINS=(
    "app.company.com"
    "client.company.com"
    "partner.company.com"
)

echo "🌐 Setting up multi-domain configuration..."

for domain in "${DOMAINS[@]}"; do
    echo "πŸ“ Configuring $domain..."
    
    # Create Nginx configuration
    cat > "/etc/nginx/sites-available/$domain" << EOF
server {
    listen 80;
    server_name $domain;
    root /var/www/puqcloud/public;
    
    index index.php index.html index.htm;
    
    location / {
        try_files \$uri \$uri/ /index.php?\$query_string;
    }
    
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        include fastcgi_params;
    }
    
    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
        try_files \$uri /index.php?\$query_string;
        expires max;
        log_not_found off;
    }
}
EOF
    
    # Enable site
    ln -sf "/etc/nginx/sites-available/$domain" "/etc/nginx/sites-enabled/"
    
    # Get SSL certificate
    certbot --nginx -d "$domain" --non-interactive --agree-tos -m "admin@$domain"
    
done

# Test configuration
nginx -t && systemctl reload nginx

echo "βœ… Multi-domain setup completed!"

πŸŽ“ Learning and Development

16. πŸ“š Development Workflow Setup

Set up complete development environment:

#!/bin/bash
# Development workflow setup

echo "πŸŽ“ Setting up development workflow..."

# Install development tools
echo "πŸ› οΈ Installing development tools..."
npm install -g @vue/cli laravel-mix cross-env

# Install VS Code extensions (if VS Code is available)
if command -v code &> /dev/null; then
    echo "πŸ“ Installing VS Code extensions..."
    code --install-extension bmewburn.vscode-intelephense-client
    code --install-extension bradlc.vscode-tailwindcss
    code --install-extension octref.vetur
fi

# Set up Git hooks
echo "πŸ“‹ Setting up Git hooks..."
cd /var/www/puqcloud

cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
# Pre-commit hook for PUQcloud

echo "πŸ” Running pre-commit checks..."

# PHP syntax check
find . -name "*.php" -not -path "./vendor/*" -exec php -l {} \; | grep -v "No syntax errors"

# Run PHPUnit tests
php artisan test

# Check for debugging statements
if grep -r "dd(" app/ resources/ || grep -r "dump(" app/ resources/; then
    echo "❌ Found debugging statements in code!"
    exit 1
fi

echo "βœ… Pre-commit checks passed!"
EOF

chmod +x .git/hooks/pre-commit

# Set up environment switcher
cat > switch-env.sh << 'EOF'
#!/bin/bash
# Environment switcher

ENV=${1:-local}

case $ENV in
    "local")
        cp .env.local .env
        php artisan config:clear
        echo "Switched to local environment"
        ;;
    "staging")
        cp .env.staging .env
        php artisan config:clear
        echo "Switched to staging environment"
        ;;
    "production")
        cp .env.production .env
        php artisan config:clear
        echo "Switched to production environment"
        ;;
    *)
        echo "Usage: $0 {local|staging|production}"
        exit 1
        ;;
esac
EOF

chmod +x switch-env.sh

echo "βœ… Development workflow setup completed!"

17. πŸš€ Deployment Pipeline

Complete CI/CD pipeline setup:

#!/bin/bash
# Deployment pipeline setup

echo "πŸš€ Setting up deployment pipeline..."

# Create deployment script
cat > deploy.sh << 'EOF'
#!/bin/bash
# Deployment script

set -e

ENVIRONMENT=${1:-production}
BRANCH=${2:-main}

echo "πŸš€ Deploying PUQcloud to $ENVIRONMENT from $BRANCH branch..."

# Backup current installation
echo "πŸ’Ύ Creating backup..."
./backup.sh

# Pull latest code
echo "πŸ“₯ Pulling latest code..."
git fetch --all
git checkout $BRANCH
git pull origin $BRANCH

# Install/update dependencies
echo "πŸ“¦ Installing dependencies..."
composer install --no-dev --optimize-autoloader
npm ci && npm run production

# Run migrations
echo "πŸ—„οΈ Running migrations..."
php artisan migrate --force

# Clear caches
echo "🧹 Clearing caches..."
php artisan config:cache
php artisan route:cache
php artisan view:cache

# Restart services
echo "πŸ”„ Restarting services..."
php artisan horizon:terminate
supervisorctl restart horizon
php artisan queue:restart

# Run health checks
echo "πŸ₯ Running health checks..."
./health-check.sh

echo "βœ… Deployment completed successfully!"
EOF

chmod +x deploy.sh

# Create rollback script
cat > rollback.sh << 'EOF'
#!/bin/bash
# Rollback script

BACKUP_FILE=${1}

if [ -z "$BACKUP_FILE" ]; then
    echo "Usage: $0 <backup_file>"
    echo "Available backups:"
    ls -la /backups/puqcloud/
    exit 1
fi

echo "πŸ”„ Rolling back to $BACKUP_FILE..."

# Stop services
supervisorctl stop horizon

# Restore backup
tar -xzf "/backups/puqcloud/$BACKUP_FILE" -C /

# Restart services
systemctl restart nginx php8.2-fpm
supervisorctl start horizon

echo "βœ… Rollback completed!"
EOF

chmod +x rollback.sh

echo "βœ… Deployment pipeline setup completed!"

πŸ“Š Performance and Optimization

Performance monitoring and optimization script:

#!/bin/bash
# Performance optimization script

echo "πŸ“Š PUQcloud Performance Optimization..."

# Optimize database
echo "πŸ—„οΈ Optimizing database..."
cd /var/www/puqcloud
php artisan optimize:clear
php artisan optimize

# Configure PHP-FPM for performance
echo "🐘 Optimizing PHP-FPM..."
sed -i 's/pm.max_children = .*/pm.max_children = 50/' /etc/php/8.2/fpm/pool.d/www.conf
sed -i 's/pm.start_servers = .*/pm.start_servers = 10/' /etc/php/8.2/fpm/pool.d/www.conf
sed -i 's/pm.min_spare_servers = .*/pm.min_spare_servers = 5/' /etc/php/8.2/fpm/pool.d/www.conf
sed -i 's/pm.max_spare_servers = .*/pm.max_spare_servers = 15/' /etc/php/8.2/fpm/pool.d/www.conf

# Optimize Nginx
echo "🌐 Optimizing Nginx..."
cat >> /etc/nginx/nginx.conf << 'EOF'
# Performance optimizations
worker_processes auto;
worker_connections 1024;
keepalive_timeout 65;
client_max_body_size 100M;

# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
EOF

# Setup Redis caching
echo "πŸ”„ Configuring Redis caching..."
sed -i 's/CACHE_DRIVER=.*/CACHE_DRIVER=redis/' .env
sed -i 's/SESSION_DRIVER=.*/SESSION_DRIVER=redis/' .env

# Restart services
systemctl restart php8.2-fpm nginx redis-server

echo "βœ… Performance optimization completed!"

These examples cover the most common use cases and scenarios for PUQcloud deployment and management. Each script can be customized according to specific requirements and environments.