Setup a Django Web Server – Part 1

Part 1 of 2: How to setup a Debian based Django web development server. This tutorial is the exact instructions I am using in my development environment.

I love learning new things. Django is no exception. Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.

Why do I want to learn Django? Because I have a few ideas of some dynamic, database driven websites I want to launch in the near future and Django is known for it’s rapid development workflow.

Not long ago, I started learning the basics of Python. I feel I know enough to be dangerous. So, I started diving into Django web-framework. The early stages of my Django learning were pretty tough. I couldn’t wrap my head around a lot of the basics.

I’m at the point where I feel I have a handle on the basics. This article is going to show how I setup and configured a bare-bones debian server to be my Django web development environment. I have rebuilt my server at least 5 times during this learning phase so I can provide you the most accurate guide and information possible.

One quick note I would like to add is the fact that we are not using any type of version control in this article since it’s out of the scope of this tutorial. I do recommend you learn and use version control.

1. Install the OS

Follow along with that article but make sure to select the “Standard System Utilities” option as in the screenshot below:

Also a quick tip for configuring the networking settings during the install:

If it’s a physical server, unplug the network cable before beginning the setup.

If it’s a virtual machine, go into the networking settings and uncheck the cable connected option.

This will bring up an option to manually configure the networking settings during the install. Then after manually configuring the settings, you can plug the cable back in if it’s a physical machine, or check the cable connected option within the VM settings.

2. Install Some Basic Utilities

These are a few of my favorite Linux utilities that I like to install.

Now that we have our base system ready, let’s review what utilities I like installing and why.

openssh-server: So I can remotely connect to this server from my laptop.

screen: Use multiple windows with one SSH session. Also save us from disconnection disasters.

tree: Nice visual tree representation of a folder structure. I like this tool while learning Django since there is a lot happening with many directories and files.

vim: By default Vim is already installed but only a very basic version. This will give us more functionality within Vim.

sudo: Give us the ability to run root commands via sudo rather than logging in as root.

Log into the server as the non-root account, then switch user to root:

su root

Re-synchronize the package index files from their sources and upgrade and then install new packages currently installed on the system:

apt-get update && apt-get upgrade

Install the utilities:

apt-get install openssh-server screen curl tree vim sudo

Configure Vim

cp /usr/share/vim/vim73/vimrc_example.vim ~/.vimrc

3. Configure Sudo (Sudoers)

We need to configure sudo to allow our non-root account root access on-the-fly rather than having to switch the user account to root.

While still logged-in as root, run the following command to add your user account to the sudo group:

substitute cdavis for your user account

usermod -aG sudo cdavis

Log all the way out of the server (both root and non-root accounts) by typing exit then enter twice. You want to be at the login prompt.

4. Remotely Connect Using SSH

Now that we are logged completely out of the server, let’s remotely manage the server from the comfort of our desktop or laptop using SSH.

To read my quick tip on connecting to the Debian Linux server using SSH from either Windows 8.1 or Mac OS X, check out this article.

After you successfully connect to the server over SSH, run screen in order to start a screen session (in case we get disconnected from the server we will be able to reconnect to that session later.)