You are currently viewing How to install Django in cPanel?

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.

1 1

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

2 1

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.

3 1

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.

4 1

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!