Knowledge Base

How to install and configure Django on a Linux shared hosting account

Django is a Python-based framework that enables you to quickly and easily create powerful websites. This article demonstrates how to install and configure Django on a Linux shared hosting account that uses cPanel.

After completing the following procedures, you will have a functioning Django site on your account that:

Loads a static homepage for the domain.

Loads the Django administration interface.

Uses a SQLite database.

Although we have tested and run this Django configuration on shared hosting accounts, it is not supported. You can use this configuration as a starting point for your own Django projects, but A2 Hosting cannot help you troubleshoot or debug any custom configurations.

Activate the virtual environment, using the command you noted in step 7 above. For example:

source /home/username/virtualenv/myapp/3.6/bin/activate

The command prompt now starts with (myapp:3.6) to indicate that you are working in the myapp virtual environment with Python 3.6. All of the following commands in this article assume that you are working in the Python virtual environment. If you log out of your SSH session (or deactivate the virtual environment by using the deactivate command), make sure you reactivate the virtual environment before following any of the steps below.

To install Django, type the following commands:

cd ~
pip install django

To verify the version of Django that is installed, type the following command:

django-admin --version

To create a Django project, type the following command:

django-admin startproject myapp ~/myapp

To create directories for the static project files, type the following commands:

Use a text editor to create a basic index.html file in the ~/myapp/templates/static_pages directory. The file can be as simple as a text file that says Hello world.

Type the following command:

python ~/myapp/manage.py migrate

Set up the superuser account:

Type the following command:

python ~/myapp/manage.py createsuperuser

At the Username prompt, type the administrator username, and then press Enter.

At the Email address prompt, type the administrator e-mail address, and then press Enter.

At the Password prompt, type the administrator password, and then press Enter.

Type the following command to collect the static files:

python ~/myapp/manage.py collectstatic

If you are asked if you want to overwrite existing files, type yes and then press Enter.

In cPanel, restart the Python application:

Log in to cPanel.

If you do not know how to log in to your cPanel account, please see this article.

In the SOFTWARE section of the cPanel home screen, click Setup Python App.

Under Existing applications, locate the correct application, and then click Restart.

Test the Django site:

Use your browser to go to http://www.example.com, where example.com represents your domain name. The index.html file should load.

Use your browser to go to http://www.example.com/admin, where example.com represents your domain name. You should see the Django administration login page. To log in, use the superuser credentials that you created earlier.

If the web site does not appear in your browser, try running the passenger_wsgi.py file manually. To do this, type the following command:

python ~/myapp/passenger_wsgi.py

There should not be any text output to the console when you run this file. If there are any errors, check the syntax in the configuration files.

More Information

Now that you have a Django-enabled web site up and running, you can start the real work of developing your own applications. The following resources can help:

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.