How to Deploy Horilla on Linux Using a Single Service File

Deploying a Django application such as Horilla can appear daunting, but following the correct steps is easy. This tutorial will guide you through installing Horilla as a systemd service on a Linux server, allowing you to start, stop, and manage it easily. If you’re an experienced developer or just starting with Linux, this easy-to-follow guide will keep your deployment up and running smoothly.
Prerequisites
Before we start, ensure you have everything required for the task.
- A Linux server (eg: Amazon Linux)
- A user account with sudo privileges (preferably ec2-user for AWS Linux)
- Git installed (sudo apt install git or sudo yum install git)
- Python 3 installed (python3 –version to check)
- Pip installed (sudo apt install python3-pip)
- Virtual environment support (python3 -m venv –help to verify)
After you have all these set up, you’re ready to deploy Horilla!
Step 1: Set Up the Horilla Application
First, navigate to the /opt/ directory, create the Horilla_Main directory, and pull the Horilla source code.
cd /opt/
mkdir Horilla_Main
sudo git clone https://github.com/horilla-opensource/horilla.git master
Set Directory Ownership
Ensure the directory is owned by the user that will run the application:
sudo chown -R ec2-user:ec2-user /opt/Horilla_Main
Create a Virtual Environment
Navigate to the Horilla directory and create a virtual environment:
cd /opt/Horilla_Main
python3 -m venv horillavenv
Activate the Virtual Environment and Install Dependencies
source horillavenv/bin/activate
pip install -r requirements.txt
With the application set up, let’s configure systemd to manage the Horilla service.
Step 2: Create a Service File for Horilla
Create the Service File
Create a systemd service file for Horilla:
sudo nano /etc/systemd/system/horilla.service
Add the Following Configuration:
[Unit]
Description=Horilla Development Server
After=network.target
[Service]
User=ec2-user
Group=ec2-user
WorkingDirectory=/opt/Horilla_Main
Environment="DJANGO_SETTINGS_MODULE=horilla.settings"
ExecStart=/opt/Horilla_Main/horillavenv/bin/python3 manage.py runserver 0.0.0.0:8000
Restart=always
[Install]
WantedBy=multi-user.target
Save (Ctrl + O then enter) and exit (Ctrl + X).
Step 3: Reload Systemd and Start the Horilla Service
Run the following commands to reload systemd, enable the service to start on boot, and start Horilla:
sudo systemctl daemon-reload
sudo systemctl enable horilla.service
sudo systemctl start horilla.service
To verify if Horilla is running:
sudo systemctl status horilla.service
Step 4: Activate the Virtual Environment and Collect Static Files
If Horilla is running successfully, activate the virtual environment and collect static files:
cd /opt/Horilla_Main
. horillavenv/bin/activate
python3 manage.py collectstatic
Step 5: Configure for Production
Update Settings for Production
Open settings.py and set DEBUG to False:
sudo nano horilla/settings.py
Change:
DEBUG = False
Set ALLOWED_HOSTS
Update the ALLOWED_HOSTS list with your domain or IP address:
ALLOWED_HOSTS = ['your-domain.com', 'your-ip-address']
Step 6: Configure Media File Serving
If media files are not loading, add a route in urls.py.
Edit URLs for Media Files
Open urls.py:
sudo nano horilla/urls.py
Add Media Route
from django.conf import settings
from django.views.static import serve
from django.urls import path
urlpatterns = [
# Other paths
]
if not settings.DEBUG:
urlpatterns += [
path('media/<path:path>', serve, {'document_root': settings.MEDIA_ROOT}),
]
# if static is also not loading uncomment below lines
# urlpatterns += [
# path(static/<path:path>', serve, {'document_root': #settings.MEDIA_ROOT}),
# ]
Step 7: Restart the Horilla Service
After making all changes, restart the Horilla service to apply updates:
sudo systemctl restart horilla.service
Conclusion
By following this guide, you have successfully deployed Horilla as a systemd service on your Linux server. This setup ensures that your application runs reliably, automatically starts on reboot, and properly serves static and media files. With Horilla now configured as a service, you no longer need to manually start the application, improving stability and automation.
To verify that everything is working as expected, open your web browser and visit:
Now that Horilla is up and running, your HR management system is production-ready. You can begin using it to manage employees, process payroll, and streamline other HR-related tasks. This deployment method also makes it easier to scale your application as needed.