How to Set Up Environment Variables in Horilla for Development & Pre-Production
When working with a Django-based application like Horilla, managing environment variables efficiently is key to separating development, staging, and production configurations.
In this guide, we’ll walk through how to configure .env files for Horilla, so your application loads the correct settings securely and efficiently.
This process is essential whether you’re just getting started with local development or preparing Horilla HRMS for a pre-production environment.
Why Use Environment Variables?
Environment variables help you:
Keep sensitive data like API keys, database passwords, and Django’s SECRET_KEY out of your source code.
Easily switch configurations between development, testing, and production environments.
Avoid hardcoding environment-specific settings directly into your app.
Step 1: Open the Project Directory
Start by opening a terminal and navigating to your working directory. For example:
cd development/horilla
Then, launch your preferred IDE. If you’re using Visual Studio Code, simply run:
code .
This will open the Horilla project in your editor.
- If you don’t have VS Code yet, download it here: https://code.visualstudio.com/download
Step 2: Create and Configure the .env File
Inside the root of the Horilla project, you’ll find a file named:
.env.dist
This is a template containing all the necessary environment variable keys your project expects.
To set up:
Create a new file in the same directory named:
.env
Copy the contents of .env.sample into your new .env file.

Adjust the values based on your environment (development or pre-production).
Step 3: How Environment Variables Are Loaded
Horilla loads these variables automatically from the .env file.
If you navigate to:
horilla/settings.py
You’ll notice code that reads and applies values from the .env file using the os.environ API. Common variables used include:
- DEBUG

- SECRET_KEY

- ALLOWED_HOSTS

- DATABASE_URL

- ect..
These are referenced throughout the settings to configure Django securely.
Step 4: Key Variables in the Template
Here’s a breakdown of important entries in the .env.sample file:
DEBUG
Controls Django’s debug mode:
- Set to True in development
- Set to False in production
SECRET_KEY
This is the secret cryptographic key Django uses internally. Replace the insecure default value with a strong, unique key in production.
ALLOWED_HOSTS
Define which domains or IPs can access your app.
- For local development: use * or localhost
- For production: add your domain name here
DATABASE_URL
Specify your database connection string.
For PostgreSQL:
postgres://user:password@host:port/dbname
If not set, Horilla defaults to using SQLite for development.
You can also manually configure database settings by specifying:
- DB_ENGINE (e.g., django.db.backends.postgresql)
- DB_NAME
- DB_USER
- DB_PASSWORD
- DB_HOST
- DB_PORT
Comment out or replace the SQLite configuration as needed.
LDAP, Cloud Storage Settings, or Additional Settings
Toward the bottom of the .env.dist file, you’ll also find placeholders for:
- LDAP configuration
- Cloud storage access keys
- File format support
- You can update these based on your integration needs.
Step 5: Run the Server
Once your .env file is configured, run the development server:
python manage.py runserver
Horilla will load all the environment variables and start with the appropriate settings.
Conclusion
Properly configuring environment variables is not just a technical step; it’s a foundational practice for maintaining security, scalability, and maintainability in your Horilla deployments.
By using a .env file to manage settings like DEBUG, SECRET_KEY, ALLOWED_HOSTS, and DATABASE_URL, you gain the flexibility to:
- Isolate development, staging, and production environments with ease.
- Secure sensitive information by keeping credentials and API keys out of your source code.
- Adapt quickly to different deployment infrastructures (e.g., local server, Docker, AWS, or cloud platforms).
Whether you’re working solo or in a team, following these practices reduces the chances of misconfiguration, especially when moving from local development to production.
Best Practices to Keep in Mind:
- Never commit .env files to version control (e.g., Git). Always list them in your .gitignore.
- Use strong, unique values for secrets like SECRET_KEY in production.
- Keep your development and production values separate—consider using a .env.dev, .env.staging, and .env.prod approach if needed.
- Back up your .env files securely to avoid loss of critical credentials.
- Use environment variable managers (like Direnv, Dotenv CLI, or platform-specific config tools) for large-scale or team projects.
By configuring and managing environment variables correctly, you ensure that Horilla behaves predictably and securely, no matter where it’s deployed. This approach also prepares your system for smoother scaling and integration with external services like databases, authentication systems (e.g., LDAP), and cloud storage.
As your application grows in complexity and reaches more users, this modular and secure configuration style becomes even more critical.
