New

Experience Smart HR with Horilla Mobile App

Google Play Store Google Play Store
Home / Blogs

How to Set Up Environment Variables in Horilla for Development & Pre-Production

HRMS Software
·

July 14, 2025

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.

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.

Horilla Editorial Team Author

Horilla Editorial Team is a group of experienced writers and editors who are passionate about HR software. We have a deep understanding of the HR landscape and are committed to providing our readers with the most up-to-date and informative content. We have written extensively on a variety of HR software topics, including applicant tracking systems, performance management software, and payroll software etc. We are always looking for new ways to share our knowledge with the HR community. If you have a question about HR software, please don't hesitate to contact us.