Installing and configuring Django on unmanaged servers
This guide explains how to install and configure Django on an unmanaged server.
Installing Django
-
Create a virtual environment for Python using
virtualenvand install Django. -
Log in to your server using SSH.
-
Install Python, pip, and virtualenv (as root):
Debian / Ubuntu:
apt-get install python3
apt-get install python3-pip
pip3 install virtualenv
AlmaLinux / Fedora:
yum install python34
yum install python34-pip
pip3 install virtualenv
-
Create and activate a virtual environment as a regular user:
cd ~
mkdir django-apps
cd django-apps
virtualenv env
source env/bin/activate
pip install django
-
Check the installed Django version:
django-admin --version
Configuring Django
-
Create a new Django project:
cd ~/django-apps
django-admin startproject mysite
-
Edit the settings file
/home/username/django-apps/mysite/mysite/settings.py:
-
Ensure debug mode is enabled:
DEBUG = True
-
Set allowed hosts (replace with your server’s IP address):
ALLOWED_HOSTS = ['xxx.xxx.xxx.xxx']
-
Start the development web server (replace with your server IP):
python ~/django-apps/mysite/manage.py runserver xxx.xxx.xxx.xxx:8000
-
Visit the site in your browser:
http://xxx.xxx.xxx.xxx:8000
You should see: "The install worked successfully! Congratulations!"
Configuring the administration interface
-
Run migrations and create a superuser:
cd ~
python ~/django-apps/mysite/manage.py migrate
python ~/django-apps/mysite/manage.py createsuperuser
-
Provide the admin username, e-mail, and password when prompted.
-
If the development server is not running, start it:
python ~/django-apps/mysite/manage.py runserver xxx.xxx.xxx.xxx:8000
-
Access the admin interface at
http://xxx.xxx.xxx.xxx:8000/admin
Log in with the username and password you created.
More information
-
Official Django documentation: http://docs.djangoproject.com
-
Django extensions: https://github.com/django-extensions/django-extensions