If you want to install Django in your cPanel you also have to enable  Terminal. It is not enabled by default. If you need to enable this please contact our support. To install Django on your cPanel account follow the steps below:

1) First create a python app from the “set up python app” option of your cPanel. 

2) After clicking the “set up python app” Now click on the “create application” option and you will see the screen same as below.  

In the “Application root” field type the full path of the application directory

Select your Application URL
Select the desired python version. (3.7.8 Recommended)

3) Now click on the “create” button and a virtual environment will be shown with a command at the top. You have to run the same command that you have found from the app creation from Terminal. You can also do this by directly logging into by SSH.

4) Now go to your cPanel dashboard and click on the “Terminal” option from the Advanced section. Copy the command from the previous step and paste it here to open the virtual environment.

5) Run the following command to install Django.

“pip install django” 

6) “django-admin startproject myproject .” Now type this command to start a new project. Here we are creating a project called myproject

7) Turn back to your cPanel > File manager > {your app location}/passanger_wsgi.py

8) Now edit the “passanger_wsgi.py” file. Then erase everything and copy-paste this “from myproject.wsgi import application” command here.

8) Go to your “myproject” folder and edit “settings.py” file. You will get a few codes here. You will find ALLOWED_HOSTS, you have to type your domain name here with a quotation. Example:
ALLOWED_HOSTS = [“example.com”]

9)At the bottom of the page copy-paste this code 

MEDIA_URL = '/media'
STATICFILES_DIRS=[BASE_DIR / "assets",]
STATIC_ROOT = '/home/Cpanel user name/public_html/static'
MEDIA_ROOT = '/home/Cpanel user name/public_html/media'

Note: In place of Cpanel user name, enter the username of your Cpanel.

10) Create a folder in your project folder named “assets” and create a folder in your public_html folder named “media”

11) Now go back to Terminal and run this command “chmod +x manage.py” from inside the project directory as before and then run this command “./manage.py collectstatic”

12) Restart python app from cPanel > Software section > Set up Python App > edit > restart.

Your Django installation is successful. Now visit your website and check. Thank you!

Leave a Reply