OBu OBu - 2 years ago 169
Linux Question

Deploy Django project using wsgi and virtualenv on shared webhosting server without root access

I have a Django project which I would like to run on my shared webspace (1und1 Webspace) running on linux. I don't have root access and therefore can not edit apache's httpd.conf or install software system wide.

What I did so far:

  • installed squlite locally since it is not available on the server

  • installed Python 3.5.1 in ~/.localpython

  • installed virtualenv for my local python

  • created a virtual environment in ~/ve_tc_lb

  • installed Django and Pillow in my virtual environment

  • cloned my django project from git server

After these steps, I'm able to run
python manage.py runserver
in my project directory and it seems to be running (I can access the login screen using lynx on my local machine).

I read many postings on how to configure fastCGI environments, but since I'm using Django 1.9.1, I'm depening on wsgi. I saw a lot about configuring django for wsgi and virtualenv, but all examples required access to httpd.conf.

The shared web server is apache.
I can create a new directory in my home with a sample hello.py and it is working when I enter the url, but it is (of course) using the python provided by the server and not my local installation.
When I change the first line indicating which python version to use to my virtual environment (
), it seems to use the correct version in the virtual environment. Since I'm using different systems for developing and deployment, I'm not sure whether it is a good idea to e.g. add such a line in my

Update 2016-06-02
A few more things I tried:

All in all it seems like my provider 1und1 did not install wsgi extensions (even though the support told me a week ago it would be installed)

Update 2016-06-12: I got a reply from support (after a week or so :-S ) confirming that they dont have mod_wsgi but wsgiref...

So I'm a bit stuck here - which steps should I do next?
I'll update the question regularly based on comments and remarks. Any help is appreciated.

Answer Source

Since your apache is shared, I don't expect you can change the httpd.conf but use instead your solution. My suggestion is:

  1. If you have multiple servers you will deploy your project (e.g. testing, staging, production), then do the following steps for each deploy target.
  2. In each server, create a true wsgi.py file which you will never put in versioning systems. Pretty much like you would do with a local_settings.py file. This file will be named wsgy.py since most likely you cannot edit the apache settings (since it is shared) and that name will be expected for your wsgi file.
  3. The content for the file will be:

     from my_true_wsgi import *

    Which will be different for each deploy server, but the difference will be, most likely, in the shebang line to locate the proper python interpreter.

  4. You will have a file named my_true_wsgi to have it matching the import in the former code. That file will be in the versioning systems, unlike the wsgi.py file. The contents of such file is the usual contents of the wsgi.py on any regular django project, just that you are not using that name directly.

With this solution you can have several different wsgi files with no conflict on shebangs.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download