# Installing and configuring Django on unmanaged servers

> Install Django in a Python virtual environment on an unmanaged server and set up its administration interface.

Source: https://helpcenter.ruachost.com/developers/programming-languages/installing-and-configuring-django-on-unmanaged-servers/

This guide explains how to install and configure Django on an unmanaged server.

## Installing Django

1. **Create a virtual environment for Python** using `virtualenv` and install Django.
2. **Log in to your server using SSH.**
3. **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
```

4. **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
```

5. ## Check the installed Django version

```
django-admin --version
```

## Configuring Django

1. ## Create a new Django project

```
cd ~/django-apps
django-admin startproject mysite
```

2. **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']
```

3. **Start the development web server** (replace with your server IP):

```
python ~/django-apps/mysite/manage.py runserver xxx.xxx.xxx.xxx:8000
```

4. **Visit the site** in your browser: `http://xxx.xxx.xxx.xxx:8000`\
   You should see: "The install worked successfully! Congratulations!"

## Configuring the administration interface

1. ## Run migrations and create a superuser

```
cd ~
python ~/django-apps/mysite/manage.py migrate
python ~/django-apps/mysite/manage.py createsuperuser
```

2. **Provide the admin username, e-mail, and password** when prompted.
3. ## If the development server is not running, start it

```
python ~/django-apps/mysite/manage.py runserver xxx.xxx.xxx.xxx:8000
```

4. **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](http://docs.djangoproject.com/)
- Django extensions: <https://github.com/django-extensions/django-extensions>
