Deploy application with Django (only for golem site)

Deploy application with Django

How to go about developing Django projects.

Introduction

Warning: The following considerations are valid only for websites residing on golems (virtual host with domain web.cs.unibo.it); therefore they are not valid for sites on gocker (domain tw.cs.unibo.it).

Django applications need an entry point to be launched. Typically the entry point is a wsgi file. The student web spaces virtual hosts are all configured with wsgi support.

In particular, there is a directive that allows the /home/web/site1626/wsgi.wsgi file to be used as an entry point for Django.

It is possible to use python virtualenvs, preparing them from a machine other than the webserver, on which students do not have a shell to work with. Details will be explained in the next sections.

Virtualhost level directives

The virtualhost relative to each web space (in the example relating to the site1626 group) the following directive is used: WSGIScriptAlias ​​/ wsgi /home/web/site1626/html/wsgi.wsgi This means that Django's wsgi file is the wsgi.wsgi file specified in the directive (obviously site1626 must be replaced with its own site).

The wsgi file must be created by the students. The wsgi.wsgi file is obviously interpreted by the webserver as a wsgi script.

Virtualenv

in case you want to use python virtualenv, you have to consider the following:

  1. directives cannot be created on the websever golem, as students do not have a shell on the webserver.
  2. A natural place to create virtualenv are the machines of the laboratories. Be careful though that the webserver is a debian wheezy while the machines in the labs are debian jessie. This could lead to incompatibility problems between libraries, that is, virtualenv may not work on the webserver.
  3. To get around the above problem, you could create the virtualenv on a debian wheezy machine. However, it is up to the students to find a way to create the virtual machine, for example outside the services offered by the Department.

A typical place to put virtualenvs is as follows (assuming the web space is site1626): / Home / web / site1626 / data / and maybe in a subfolder called venv. Inside the virtualenv students can install Django to the version they want if the one installed in the webserver is not considered updated enough.

Where to create your own Django project

Rather than creating the Django project in the document root / Home / web / site1626 / html / it is preferable to create it in a folder that is not directly exposed to the web. This is for security reasons. A good place is the following / Home / web / site1626 / data / project where the project folder can be replaced with a name of your choice.

Configure the wsgi.wsgi file

As mentioned, the /home/web/site1626/html/wsgi.wsgi file must represent the entry point of the django application. When creating a Django project, a wsgi.py file is created by default which acts as the entry point wsgi. The default version of Django must be changed in order to set the path to reach your virtualenv and your project and to activate your virtualenv. Attached is an example of a wsgi.wsgi file.

How to reach the Django application

Assuming that Django is installed in the site1626 web space, the Django application can be reached from the URL: http://site1626.web.cs.unibo.it/wsgi/

Other notes

Students do not have access to the virtualhost configuration that configures their web space. Therefore they cannot issue Apache directives related to the wsgi daemon process, as indicated in the Django documentation