At the time of the 2018 Spring Festival, heaven knows what I went through, posting a blog article on the fourth day of the new year. Django was actually configured before the New Year; I had just learned some knowledge about developing web applications with python at that time, so I configured it along the way.

Environment used for the configuration

  • System: Ubuntu16.04 (LTS)
  • python version: python3.6 (using Anaconda to create a virtual environment)

Preparation

Uninstalling an old version of Django

If you are upgrading from an older version of Django, you need to deal with the old version a little.

  1. If the previous version of Django was installed through pip or easy_install, running pip or easy_install again will automatically handle the old version of Django, so you can install directly without any extra work.
  2. If it was previously installed through python setup.py install, uninstalling means deleting the Django library from the python packages; the path of the Django library can be found with the following command:
$ python -c "import django; print(django.__path__)"

Installing Apache (optional)

If Django is used in a real environment rather than a test development environment, Apache and mod_wsgi need to be installed. Before installing Apache, APR, APR-Util and Pcre need to be installed.

  • Installing APR:

Download the APR package, decompress it, and run the following commands in the decompressed folder (the folder name should not contain the version number) to install:

$ ./configure --prefix=/usr/local/apr
$ make 
$ make install 
  • Installing APR-Util:

Likewise, download the APR-Util package, decompress it, and run the following commands in the decompressed folder (the folder name should not contain the version number) to install:

$ ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr 
$ make 
$ make install
  • Installing Pcre:

Download the Pcre package; note that it is pcre rather than pcre2. Then decompress it and run in the decompressed folder:

$ ./configure --prefix=/usr/local/pcre
$ make
$ make install
  • Installing Apache2:

Download the Apache2 package, decompress it, enter the folder and run the following commands:

$ ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/  --with-pcre=/usr/local/pcre
$ make
$ make install

Installing mod_wsgi

Install it with the following commands:

$ sudo apt-get install apache2-dev
$ sudo pip install mod_wsgi

Installing Django

First create a virtual environment:

$ conda create -n django_py36 python=3.6

Install Django in the virtual environment:

(django_py36)$ sudo pip install Django

At this point the Django installation is finished.

Reference

Django Documentation

Apache documentation

fresheer’s blog — installing Apache and mod_wsgi on ubuntu