This page covers the installation of Python3, which is necessary for deploying a Django web application on a CentOS server, and then configuring the Django project.
1. Python3 Installation (yum)
Install the essential packages required for Django deployment using yum
.
sudo yum install -y epel-release # Install EPEL repository
sudo yum install -y python3 python3-pip httpd policycoreutils-python-utils # Install Python3, pip, Apache, SELinux utilities
# Gunicorn or mod_wsgi are installed in the virtual environment after Django project setup.
2. Configure Django Project
Create a directory for your Django application, and within that directory, set up a Python virtual environment to install Django and required packages. This guide uses the /home/hello
directory.
sudo mkdir -p /home/hello # Create project directory
sudo chown $(whoami) /home/hello # Grant ownership to current user
cd /home/hello # Change directory
python3 -m venv venv # Create Python virtual environment
source venv/bin/activate # Activate virtual environment
pip install --upgrade pip # Upgrade pip to the latest version
pip install django==3.2 # Install Django 3.2
# Install Gunicorn (if choosing Gunicorn integration)
pip install gunicorn
# Install mod_wsgi (if choosing mod_wsgi integration)
# pip install mod_wsgi
# Note: You don't need to use both integration methods; choose one.
django-admin startproject config . # Start Django project in current directory
python manage.py startapp hello # Create 'hello' app