• DevOps
    Case Study

    How we built a resilient multi-account, multi-cloud solution for a Health Tech service provider!

    READ CASESTUDY
    icon

    24/7 DevOps as a Service

    Round-the-clock DevOps for uninterrupted efficiency.

    icon

    Infrastructure as a Code

    Crafting infrastructure with ingenious code.

    icon

    CI/CD Pipeline

    Automated CI/CD pipeline for seamless deployments.

    icon

    DevSecOps

    Integrated security in continuous DevOps practices.

    icon

    Hire DevOps Engineers

    Level up your team with DevOps visionaries.

    icon

    Consulting Services

    Navigate success with expert DevOps consulting.

  • TechOps
    Case Study

    How we built a scalable Odoo solution for a Travel Tech service provider!

    READ CASESTUDY

    WEB HOSTING SUPPORT

    icon

    HelpDesk Support

    Highly skilled 24/7 HelpDesk Support

    icon

    Product Support

    Boost your product support with our expertise.

    MANAGED SERVICES

    icon

    Server Management

    Don’t let server issues slow you down. Let us manage them for you.

    icon

    Server Monitoring

    Safeguard your server health with our comprehensive monitoring solutions.

    STAFF AUGMENTATION

    icon

    Hire an Admin

    Transform your business operations with our expert administrative support.

    icon

    Hire a Team

    Augment your workforce with highly skilled professionals from our diverse talent pool.

  • CloudOps
    Case Study

    How we helped a Private Deemed University in India, save US $3500/m on hosting charges!

    READ CASESTUDY
    icon

    AWS Well Architected Review

    Round-the-clock for uninterrupted efficiency

    icon

    Optimize

    Efficient CloudOps mastery for seamless cloud management

    icon

    Manage

    Automated CI/CD pipeline for seamless deployments

    icon

    Migrate

    Upgrade the journey, Migrate & Modernize seamlessly

    icon

    Modernize

    Simplify compliance complexities with our dedicated services

    icon

    FinOps as a Service

    FinOps as a Service

  • SecOps
    Case Study

    How we built a scalable Odoo solution for TravelTech service provider!

    READ CASESTUDY
    icon

    VAPT

    Vulnerability Assessment and Penetration Testing

    icon

    Source Code Review

    Ensuring source code security ans safe practices to reduce risks

    icon

    Security Consultation

    On demand services for improving server security

    icon

    System Hardening

    Reduced vulnerability and proactive protection

    icon

    Managed SoC

    Monitors and maintains system security. Quick response on incidents.

    icon

    Compliance as a Service

    Regulatory compliance, reduced risk

  • Insights
    Case Study

    How we helped a Private Deemed University in India, save US $3,500/m on hosting charges!

    READ CASESTUDY
    icon

    Blog

    Explore our latest articles and insights

    icon

    Case Studies

    Read about our client success stories

    icon

    Flipbook

    Explore our latest Flipbook

    icon

    Events

    Join us at upcoming events and conferences

    icon

    Webinars

    Watch our educational webinar series

  • Our Story
  • Contact Us

Interested to collaborate?

Get in touch with us!

Ready to elevate your business with certified cloud expertise? Contact us today to learn how our team can help you leverage cloud technology to drive growth, streamline operations, and enhance security.

  • AWSAWS
  • Azure CloudAzure Cloud
  • Google CloudGoogle Cloud
  • Akamai CloudAkamai Cloud
  • OVHOVH
  • Digital OceanDigital Ocean
  • HetznerHetzner
  • Kubernetes Consultancy Services
  • K8s & Cloud native Solutions
  • 24/7 Infrastructure Monitoring
  • DevOps as a Service
  • Cloud CI/CD Solutions
  • White Labeled MSP Support
  • Our story
  • Life@SupportSages
  • Insights
  • Careers
  • Events
  • Contact Us

Connect with us!


LinkedInFacebookXInstagramYouTube

aws partneraws advanced partner
SupportSages

Copyright © 2008 – 2026 SupportSages Pvt Ltd. All Rights Reserved.
Privacy PolicyLegal TermsData ProtectionCookie Policy

How To Configure Django With Apache In CentOS 7

Travis Ville

  • 6 min read
How To Configure Django With Apache In CentOS 7

Generating audio, please wait...

Django is a Python-based free and open-source web framework that can be used for developing dynamic websites and web applications. In this article, we will explain the procedures to configure Django with Apache in CentOS 7.

Requirements

  • Server running with CentOS 7
  • Static IP address configured on your system. (We are using IP 148.251.214.61 as an example)
  • User with sudo privilege.

Install Apache Web Server

Before starting the configuration, update the server with the latest version using the following command. It will install all the latest patches and security updates to your system.

sudo yum update -y

Install the EPEL repository on your server using the following command.

sudo yum install epel-release -y
After enabling the EPEL repository, you can install Apache and other required packages using the following command.
sudo yum install python2-pip httpd mod_wsgi -y

Proceed to the next step once the installation is completed.

Install Django

Before installing Django, it is required to create the Python virtual environment. So you will need to install “virtualenv”.

sudo pip install virtualenv

After installing the “virtualenv” create a project directory for Django.

sudo mkdir /opt/djangoproject

Create a Python virtual environment using the following commands.

cd /opt/djangoproject sudo virtualenv djangoprojectenv

Enable the virtual environment to install packages.

sudo source djangoprojectenv/bin/activate

Install Django in the djangoprojectenv shell using pip command.

djangoprojectenv) [root@server djangoproject]# pip install django

Once the installation is completed, you can verify the Django version using the following command.

(djangoprojectenv) [root@server djangoproject]# django-admin --version

You should see something similar to:

1.11.18

Create the Django Project

Once Django is installed in the directory, create first Django project using the following command.

djangoprojectenv) [root@server djangoproject]# django-admin.py startproject myfirstproject.

Next, Modify the file “settings.py"

(djangoprojectenv) [root@server djangoproject]# vi myfirstproject/settings.py

Add the following line at the end of the file and save.

STATIC_ROOT = os.path.join(BASE_DIR, "static/")

Transfer the database of the project to the SQLite database using the command given below.

(djangoprojectenv) [root@server djangoproject]# ./manage.py migrate

Output :

Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions 
Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying sessions.0001_initial... OK

Create a superuser for Django. While creating superuser you will be asked to select a username, e-mail address and password.

(djangoprojectenv) [root@server djangoproject]# ./manage.py createsuperuser 
Username (leave blank to use 'root'): djangoadmin Email address:   Password:  Password (again):  
Superuser created successfully.

Collect all of the static content into the directory location we configured earlier using the following command.

(djangoprojectenv) [root@server djangoproject]# ./manage.py collectstatic

Add server’s IP address to “request.py" file to access Django from the remote machine.

(djangoprojectenv) [root@server djangoproject]# vi djangoprojectenv/lib64/python2.7/site-packages/django/http/request.py
 Add server IP address as shown below and save the file.
allowed_hosts = ['localhost', '148.251.214.61', '[::1]']

Test Django project by running the following command.

(djangoprojectenv) [root@server djangoproject]#./manage.py runserver 0.0.0.0:8989

Open your web browser and type the URL “http://148.251.214.61:8989", you should see your first Django page.

You can also access the Django admin page by typing the URL “http://148.251.214.61:8989/admin" on your web browser. Enter username “djangoadmin" and the password which you have created earlier.

To exit from your virtual environment, use the following command.

(djangoprojectenv) [root@server djangoproject]# deactivate

Configure Django for Apache

After creating a Django project, it is time to configure Apache web server for Django. Create a new configuration file.

sudo vi /etc/httpd/conf.d/django.conf

Add the following code and save the file.

Alias /static /opt/djangoproject/static <Directory /opt/djangoproject/static>  
Require all granted </Directory> <Directory /opt/djangoproject/myfirstproject>    
<Files wsgi.py>        
Require all granted    
</Files> </Directory> WSGIDaemonProcess myfirstproject python-path=/opt/djangoproject:/opt/djangoproject/djangoprojectenv/lib/python2.7/site-packages WSGIProcessGroup myfirstproject WSGIScriptAlias / /opt/djangoproject/myfirstproject/wsgi.py

Restart Apache service and enable it to start at boot.

sudo systemctl restart httpd sudo systemctl enable httpd

Set proper ownership so “httpd" has permission to use the Django project directory.

sudo chown -R apache:apache /opt/djangoproject

You can access your Django site using the URL “http://148.251.214.61/admin" on your web browser without specifying any port.

Get 24/7 expert server management

  • Apache
How To Configure Django With Apache In CentOS 7

6 ways how Outsourcing Server Management will improve Customer Retention

6 ways how Outsourcing Server Management will improve Customer Retention
  • Sever management
logo

Configuring Firewall with UFW

Configuring Firewall with UFW
  • Firewalls
  • Security
logo

Understanding the netstat command

Understanding the netstat command
  • Security
logo

Posts by Travis Ville

Travis Ville