DropVPS Team
Writer: Cooper Reagan
How to install Django on CentOS 7

Table of Contents
What you will read?
- 1 Prerequisites
- 2 Step 1: Update Your System
- 3 Step 2: Install Required Packages
- 4 Step 3: Install Virtual Environment
- 5 Step 4: Create a Virtual Environment
- 6 Step 5: Install Django
- 7 Step 6: Create a New Django Project
- 8 Step 7: Configure the Database
- 9 Step 8: Migrate the Database
- 10 Step 9: Create a Superuser
- 11 Step 10: Run the Development Server
- 12 Step 11: Access the Admin Panel
- 13 Conclusion
Django is a powerful web framework for building web applications quickly and efficiently. If you’re looking to set up a Django environment on a CentOS 7 server, you’re in the right place. In this guide, we’ll walk you through the installation process step by step.
Prerequisites
Before you start, make sure you have the following:
- A CentOS 7 server
- Root or sudo access
- Basic knowledge of the command line
Step 1: Update Your System
First, ensure that your system is up to date. Open your terminal and run:
sudo yum update -y
This command will update all the packages on your CentOS 7 server.
Step 2: Install Required Packages
Django requires Python, so let’s install Python and some essential development tools. Run the following command:
sudo yum install python3 python3-pip python3-devel gcc -y
This will install Python 3, pip (Python package manager), and development tools required for building Python packages.
Step 3: Install Virtual Environment
It’s a good practice to use a virtual environment for your Django projects. This keeps your dependencies organized and manageable. Install the virtual environment package:
sudo pip3 install virtualenv
Step 4: Create a Virtual Environment
Now, let’s create a directory for your Django project and set up a virtual environment inside it. Navigate to your desired directory and run:
mkdir ~/mydjangoapp
cd ~/mydjangoapp
virtualenv venv
Activate the virtual environment with the following command:
source venv/bin/activate
Your command prompt should change to indicate that the virtual environment is active.
Step 5: Install Django
With the virtual environment activated, you can now install Django. Use pip to install the latest version of Django:
pip install django
You can verify the installation by checking the Django version:
django-admin --version
Step 6: Create a New Django Project
Now that Django is installed, let’s create a new project. Run the following command:
django-admin startproject myproject
This creates a new directory called myproject with the necessary files.
Step 7: Configure the Database
For this example, we will use SQLite, which comes bundled with Django. You can find the database configuration in myproject/settings.py. Open the file with your favorite text editor:
nano myproject/settings.py
Make sure the DATABASES section looks like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
Step 8: Migrate the Database
Now it’s time to set up the database tables. Run the following command:
python manage.py migrate
This command applies all the migrations, creating the necessary tables in your SQLite database.
Step 9: Create a Superuser
To access the Django admin panel, you need to create a superuser. Run:
python manage.py createsuperuser
Follow the prompts to set up your username and password.
Step 10: Run the Development Server
You’re almost there! You can now run the Django development server. Use this command:
python manage.py runserver 0.0.0.0:8000
Your Django application will be accessible at http://your_server_ip:8000/.
Step 11: Access the Admin Panel
To access the Django admin panel, navigate to http://your_server_ip:8000/admin/ in your web browser. Log in using the superuser credentials you created earlier.
Conclusion
Congratulations! You have successfully installed Django on your CentOS 7 server. You are now ready to start building your web applications. Remember to deactivate the virtual environment when you’re done working:
deactivate
With this setup, you can explore the vast capabilities of Django and create robust applications. Happy coding!