Installing and configuring Django on unmanaged servers
This guide explains how to install and configure Django on an unmanaged server.
Installing Django
Section titled “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 python3apt-get install python3-pippip3 install virtualenvAlmaLinux / Fedora:
yum install python34yum install python34-pippip3 install virtualenv- Create and activate a virtual environment as a regular user:
cd ~mkdir django-appscd django-appsvirtualenv envsource env/bin/activatepip install django-
Check the installed Django version
Section titled “Check the installed Django version”
django-admin --versionConfiguring Django
Section titled “Configuring Django”-
Create a new Django project
Section titled “Create a new Django project”
cd ~/django-appsdjango-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
Section titled “Configuring the administration interface”-
Run migrations and create a superuser
Section titled “Run migrations and create a superuser”
cd ~python ~/django-apps/mysite/manage.py migratepython ~/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
Section titled “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
Section titled “More information”- Official Django documentation: http://docs.djangoproject.com
- Django extensions: https://github.com/django-extensions/django-extensions