Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/obando1998/Proyecto_UCP/llms.txt

Use this file to discover all available pages before exploring further.

Overview

DevolutionSync includes production-ready Docker configuration for containerized deployment. This approach ensures consistent environments across development, staging, and production systems.

Prerequisites

Docker Engine

Version 20.10 or higher

Docker Compose

Version 2.0 or higher

MySQL Server

Version 8.0 (external or containerized)

Network Access

Port 8097 available for web access

Installation

# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

# Verify installation
docker --version
docker-compose --version

Dockerfile Breakdown

The Dockerfile defines the container image for DevolutionSync:
Dockerfile
# Use official PHP with Apache base image
FROM php:8.2-apache

# Enable necessary PHP extensions
RUN docker-php-ext-install pdo pdo_mysql mysqli

# Copy all project files to container
COPY . /var/www/html/

# Adjust permissions for Apache
RUN chown -R www-data:www-data /var/www/html \
    && chmod -R 755 /var/www/html

# Expose Apache port
EXPOSE 80

Dockerfile Components

FROM php:8.2-apache
Official PHP image with:
  • PHP 8.2 runtime
  • Apache 2.4 web server
  • Debian-based Linux
  • Pre-configured for web applications
This base image includes mod_rewrite and other essential Apache modules.
RUN docker-php-ext-install pdo pdo_mysql mysqli
Installed extensions:
ExtensionPurpose
pdoPHP Data Objects - database abstraction layer
pdo_mysqlMySQL driver for PDO
mysqliMySQL Improved extension (legacy support)
These extensions enable database connectivity for DevolutionSync.
COPY . /var/www/html/
Copies entire project directory into container:
  • PHP source code
  • Controllers, Models, Views
  • Configuration files
  • Static assets (CSS, JS, images)
  • Upload directories
RUN chown -R www-data:www-data /var/www/html \
    && chmod -R 755 /var/www/html
Security configuration:
  • Owner: www-data (Apache user)
  • Group: www-data
  • Permissions: 755 (rwxr-xr-x)
    • Owner: Read, Write, Execute
    • Group: Read, Execute
    • Others: Read, Execute
Upload directories may need 775 or 777 permissions for write access.
EXPOSE 80
Documents that the container listens on port 80 (HTTP). This is Apache’s default port inside the container.

Docker Compose Configuration

The Docker-compose.yml orchestrates the application container and its dependencies:
Docker-compose.yml
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: Proyecto_UCP
    ports:
      - "8097:80"
    volumes:
      - ./:/var/www/html
    # depends_on:
    #   - db
    networks:
      - red_local

volumes:
  db_data:

networks:
  red_local:

Configuration Breakdown

web:
  build:
    context: .
    dockerfile: Dockerfile
  container_name: Proyecto_UCP
  ports:
    - "8097:80"
  volumes:
    - ./:/var/www/html
  networks:
    - red_local
Service configuration:
SettingValueDescription
build.context.Build from current directory
build.dockerfileDockerfileUse specified Dockerfile
container_nameProyecto_UCPContainer name for easy reference
ports8097:80Map host:container ports
volumes./:/var/www/htmlMount project directory
networksred_localConnect to custom network

Database Configuration (Commented)

The current configuration uses an external MySQL database:
# depends_on:
#   - db
To run MySQL in Docker, uncomment and add:
Docker-compose.yml
services:
  web:
    # ... existing configuration ...
    depends_on:
      - db
    environment:
      - DB_HOST=db
      - DB_NAME=devolutionsync
      - DB_USER=sanmarino
      - DB_PASS=sanmarino2021*
  
  db:
    image: mysql:8.0
    container_name: mysql_devolution
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: devolutionsync
      MYSQL_USER: sanmarino
      MYSQL_PASSWORD: sanmarino2021*
    ports:
      - "3306:3306"
    volumes:
      - db_data:/var/lib/mysql
      - ./Script_BD/Script_DB.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - red_local

volumes:
  db_data:
Update config/conexion.php:
$host = 'db';  // Service name instead of IP

Deployment Steps

Quick Start

1

Clone Repository

git clone https://github.com/your-org/devolutionsync.git
cd devolutionsync
2

Configure Database

Edit config/conexion.php with your database credentials:
config/conexion.php
$host = '192.200.100.40';  // Your MySQL server
$db   = 'devolutionsync';
$user = 'SANMARINO';
$pass = 'sanmarino2021*';
3

Build Docker Image

docker-compose build
This creates the container image with all dependencies.
4

Start Container

docker-compose up -d
The -d flag runs containers in detached mode (background).
5

Verify Deployment

# Check container status
docker-compose ps

# View logs
docker-compose logs -f web
Access application: http://localhost:8097

Detailed Deployment

# Build without cache (force rebuild)
docker-compose build --no-cache

# Build with progress output
docker-compose build --progress=plain

Environment Variables

For production, use environment variables instead of hardcoded credentials:

Create .env File

.env
# Database Configuration
DB_HOST=192.200.100.40
DB_NAME=devolutionsync
DB_USER=SANMARINO
DB_PASS=sanmarino2021*
DB_CHARSET=utf8

# Application Configuration
APP_ENV=production
APP_DEBUG=false
APP_URL=http://localhost:8097

# Session Configuration
SESSION_LIFETIME=3600
SESSION_COOKIE_NAME=devolution_session

Update docker-compose.yml

Docker-compose.yml
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: Proyecto_UCP
    ports:
      - "8097:80"
    volumes:
      - ./:/var/www/html
    environment:
      - DB_HOST=${DB_HOST}
      - DB_NAME=${DB_NAME}
      - DB_USER=${DB_USER}
      - DB_PASS=${DB_PASS}
      - APP_ENV=${APP_ENV}
    env_file:
      - .env
    networks:
      - red_local

Update config/conexion.php

config/conexion.php
<?php
class Conexion {
    public static function Conectar() {
        // Read from environment variables
        $host = getenv('DB_HOST') ?: '192.200.100.40';
        $db   = getenv('DB_NAME') ?: 'devolutionsync';
        $user = getenv('DB_USER') ?: 'SANMARINO';
        $pass = getenv('DB_PASS') ?: 'sanmarino2021*';
        $charset = getenv('DB_CHARSET') ?: 'utf8';

        $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
        
        // ... rest of configuration ...
    }
}
Add .env to .gitignore to prevent committing secrets:
.gitignore
.env
.env.*
!.env.example

Container Management

Common Commands

# Open bash shell
docker-compose exec web bash

# Run PHP command
docker-compose exec web php -v

# Check Apache configuration
docker-compose exec web apache2ctl -t

# View PHP configuration
docker-compose exec web php -i
# Copy file from container
docker cp Proyecto_UCP:/var/www/html/logs/error.log ./error.log

# Copy file to container
docker cp ./config.php Proyecto_UCP:/var/www/html/config/

# View file in container
docker-compose exec web cat /var/www/html/index.php
# View container processes
docker-compose top

# Check resource usage
docker stats Proyecto_UCP

# Inspect container
docker inspect Proyecto_UCP

# View Apache error log
docker-compose exec web tail -f /var/log/apache2/error.log

# View PHP error log
docker-compose exec web tail -f /var/log/apache2/php_errors.log
# Restart all services
docker-compose restart

# Restart specific service
docker-compose restart web

# Rebuild and restart
docker-compose up -d --build

Production Optimization

Dockerfile for Production

Dockerfile.prod
FROM php:8.2-apache

# Install production dependencies
RUN apt-get update && apt-get install -y \
    libzip-dev \
    zip \
    unzip \
    && docker-php-ext-install pdo pdo_mysql mysqli zip \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Enable Apache modules
RUN a2enmod rewrite headers expires

# Copy application files
COPY . /var/www/html/

# Set production PHP settings
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

# Configure PHP
RUN echo "upload_max_filesize = 10M" >> $PHP_INI_DIR/php.ini \
    && echo "post_max_size = 10M" >> $PHP_INI_DIR/php.ini \
    && echo "memory_limit = 256M" >> $PHP_INI_DIR/php.ini \
    && echo "display_errors = Off" >> $PHP_INI_DIR/php.ini \
    && echo "log_errors = On" >> $PHP_INI_DIR/php.ini

# Set permissions
RUN chown -R www-data:www-data /var/www/html \
    && chmod -R 755 /var/www/html \
    && chmod -R 775 /var/www/html/uploads

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
    CMD curl -f http://localhost/ || exit 1

EXPOSE 80

Production docker-compose.yml

docker-compose.prod.yml
services:
  web:
    build:
      context: .
      dockerfile: Dockerfile.prod
    container_name: devolution_prod
    restart: always
    ports:
      - "80:80"
    environment:
      - DB_HOST=${DB_HOST}
      - DB_NAME=${DB_NAME}
      - DB_USER=${DB_USER}
      - DB_PASS=${DB_PASS}
      - APP_ENV=production
    env_file:
      - .env.production
    volumes:
      - ./uploads:/var/www/html/uploads
      - ./logs:/var/www/html/logs
    networks:
      - red_local
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

networks:
  red_local:
    driver: bridge

Security Best Practices

Use Non-Root User

RUN useradd -m -s /bin/bash appuser
USER appuser

Scan for Vulnerabilities

docker scan devolutionsync:latest

Use Secrets

secrets:
  db_password:
    file: ./secrets/db_password.txt

Limit Resources

deploy:
  resources:
    limits:
      cpus: '1'
      memory: 512M

Monitoring and Logging

Log Configuration

docker-compose.yml
services:
  web:
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

Health Checks

docker-compose.yml
services:
  web:
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

Troubleshooting

Error: Bind for 0.0.0.0:8097 failed: port is already allocatedSolution:
# Find process using port
sudo lsof -i :8097

# Kill process
sudo kill -9 <PID>

# Or change port in docker-compose.yml
ports:
  - "8098:80"  # Use different port
Error: Connection refused or Access deniedSolution:
# Check database is accessible from container
docker-compose exec web ping 192.200.100.40

# Test MySQL connection
docker-compose exec web php -r "new PDO('mysql:host=192.200.100.40;dbname=devolutionsync', 'SANMARINO', 'sanmarino2021*');"

# Verify credentials in config/conexion.php
Error: Permission denied when uploading filesSolution:
# Fix permissions from inside container
docker-compose exec web chown -R www-data:www-data /var/www/html/uploads
docker-compose exec web chmod -R 775 /var/www/html/uploads
Solution:
# View logs to identify error
docker-compose logs web

# Check container exit code
docker inspect Proyecto_UCP --format='{{.State.ExitCode}}'

# Start in foreground to see errors
docker-compose up web

Backup and Recovery

Backup Container Data

# Backup uploads directory
tar -czf uploads-backup-$(date +%Y%m%d).tar.gz ./uploads

# Backup database (if using Docker MySQL)
docker-compose exec db mysqldump -u root -p devolutionsync > backup-$(date +%Y%m%d).sql

# Backup entire container
docker commit Proyecto_UCP devolution_backup:$(date +%Y%m%d)

Restore from Backup

# Restore uploads
tar -xzf uploads-backup-20240315.tar.gz

# Restore database
docker-compose exec -T db mysql -u root -p devolutionsync < backup-20240315.sql

Next Steps

Architecture

Understand system architecture

Database Schema

Learn database structure

Configuration

Configure environment settings

Monitoring

Set up monitoring and alerts

Build docs developers (and LLMs) love