How to deploy a django project on cpanel

How to deploy a django project on cpanel

Aug. 1, 2020, 7:16 p.m.

 500

 300

Hey DjangoWorld,

Have a great day. Today I will show you how to deploy a Django application in cPanel or shared hosting.

 

 

 

#1. First, you have to select a python supported hosting like NameCheap. Then go to hosting and install python in your selected domain, select python version and type your Application root name

 

 

 

 

 

#2. Copy the source code and past it in your hosting terminal or connected with SSH connection and set up your required python packed like Django, MysQLclient, Pillow, etc

 

 

 

 

 

 

#3. Go to file manager and you will see that there is a new folder which is the same name as you gave the Application root name. Open that folder and you will see the same as the picture below. Open the passenger_wsgi.py and edit it. Change all text
(
import os
import sys


sys.path.insert(0, os.path.dirname(__file__))


def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    message = 'It works!\n'
    version = 'Python %s\n' % sys.version.split()[0]
    response = '\n'.join([message, version])
    return [response.encode()]
)

to ( from testdjnago.wsgi import application) and save it. 

 

 

 

 

 


then set up your first project 

##djnago-admin startproject testdjango .

 

 

 

 

Now go to testdjango>settings.py and edit it.

 

 

 

change the ALLOWED_HOSTS = [] to ALLOWED_HOSTS = ['domain.com', 'www.domain.com']

 

make sure DEBUG is False and add those code in the bottom in your django settings 

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = "/home/domainuser/path/static"

 

and 

 


MEDIA_URL = '/media/'
MEDIA_ROOT =  "home/domainuser/path/media"

save the file and again go to terminal and again use the code below

#python manage.py collectstatic

then restart your application. Boom!! deploy is done.

 

For any kinds of information please comment!!

Total Comments