FREE .COM Domain registration in annual purchase + Huge Discounts

Contact Info

Bharatpur, Chitwan

+977 9828104810

[email protected]

Learn how to deploy your Django application in cPanel with ease. This step-by-step guide covers creating a virtual environment, installing Django, configuring your application, and starting your application on the server. Optimize your Django deployment with Noditt Host web hosting.

Deploy a Django project on cPanel can seem like a daunting task, but with the right guidance, it can be a straightforward process. In this comprehensive guide, we will cover all the necessary steps to successfully deploy Django project on cPanel, including creating a virtual environment, configuring the database, and setting up the domain.

It’s crucial to note that you will need a web hosting account that supports Python and Django before we get started. If you don’t already have one, you can open an account with Noditt Host for web hosting. Our hosting options include cPanel and are Django-optimized, making it simple to install your application.

Step 1: Create a Virtual Environment to deploy Django project

The first step in deploying a Django project on cPanel is to create a virtual environment. Virtual environments allow you to keep the dependencies for your project separate from those of other projects, ensuring that your project will run smoothly on the server.

To create a virtual environment, you will need to use a tool called virtualenv. You can install virtualenv by running the following command:

pip install virtualenv

Once virtualenv is installed, you can create a new virtual environment by running the following command:

virtualenv myenv

This will create a new directory called “myenv” in your project’s root directory, which will contain all the necessary files for your virtual environment.

Step 2: Install Django and Other Dependencies With your virtual environment created, you can now install Django and any other dependencies your project requires. To do this, you will need to activate your virtual environment by running the following command:

source myenv/bin/activate

This will change the command prompt to indicate that the virtual environment is active. You can now install Django and any other dependencies by running the following command:

pip install django

Step 3: Configure the Database of your Django Project

The next step is to configure the database for your Django project. cPanel provides a database management system called MySQL, which you can use to set up a database for your project.

To create a new database, log in to cPanel and navigate to the “MySQL Databases” section. Here, you can create a new database by entering a name and username, and then clicking “Create Database”.

Once your database is created, you will need to configure the database settings in your Django project’s settings.py file. To do this, you will need to add the following to your settings.py file:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'your_database_name',
        'USER': 'your_database_username',
        'PASSWORD': 'your_database_password',
        'HOST': 'localhost',
        'PORT': '3306',
    }
}

Make sure to replace ‘your_database_name’, ‘your_database_username’, and ‘your_database_password’ with the corresponding values for your database.

Step 4: Set up the Domain for your Django project.

The next step is to set up the domain for your Django project. To do this, you will need to log in to cPanel and navigate to the “Addon Domains” section. Here, you can add a new domain by entering the domain name and the folder where your project is located.

Once the domain is set up, you will need to update the ALLOWED_HOSTS setting in your Django project’s settings.py file. To do this, you will need to add the following to your settings.py file:

ALLOWED_HOSTS = ['yourdomain.com']  # or you can simply put '*' as well which includes all

Make sure to replace ‘yourdomain.com’ with the actual domain name of your project

Step 5: Create a WSGI Passenger File

The next step is to create a WSGI Passenger file, which is a file that tells the Apache web server how to run your Django project. To create a WSGI Passenger file, you will need to create a new file called “passenger_wsgi.py” in your project’s root directory.

The contents of the passenger_wsgi.py file should look like this:

import os
import sys

sys.path.append('/path/to/your/project')

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'your_project_name.settings')

application = get_wsgi_application()

Make sure to replace ‘/path/to/your/project’ with the actual path to your project and ‘your_project_name.settings’ with the actual name of your project’s settings.py file.

Step 6: Configure the Passenger Setup in cPanel

The final step is to configure the Passenger setup in cPanel to run your Django project. To do this, you will need to log in to cPanel and navigate to the “setup python app” section.

Here, you will need to select the version of Python that your project is using and then click on “Set as current”.

Next, navigate to the “Passenger” section and select the domain for your project. You will then need to select the document root for your project, which is the folder where your project is located, and click on “Save”.

Once the Passenger setup is configured, your Django project should be up and running on your cPanel server. You can test this by navigating to your domain in a web browser and checking if the project loads correctly.

In conclusion, deploying a Django project on cPanel can seem like a daunting task, but with the right guidance, it can be a straightforward process. By following the steps outlined in this guide, you should be able to successfully deploy your Django project on cPanel and run it in production.

Leave a Reply

Your email address will not be published. Required fields are marked *