Skip to main content

Overview

Dashboard Dilemas uses environment variables for database credentials and can be extended with additional configuration options. The application also uses PHP constants defined in includes/config.php for runtime configuration.

Environment File

Creating .env File

Copy the example file to create your environment configuration:
cp .env.example .env

Environment Variables

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=
DB_NAME=wordpress_db

Variable Reference

VariableDefaultDescription
DB_HOSTlocalhostMySQL server hostname or IP address
DB_USERrootDatabase username
DB_PASSWORD(empty)Database password
DB_NAMEwordpress_dbDatabase name
Never commit your .env file to version control. It should be listed in .gitignore.

PHP Configuration Constants

The includes/config.php file defines application-wide constants that complement environment variables.

Site Configuration

Automatic Site URL Detection

The application automatically detects the site URL based on the current environment:
includes/config.php
$_proto = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$_host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$_base = dirname(dirname($_SERVER['SCRIPT_NAME'] ?? '/dashboard-dilemas'));
$_basePath = (str_ends_with($_base, 'dashboard-dilemas')) ? $_base : $_base . '/dashboard-dilemas';
define('SITE_URL', rtrim($_proto . '://' . $_host . $_basePath, '/'));
The site URL is automatically adjusted for both local development (/dashboard-dilemas) and production environments.

WordPress Integration

define('WP_SITE_URL', 'http://localhost:8888/dilemas');
define('WP_PATH', '/Users/benitogutierrez/GITBG/dilemas');
Update WP_PATH and WP_SITE_URL to match your WordPress installation path. These are required for email functionality using WordPress’s PHPMailer.

SMTP Configuration

Email server settings are defined as PHP constants:
includes/config.php
define('SMTP_HOST', ''); // e.g., smtp-relay.brevo.com
define('SMTP_USER', '');
define('SMTP_PASS', '');
define('SMTP_PORT', 587);
define('SMTP_SECURE', 'tls'); // 'tls' or 'ssl'
define('SMTP_FROM_EMAIL', '[email protected]');
define('SMTP_FROM_NAME', 'Dilemas Eticos');
Recommended SMTP providers: Brevo, SendGrid, or Gmail SMTP. See Email Configuration for details.

AI Integration

Gemini AI API key for enhanced features:
define('GEMINI_API_KEY', 'your_api_key_here');
Get your API key from Google AI Studio
Security Alert: The example file contains a placeholder API key. Replace it with your own key and never commit real credentials to version control.

Cron Job Configuration

For automated email reminders, configure a cron secret:
cron_email_reminders.php
define('CRON_SECRET', getenv('CRON_SECRET') ?: 'dilemas_cron_2024_secret');
Add this to your .env file:
.env
CRON_SECRET=your_secure_random_secret_here
Then set up your cron job:
# Run daily at 9:00 AM
0 9 * * * curl -s "https://yourdomain.com/dashboard-dilemas/cron_email_reminders.php?secret=your_secure_random_secret_here"

Configuration by Environment

Development Environment

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=root
DB_NAME=dilemas_dev
CRON_SECRET=dev_secret_123

Production Environment

DB_HOST=localhost
DB_USER=dilemas_prod
DB_PASSWORD=strong_secure_password_here
DB_NAME=dilemas_production
CRON_SECRET=long_random_secure_string_here

Security Best Practices

Ensure .env file has restricted permissions:
chmod 600 .env
chown www-data:www-data .env
Always exclude sensitive files from version control:
.gitignore
.env
.env.local
.env.production
includes/config.php
dev/debug/*.log
Generate strong secrets using:
# Generate random string for CRON_SECRET
openssl rand -base64 32

# Or use PHP
php -r "echo bin2hex(random_bytes(32));"
Use a dedicated database user with minimal privileges:
CREATE USER 'dilemas_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON dilemas.* TO 'dilemas_user'@'localhost';
FLUSH PRIVILEGES;

Troubleshooting

Common Issues

Problem: Database connection fails even with correct .env file.Solution: PHP doesn’t load .env files by default. You may need to:
  • Use a library like vlucas/phpdotenv
  • Manually load environment variables in your web server configuration
  • Set variables directly in PHP using putenv()
Problem: Emails fail to send.Solution:
  • Verify SMTP credentials are correct
  • Check SMTP_PORT and SMTP_SECURE settings
  • Ensure firewall allows outbound connections on the SMTP port
  • Check error logs in dev/debug/error.log
Problem: Certificate emails fail with “WordPress not found” error.Solution: Update WP_PATH constant in includes/config.php to point to your actual WordPress installation directory.

Next Steps

Database Setup

Configure MySQL database and schema

Email Configuration

Set up SMTP for notifications

Build docs developers (and LLMs) love