Skip to content

Environment Setup

This guide provides comprehensive instructions for setting up the Stratpoint Timesheet Application in various environments including development, staging, and production deployments.

System Requirements

Hardware Requirements

Minimum Requirements: - CPU: 2 cores, 2.4 GHz - RAM: 4 GB - Storage: 50 GB SSD - Network: 100 Mbps

Recommended Requirements: - CPU: 4+ cores, 3.0+ GHz - RAM: 8+ GB - Storage: 100+ GB SSD - Network: 1 Gbps

Production Requirements: - CPU: 8+ cores, 3.2+ GHz - RAM: 16+ GB - Storage: 500+ GB SSD with backup - Network: 1+ Gbps with redundancy

Software Requirements

Operating System: - Ubuntu 20.04 LTS or later - CentOS 8 or later - Red Hat Enterprise Linux 8+ - Docker-compatible OS

Core Dependencies: - PHP 8.0 or later - MySQL 8.0 or later - Redis 6.0 or later - Apache 2.4 or Nginx 1.18+ - Node.js 16+ (for build tools) - Composer 2.0+

Environment Types

Development Environment

graph TB
    A[Developer Machine] --> B[Local Docker Containers]
    B --> C[PHP/Laravel Container]
    B --> D[MySQL Container]
    B --> E[Redis Container]
    B --> F[Apache Container]

    G[Code Editor] --> H[Local Git Repository]
    H --> I[Version Control]

Development Setup: - Local Docker environment - Hot reloading for development - Debug mode enabled - Local database with sample data - Mock external services

Staging Environment

graph TB
    A[Staging Server] --> B[Application Server]
    B --> C[Web Server]
    B --> D[Database Server]
    B --> E[Cache Server]

    F[CI/CD Pipeline] --> G[Automated Deployment]
    G --> A

Staging Characteristics: - Production-like configuration - Automated deployment from develop branch - Integration testing environment - Limited external integrations - Performance testing capabilities

Production Environment

graph TB
    A[Load Balancer] --> B[App Server 1]
    A --> C[App Server 2]
    A --> D[App Server N]

    B --> E[Database Primary]
    C --> E
    D --> E

    B --> F[Database Replica]
    C --> F
    D --> F

    B --> G[Redis Cluster]
    C --> G
    D --> G

    H[Backup System] --> E
    I[Monitoring] --> A
    I --> B
    I --> C
    I --> D

Installation Methods

Prerequisites:

# Install Docker and Docker Compose
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USER

# 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

Docker Compose Configuration:

version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: docker/Dockerfile
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - .:/var/www/html
      - ./docker/apache/sites-available:/etc/apache2/sites-available
      - ./docker/certs:/etc/ssl/certs
    environment:
      - APP_ENV=production
      - DB_HOST=mysql
      - REDIS_HOST=redis
    depends_on:
      - mysql
      - redis
    networks:
      - timesheet-network

  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_USER: ${DB_USERNAME}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    volumes:
      - mysql_data:/var/lib/mysql
      - ./database/backups:/backups
    ports:
      - "3306:3306"
    networks:
      - timesheet-network

  redis:
    image: redis:6.0-alpine
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - timesheet-network

volumes:
  mysql_data:
  redis_data:

networks:
  timesheet-network:
    driver: bridge

Deployment Commands:

# Clone repository
git clone https://github.com/stratpoint/timesheet-web.git
cd timesheet-web

# Copy environment configuration
cp .env.example .env

# Build and start containers
docker-compose up -d

# Install dependencies
docker-compose exec app composer install
docker-compose exec app npm install

# Generate application key
docker-compose exec app php artisan key:generate

# Run migrations
docker-compose exec app php artisan migrate

# Seed database (optional)
docker-compose exec app php artisan db:seed

Manual Installation

System Preparation:

# Update system packages
sudo apt update && sudo apt upgrade -y

# Install PHP and extensions
sudo apt install php8.0 php8.0-fpm php8.0-mysql php8.0-redis \
    php8.0-xml php8.0-mbstring php8.0-curl php8.0-zip \
    php8.0-gd php8.0-intl php8.0-bcmath -y

# Install MySQL
sudo apt install mysql-server-8.0 -y

# Install Redis
sudo apt install redis-server -y

# Install Apache
sudo apt install apache2 -y

# Enable Apache modules
sudo a2enmod rewrite ssl headers

Application Setup:

# Clone repository
git clone https://github.com/stratpoint/timesheet-web.git /var/www/timesheet
cd /var/www/timesheet

# Set permissions
sudo chown -R www-data:www-data /var/www/timesheet
sudo chmod -R 755 /var/www/timesheet
sudo chmod -R 775 storage bootstrap/cache

# Install Composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

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

# Install Node.js and npm
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt install nodejs -y

# Build frontend assets
npm install
npm run production

Configuration

Environment Variables

Core Configuration (.env):

# Application
APP_NAME="Stratpoint Timesheet"
APP_ENV=production
APP_KEY=base64:generated_key_here
APP_DEBUG=false
APP_URL=https://timesheet.stratpoint.com

# Database
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=timesheet
DB_USERNAME=timesheet_user
DB_PASSWORD=secure_password

# Cache
CACHE_DRIVER=redis
SESSION_DRIVER=redis
QUEUE_CONNECTION=redis

# Redis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

# Mail
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your_email@gmail.com
MAIL_PASSWORD=your_app_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=noreply@stratpoint.com
MAIL_FROM_NAME="Stratpoint Timesheet"

# AWS S3
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_DEFAULT_REGION=ap-southeast-1
AWS_BUCKET=timesheet-storage

# JWT
JWT_SECRET=your_jwt_secret_key
JWT_TTL=60

# SSO Configuration
AUTH_METHOD=brewerySso
ADAPTER_URL=https://sso.provider.com
AUTH_REALM=stratpoint
AUTH_SERVER_URL=https://auth.provider.com
AUTH_CLIENT_ID=timesheet-app
SSO_SECRET=sso_secret_key
SSO_KEY=sso_encryption_key

Database Setup

Database Creation:

-- Create database
CREATE DATABASE timesheet CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Create user
CREATE USER 'timesheet_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON timesheet.* TO 'timesheet_user'@'localhost';
FLUSH PRIVILEGES;

Migration and Seeding:

# Run migrations
php artisan migrate

# Seed initial data
php artisan db:seed

# Create admin user
php artisan tinker
>>> User::create([
    'firstname' => 'Admin',
    'lastname' => 'User',
    'email' => 'admin@stratpoint.com',
    'password' => Hash::make('admin_password'),
    'role_id' => 1,
    'isActive' => true
]);

Web Server Configuration

Apache Virtual Host:

<VirtualHost *:80>
    ServerName timesheet.stratpoint.com
    DocumentRoot /var/www/timesheet/public

    <Directory /var/www/timesheet/public>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/timesheet_error.log
    CustomLog ${APACHE_LOG_DIR}/timesheet_access.log combined

    # Redirect to HTTPS
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</VirtualHost>

<VirtualHost *:443>
    ServerName timesheet.stratpoint.com
    DocumentRoot /var/www/timesheet/public

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/timesheet.crt
    SSLCertificateKeyFile /etc/ssl/private/timesheet.key

    <Directory /var/www/timesheet/public>
        AllowOverride All
        Require all granted
    </Directory>

    # Security headers
    Header always set X-Content-Type-Options nosniff
    Header always set X-Frame-Options DENY
    Header always set X-XSS-Protection "1; mode=block"
    Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

    ErrorLog ${APACHE_LOG_DIR}/timesheet_ssl_error.log
    CustomLog ${APACHE_LOG_DIR}/timesheet_ssl_access.log combined
</VirtualHost>

SSL Certificate Setup

Let's Encrypt (Recommended):

# Install Certbot
sudo apt install certbot python3-certbot-apache -y

# Obtain certificate
sudo certbot --apache -d timesheet.stratpoint.com

# Auto-renewal
sudo crontab -e
# Add: 0 12 * * * /usr/bin/certbot renew --quiet

Performance Optimization

PHP Configuration

PHP-FPM Optimization:

; /etc/php/8.0/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500

; PHP settings
memory_limit = 256M
max_execution_time = 300
upload_max_filesize = 50M
post_max_size = 50M

Database Optimization

MySQL Configuration:

# /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
innodb_buffer_pool_size = 2G
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
query_cache_type = 1
query_cache_size = 256M
max_connections = 200

Caching Configuration

Redis Configuration:

# /etc/redis/redis.conf
maxmemory 1gb
maxmemory-policy allkeys-lru
save 900 1
save 300 10
save 60 10000

This environment setup guide provides a comprehensive foundation for deploying the Stratpoint Timesheet Application across different environments while ensuring optimal performance, security, and scalability.