Home WebServer PanelcPanel How to install Django on cPanel

How to install Django on cPanel

by Lê Quyền
Published: Last Updated on

In this article, AZDIGI will show you how to install Django on cPanel. If you need any support, please contact AZDIGI via the hotline at 028 888 24768 or email support@azdigi.com

Django is one of the most popular frameworks for developing web applications using Python. With cPanel, installing Django has become easier than ever. In this article, AZDIGI will guide you on how to install Django on the cPanel interface.

Step 1: Login to cPanel

Access the cPanel administration page and log in with your administrator account. Then, we will navigate to the “Software” section and select “Setup Python App”.


Step 2: Create a Python application

Next, we will create a new Python application. You need to fill in the required parameters as follows:

  • Application root: the path to the directory containing the Django application.
  • Application URL: the URL address of the application.
  • Application startup file: the path to the “wsgi.py” file in the Django application.
  • Application Entry Point: “wsgi”.

After filling in all the information, click the “Create” button.


Step 3: Install Django

  1. Copy the command to access the virtual environment created for the Python app and execute the command through the SSH interface on cPanel.
  1. Once the Python application is created, we will install Django using the Terminal. We will access the Terminal through the cPanel administration page and run the following commands:
pip install --upgrade pip

pip install django
  1. These commands will install Django on our server. After the installation is complete, we will double-check it by running the following command:
python -m django --version

  1. If the Django version is displayed, it means we have successfully installed Django.
  1. Create a Django project in the main directory (in this example, the main directory is “main_site” and the project name is “demo_project”) using the command:
django-admin startproject demo_project .
  • Note: The command has a dot at the end.
  1. After creating the project, the existing files in the root directory will look as follows:
  1. Perform the configuration edits for these files accordingly, delete the content of the “passenger_wsgi.py” file, and replace it with the following line:
from demo_project.wsgi import application
  • Perform the following steps with the commands:
echo > passenger_wsgi.py && echo "from demo_project.wsgi import application" > passenger_wsgi.py
Untitled6 1
  1. Edit the “demo_project/settings.py” file
  • Add the desired domain name to the “ALLOWED_HOSTS” line.
Untitled7 1
  • Move to the end of the file and add the following line:
STATIC_ROOT = '<đường dẫn đến public_html>/static'
  • Save and quit
  1. Add execute permission to the “manage.py” file:
chmod +x manage.py
  1. Apply the new configuration changes:
./manage.py migrate
  • If the configuration file is correct, it should display as follows:
  1. Update the content of CSS and JS related to “static_root”:
./manage.py collectstatic
  • Restart the Python app and try accessing the website.
  • Try accessing the website:

**The admin access link will be: http://python.quyenlt.com/admin

  1. Create an admin account to manage the website:
./manage.py createsuperuser
  • Try logging in to the admin panel:

How to install Django on cPanel using MySQL Database

By default, when installing Django on the cPanel Python app, the website will use the SQLite Database. However, we can create a MySQL database and configure Django to use this MySQL Database. Note that the database switch process will result in data loss in the current database.

Step 1: Create a database


Step 2: Using the Terminal, access the Python app virtual environment and edit the database information in the settings file:<project name>/settings.py

         'ENGINE': 'django.db.backends.mysql',
         'NAME': 'fmlfjqfh_python',
         'USER': 'fmlfjqfh_python',
         'PASSWORD': 'f@QAHyEBx_h=',
         'HOST': 'localhost',
         'PORT': '3306',

Then, install the mysqlclient library and re-run the command to save the configuration:

pip install mysqlclient

./manage.py migrate

Step 4: Reset the Python app and try accessing the website again


In this way, we have learned how to install Django on the cPanel interface. This will make web application development easier with Django. Hopefully, this article will be helpful to you in the process of developing your applications.

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign