Skip to main content
ipMoodle uses environment variables to configure the deployment without hardcoding values. The deploy.sh script generates a .env file that Docker Compose reads during container startup.

Core variables

These variables are defined in deploy.sh and control the fundamental deployment settings:
SITE_URL
string
required
The public URL where Moodle will be accessibleExample: https://eva.intiinside.comDefault: Must be set before running deploy.sh
This URL is used in Moodle’s configuration and email notifications
DB_NAME
string
required
PostgreSQL database nameDefault: moodle (deploy.sh:5)Used by both the database container and Moodle application to connect to the correct database.
DB_USER
string
required
PostgreSQL database usernameDefault: moodle (deploy.sh:6)Credentials for Moodle to authenticate with PostgreSQL.
DB_PASS
string
required
PostgreSQL database passwordDefault: moodle (deploy.sh:7)
Change this default password for production deployments

Docker Compose variables

These variables are used in docker-compose.yml to configure services:

Database service (db)

docker-compose.yml:8-10
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASS}
PostgreSQL reads these standard environment variables during initialization to create the database and user.

Application service (app)

docker-compose.yml:22-27
MOODLE_DB_TYPE: pgsql
MOODLE_DB_HOST: db
MOODLE_DB_NAME: ${DB_NAME}
MOODLE_DB_USER: ${DB_USER}
MOODLE_DB_PASSWORD: ${DB_PASS}
MOODLE_URL: ${SITE_URL}
MOODLE_DB_HOST: db uses Docker’s service discovery. The db service is automatically resolvable via Docker DNS.

Setting variables

Before deployment

Edit deploy.sh before running it:
deploy.sh:3-7
# --- CONFIGURACIÓN ---
export SITE_URL="https://eva.intiinside.com"
export DB_NAME="moodle"
export DB_USER="moodle"
export DB_PASS="moodle"
Uncomment and modify the SITE_URL line (line 4) with your actual domain.

After deployment

If you need to change variables after initial deployment:
1

Edit the .env file

Modify the generated .env file in your project root:
nano .env
2

Restart services

Restart containers to pick up new values:
docker compose down
docker compose up -d
3

Update Moodle config

If you changed SITE_URL, update Moodle’s configuration:
docker compose exec app nano /var/www/html/config.php
Find and update the $CFG->wwwroot value.

Security best practices

Never commit .env files to version control. Add .env to your .gitignore file.

Use strong passwords

Generate secure passwords for DB_PASS:
openssl rand -base64 32

Restrict file permissions

Limit access to the .env file:
chmod 600 .env

Use secrets management

For production, consider using Docker secrets or external secret managers instead of plain .env files.

Separate environments

Maintain different .env files for development, staging, and production environments.

Verification

Check that environment variables are correctly loaded in containers:
# Check app container environment
docker compose exec app env | grep MOODLE

# Check database container environment
docker compose exec db env | grep POSTGRES
Expected output for app container:
MOODLE_DB_TYPE=pgsql
MOODLE_DB_HOST=db
MOODLE_DB_NAME=moodle
MOODLE_DB_USER=moodle
MOODLE_DB_PASSWORD=moodle
MOODLE_URL=https://eva.intiinside.com

Troubleshooting

  1. Verify environment variables are set correctly in .env
  2. Check database credentials match between app and db services
  3. Ensure database container is running: docker compose ps db
  4. Check database logs: docker compose logs db
  1. Update SITE_URL in .env
  2. Edit /var/www/html/config.php inside the app container
  3. Update $CFG->wwwroot to match your new URL
  4. Restart services: docker compose restart
The .env file must be in the same directory as docker-compose.yml. Check:
ls -la .env
cat .env
Regenerate if needed by running the relevant section of deploy.sh.

Next steps

PHP settings

Configure PHP memory, upload limits, and timeouts

Nginx configuration

Customize web server settings

Database tuning

Optimize PostgreSQL performance

Security hardening

Implement security best practices

Build docs developers (and LLMs) love