Environment Configuration
Relevant source files
The following files were used as context for generating this wiki page:
The environment configuration system for the IT Management project serves as the foundation for system-wide settings, database connectivity, and security parameters. It manages how the application interacts with server-side variables, database credentials, and path constants required for multi-tenant isolation. The core of this system is centered in config/config.php, which is required by every entry point in the application to ensure a consistent execution environment.
This configuration layer facilitates the transition from local development to production by supporting both hardcoded constants (primarily for legacy or local setups) and environment variables for sensitive secrets. It also establishes the core technical constraints, such as the mandatory use of the mysqli extension and the strict "Zero Dependencies" architecture.
Sources: config/AGENT_NOTES.md, README.md:231-236, INSTALLATION.txt:13-20
Core Configuration Architecture
The configuration architecture is designed to load settings from multiple sources, prioritizing security and modularity. The application initializes by setting up path constants and loading environment variables before establishing the database connection.
Configuration Load Order
The following diagram illustrates the sequence in which the environment is prepared:
The system ensures that the database connection ($conn) is available globally after config.php is included.
Sources: config/config.php, config/AGENT_NOTES.md:14-22, README.md:162-171
Key Configuration Elements
| Element | Description | Implementation Detail |
|---|---|---|
| Database Credentials | Host, Name, User, and Password for MySQL. | Defined as constants or loaded via getenv(). |
| Path Constants | Absolute paths for uploads (images, floor plans, backups). | e.g., ROOT_PATH, FLOOR_PLAN_DIR. |
| Multi-Tenancy | Resolves the active company_id. | Derived from the authenticated session. |
| Security Secrets | API keys for third-party integrations (e.g., IP2WHOIS). | Loaded from .env or Server Environment. |
Sources: config/AGENT_NOTES.md:4-12, README.md:173-180, INSTALLATION.txt:13-20
Database Environment Setup
The application strictly utilizes the mysqli implementation and explicitly forbids the use of PDO. Configuration for the database environment is typically handled in config/config.php.
Database Connection Parameters
| Parameter | Default Value | Environment Variable (Recommended) |
|---|---|---|
| DB_HOST | localhost | ITM_DB_HOST |
| DB_NAME | itmanagement | ITM_DB_NAME |
| DB_USER | root | ITM_DB_USER |
| DB_PASS | (blank) | ITM_DB_PASS |
Sources: config/AGENT_NOTES.md:8-10, INSTALLATION.txt:16-20, README.md:244-250
Connection Logic Example
// Standard mysqli connection pattern used in config.php
$conn = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
Sources: config/AGENT_NOTES.md:25-28, INSTALLATION.txt:37-38
Secrets and Sensitive Information
A critical rule for environment configuration is the removal of secrets from version control. The application supports loading these values from environment variables or a local .env file via the itm_load_dotenv_file() function.
Environment Variable Integration
The system looks for specific prefixed variables to configure external services and security hardening:
ITM_APP_URL: Used for URL hardening.ITM_ALLOWED_HOSTS: Defines permitted hostnames.IP2WHOIS_API_KEYorITM_IP2WHOIS_API_KEY: Required for Network Discovery domain lookups.
Sources: wiki/Security.md:45-55, README.md:321-326
Recommended Deployment Configuration
For production environments, it is recommended to set these variables in the web server configuration (e.g., Apache vhost) or container runtime:
SetEnv ITM_DB_HOST db.production.local
SetEnv ITM_DB_NAME it_management_prod
SetEnv ITM_DB_USER itm_svc
SetEnv ITM_DB_PASS k3y_str0ng_p4ss
Sources: README.md:244-250, wiki/Security.md:52-57
File System and Path Configuration
The environment configuration defines several directory structures required for asset management. These must be created manually during initial setup and are represented as constants within the system.
Required Directories
images/: Equipment photo uploads.tickets_photos/: Ticket attachment storage.backups/: SQL backup file destination.floor_plans/: Building layout storage (automatically creates company subfolders).
Sources: README.md:162-171, INSTALLATION.txt:7-11
Script and CLI Environment
For maintenance and automated tasks, the environment supports a CLI mode. Scripts intended for terminal use must define ITM_CLI_SCRIPT to bypass standard web session redirects and authentication checks.
Summary
Environment configuration in the IT Management system centers on a single source of truth: config/config.php. It prioritizes security through environment variable support and multi-tenant isolation by resolving company_id from the session context. By maintaining a zero-dependency architecture and utilizing native mysqli connections, the system ensures a lightweight and highly compatible environment for both development and production deployments.
Sources: config/AGENT_NOTES.md:4-6, AGENT_NOTES.md:8-12, README.md:231-236