Setting Up Django with CyberPanel: A Beginner-Friendly Guide

Mehedi Khan
Django Unleashed
Published in
2 min readMar 31, 2024

In this tutorial, we’ll guide you through the process of setting up Django with CyberPanel, a web hosting control panel that makes managing your website and applications simple. Django is a powerful web framework for building web applications using Python. By integrating Django with CyberPanel, you can efficiently host and manage your Django projects.

Setting Up Django with CyberPanel

Prerequisites:

  1. A server with CyberPanel installed You can install CyberPanel on your server by following their official documentation.
  2. Basic knowledge of Python and Django.
  3. SSH access to your server.

Step 1: Create a Django project

First, log into your server via SSH. Once logged in, navigate to the directory where you want to build your Django project. Then, create a new virtual environment for your project to keep your dependencies isolated.

cd /path/to/your/directory
python3 -m venv myprojectenv

Activate the virtual environment:

source myprojectenv/bin/activate

Now, install Django using pip:

pip install django

Create a new Django project:

django-admin startproject myproject

Navigate into your project directory:

cd myproject

Step 2: Configure CyberPanel

Log in to your CyberPanel control panel.

  1. Navigate to the “Website” section.
  2. Click on “Create Website”.
  3. Fill the required details like domain name, username and password.
  4. For “Type”, select “Python”.
  5. Under “Script Handler”, select “WsgiHandler”.
  6. Set “document root” to the directory where your Django project resides.

Click “Create Website” to finish setting up your website.

Step 3: Configure Django settings

Open your Django project’s settings.py file:

nano /path/to/your/directory/myproject/settings.py

Update the ALLOWED_HOSTS setting to include your domain name:

ALLOWED_HOSTS = ['yourdomain.com', 'www.yourdomain.com']

Step 4: Configure WSGI File

Create a new WSGI file for your Django project:

nano /home/yourusername/yourdomain.com/public_wsgi.py

Paste the following content into the file, replacing “myproject” with your project name:

import os
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")

application = get_wsgi_application()

Save and close the file.

Step 5: Restart CyberPanel

After completing the configuration, restart CyberPanel to apply the changes.

Step 6: Test your Django application

Visit your domain in a web browser to see if your Django application is running correctly If everything is set up correctly, you should see the default Django welcome page.

Congratulations! You have successfully set up Django with CyberPanel. You can now start building your Django web application and deploy it easily.

Thank you for reading. If you find something wrong or better ways to do it, let me know in the comments below.

If you like the post, hit the 👏 button below so that others may find it useful. You can follow me on GitHub , daily.dev community and connect with me on LinkedIn.

More Stories:

Django

25 stories

--

--

Mehedi Khan
Django Unleashed

I'm a Software engineer. I'm comfortable with Python, Django, and Full-stack Web Development. Follow To Support Me On Medium 🫠