Django Cpanel starter

Aug. 10, 2020

  • server1.jpg Back-End

Cpanel starter guide for python/Django application

1)login on cpanel account

2)Open Setup Puthon App

3)Create application (say its name is myapp)

4)Open a ssh terminal:

ssh -p port username@domain.ext

Details are available by the hosting.

5)At the top page we have:

Enter to the virtual environment.To enter to virtual environment, run the command: source /home/username/virtualenv/myapp/3.7/bin/activate && cd /home/username/myapp

After that, will follow the usual procedures:

pip install Django

and create a Django project:

django-admin startproject mysite

In the /home/username/myapp we will have a Django project mysite.

mysite/
    manage.py
    mysite/
        __init__.py
        settings.py
        urls.py
        asgi.py
        wsgi.py

and a passenger_wsgi.py which is the wsgi starter of the Django application.

Default, this file display a simple text when accesing of the http://domain/myapp

The file looks like:

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 launch our Django project, we must modify it to:

import sys

sys.path.append("/home/username/myapp/mysite")
from mysite.wsgi import application

6)Open File Manager and rename file /home/username/public_html/index.html which is the default page that will be displayed to whatever you like, say index0.html

7)Restart myapp

And that's all.


Return to home