Skip to main content

Production Deployment

Deploy the Viax platform to a production VPS server with proper security, performance optimization, and monitoring.
Production deployment requires careful attention to security. Never deploy without proper authentication, HTTPS, and security hardening.

Deployment Overview

Current Production Setup

Server

VPS Details:
  • IP: 76.13.114.194
  • OS: Linux (Ubuntu/Debian)
  • Access: SSH root access

Services

Stack:
  • Apache Web Server
  • PHP 8.3+
  • MySQL 8.0+
  • Git for deployments

Backend

Location:
  • Path: /var/www/viax/backend
  • URL: http://76.13.114.194
  • Repository: GitHub

Database

MySQL:
  • Host: localhost
  • Database: viax_production
  • User: viax_user

Pre-Deployment Checklist

1

Code Review

  • All features tested locally
  • No hardcoded credentials
  • Error handling implemented
  • Logging configured
  • Code committed to Git
2

Environment Configuration

  • Production database credentials ready
  • API keys secured
  • SMTP settings configured
  • Environment variables set
3

Security

  • SQL injection prevention (prepared statements)
  • XSS protection
  • CORS configured
  • Input validation
  • Password hashing (bcrypt)
4

Performance

  • Database indexes created
  • Query optimization done
  • Caching strategy planned
  • Assets optimized
5

Backup

  • Database backup created
  • Code repository backed up
  • Rollback plan documented

Backend Deployment

Step 1: Server Access

# Connect to VPS via SSH
ssh root@76.13.114.194

# Optional: Use SSH key for secure access
ssh -i ~/.ssh/viax_key root@76.13.114.194

Step 2: Initial Server Setup

# Update package list
sudo apt update

# Upgrade installed packages
sudo apt upgrade -y

# Install essential tools
sudo apt install -y git curl wget vim

Step 3: Deploy Backend Code

1

Create Directory Structure

# Create project directory
sudo mkdir -p /var/www/viax
cd /var/www/viax

# Set ownership
sudo chown -R $USER:$USER /var/www/viax
2

Clone Repository

# Clone backend repository
git clone https://github.com/Braian551/viax-backend.git backend
cd backend

# Or pull latest changes if already cloned
git pull origin main
3

Install Dependencies

# Install PHP dependencies
composer install --no-dev --optimize-autoloader

# Verify vendor directory created
ls -la vendor/
4

Set Permissions

# Create necessary directories
mkdir -p logs uploads

# Set ownership to web server user
sudo chown -R www-data:www-data /var/www/viax/backend

# Set directory permissions
sudo chmod -R 755 /var/www/viax/backend

# Writable directories
sudo chmod -R 775 logs uploads
sudo chmod -R 775 vendor

Step 4: Configure Apache

Create Virtual Host:
sudo vim /etc/apache2/sites-available/viax.conf
Content:
<VirtualHost *:80>
    ServerName 76.13.114.194
    ServerAdmin admin@viax.com
    
    DocumentRoot /var/www/viax/backend
    
    <Directory /var/www/viax/backend>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
        
        # Security headers
        Header set X-Content-Type-Options "nosniff"
        Header set X-Frame-Options "SAMEORIGIN"
        Header set X-XSS-Protection "1; mode=block"
    </Directory>
    
    # Error and Access logs
    ErrorLog ${APACHE_LOG_DIR}/viax_error.log
    CustomLog ${APACHE_LOG_DIR}/viax_access.log combined
    
    # PHP settings
    <FilesMatch \.php$>
        SetHandler application/x-httpd-php
    </FilesMatch>
</VirtualHost>
Enable Site:
# Enable site configuration
sudo a2ensite viax.conf

# Enable required modules
sudo a2enmod rewrite
sudo a2enmod headers

# Test configuration
sudo apache2ctl configtest

# Restart Apache
sudo systemctl restart apache2

Step 5: Configure Database

1

Create Database

sudo mysql -u root -p
-- Create database
CREATE DATABASE viax_production CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Create user
CREATE USER 'viax_user'@'localhost' IDENTIFIED BY 'STRONG_PASSWORD_HERE';

-- Grant privileges
GRANT ALL PRIVILEGES ON viax_production.* TO 'viax_user'@'localhost';

-- Apply changes
FLUSH PRIVILEGES;

-- Verify
SHOW DATABASES;
SELECT User, Host FROM mysql.user WHERE User = 'viax_user';

EXIT;
2

Import Schema

# Upload your SQL file to server
scp basededatos.sql root@76.13.114.194:/tmp/

# Import on server
mysql -u viax_user -p viax_production < /tmp/basededatos.sql

# Verify
mysql -u viax_user -p viax_production -e "SHOW TABLES;"
3

Configure Backend Database Connection

Edit /var/www/viax/backend/config/database.php:
<?php
class Database {
    private $host = 'localhost';
    private $db_name = 'viax_production';
    private $username = 'viax_user';
    private $password = 'STRONG_PASSWORD_HERE';
    private $conn;
    
    public function getConnection() {
        $this->conn = null;
        try {
            $dsn = "mysql:host={$this->host};dbname={$this->db_name};charset=utf8mb4";
            $this->conn = new PDO($dsn, $this->username, $this->password);
            $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $this->conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
        } catch(PDOException $exception) {
            error_log("DB Connection error: " . $exception->getMessage());
            throw new Exception("Database unavailable");
        }
        return $this->conn;
    }
}
?>

Step 6: Production PHP Configuration

Edit /etc/php/8.3/apache2/php.ini:
; Security
expose_php = Off
display_errors = Off
log_errors = On
error_log = /var/log/php/php_errors.log

; Performance
memory_limit = 256M
max_execution_time = 30
upload_max_filesize = 20M
post_max_size = 20M

; Session
session.cookie_httponly = 1
session.cookie_secure = 1  ; Enable when using HTTPS
session.use_strict_mode = 1

; OpCache (performance)
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.validate_timestamps=0  ; Disable in production
Restart Apache:
sudo systemctl restart apache2

Step 7: Verify Deployment

curl http://76.13.114.194/health.php

# Expected:
{"status":"ok","timestamp":"..."}

Mobile App Deployment

Android Production Build

1

Configure Build

Edit android/app/build.gradle:
android {
    defaultConfig {
        applicationId "com.viax.app"
        minSdkVersion 21
        targetSdkVersion 33
        versionCode 1
        versionName "1.0.0"
    }
    
    signingConfigs {
        release {
            storeFile file("../keystore.jks")
            storePassword System.getenv("KEYSTORE_PASSWORD")
            keyAlias "viax"
            keyPassword System.getenv("KEY_PASSWORD")
        }
    }
    
    buildTypes {
        release {
            signingConfig signingConfigs.release
            minifyEnabled true
            shrinkResources true
        }
    }
}
2

Build APK

# Clean previous builds
flutter clean
flutter pub get

# Build release APK
flutter build apk \
  --dart-define=API_BASE_URL=http://76.13.114.194 \
  --release

# Output: build/app/outputs/flutter-apk/app-release.apk
3

Build App Bundle (Google Play)

# Build AAB for Play Store
flutter build appbundle \
  --dart-define=API_BASE_URL=http://76.13.114.194 \
  --release

# Output: build/app/outputs/bundle/release/app-release.aab

iOS Production Build

1

Configure Signing

  1. Open ios/Runner.xcworkspace in Xcode
  2. Select Runner target
  3. Signing & Capabilities tab
  4. Select your team
  5. Ensure provisioning profile is set
2

Build

flutter build ios \
  --dart-define=API_BASE_URL=http://76.13.114.194 \
  --release
3

Archive for App Store

  1. In Xcode: Product > Archive
  2. Wait for archive to complete
  3. Window > Organizer
  4. Select archive > Distribute App
  5. Follow App Store distribution flow

Security Hardening

Firewall Configuration

# Install UFW (Uncomplicated Firewall)
sudo apt install ufw -y

# Allow SSH (important!)
sudo ufw allow 22/tcp

# Allow HTTP and HTTPS
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

# Enable firewall
sudo ufw enable

# Check status
sudo ufw status

SSL/TLS Setup (Future)

HTTPS is highly recommended for production. Use Let’s Encrypt for free SSL certificates.
# Install Certbot
sudo apt install certbot python3-certbot-apache -y

# Obtain certificate (requires domain name)
sudo certbot --apache -d viax.com -d www.viax.com

# Auto-renewal is configured automatically
sudo certbot renew --dry-run

Security Best Practices

In Apache config:
Options -Indexes
In php.ini:
expose_php = Off
// Validate file types
$allowed = ['jpg', 'jpeg', 'png', 'pdf'];
$ext = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));
if (!in_array($ext, $allowed)) {
    throw new Exception('Invalid file type');
}

// Check file size
if ($_FILES['file']['size'] > 5 * 1024 * 1024) { // 5MB
    throw new Exception('File too large');
}
Implement rate limiting for API endpoints:
// Simple rate limit (production: use Redis)
session_start();
$key = 'api_calls_' . $_SERVER['REMOTE_ADDR'];

if (!isset($_SESSION[$key])) {
    $_SESSION[$key] = ['count' => 0, 'reset' => time() + 60];
}

if (time() > $_SESSION[$key]['reset']) {
    $_SESSION[$key] = ['count' => 0, 'reset' => time() + 60];
}

$_SESSION[$key]['count']++;

if ($_SESSION[$key]['count'] > 100) { // 100 requests per minute
    http_response_code(429);
    die(json_encode(['error' => 'Too many requests']));
}

Monitoring & Maintenance

Server Monitoring

# Check disk space
df -h

# Check memory usage
free -h

# Check running processes
top
# or
htop

# Check Apache status
sudo systemctl status apache2

# Check MySQL status
sudo systemctl status mysql

# View Apache logs
sudo tail -f /var/log/apache2/viax_error.log
sudo tail -f /var/log/apache2/viax_access.log

# View MySQL logs
sudo tail -f /var/log/mysql/error.log

Database Backups

Automated Backup Script:
#!/bin/bash
# /var/www/viax/scripts/backup_db.sh

DATE=$(date +"%Y%m%d_%H%M%S")
BACKUP_DIR="/var/www/viax/backups"
DB_NAME="viax_production"
DB_USER="viax_user"
DB_PASS="YOUR_PASSWORD"

mkdir -p $BACKUP_DIR

# Create backup
mysqldump -u $DB_USER -p$DB_PASS $DB_NAME | gzip > $BACKUP_DIR/viax_$DATE.sql.gz

# Keep only last 7 days
find $BACKUP_DIR -name "viax_*.sql.gz" -mtime +7 -delete

echo "Backup completed: viax_$DATE.sql.gz"
Schedule with Cron:
# Edit crontab
crontab -e

# Add daily backup at 2 AM
0 2 * * * /var/www/viax/scripts/backup_db.sh >> /var/www/viax/logs/backup.log 2>&1

Update Deployment

Deployment Script:
#!/bin/bash
# /var/www/viax/scripts/deploy.sh

cd /var/www/viax/backend

# Pull latest code
git pull origin main

# Install/update dependencies
composer install --no-dev --optimize-autoloader

# Run migrations (if any)
php migrations/run_migrations.php

# Set permissions
sudo chown -R www-data:www-data /var/www/viax/backend
sudo chmod -R 755 /var/www/viax/backend
sudo chmod -R 775 logs uploads

# Restart Apache
sudo systemctl restart apache2

echo "Deployment completed successfully"

Troubleshooting

Check Apache error logs:
sudo tail -100 /var/log/apache2/viax_error.log
Common causes:
  • PHP syntax errors
  • Missing file permissions
  • Database connection issues
  • Missing PHP extensions
Test connection:
mysql -u viax_user -p viax_production
Check:
  • Credentials in database.php
  • MySQL service running
  • User permissions granted
# Check processes
top

# Enable PHP OpCache
# In php.ini: opcache.enable=1

# Optimize MySQL
sudo mysqltuner
Production Deployment Complete! Your Viax platform is now live and accessible to users.

Build docs developers (and LLMs) love