Discussion in 'General' started by dayjahone, Jun 11, 2008.

  1. dayjahone

    dayjahone Member

  2. charles

    charles Banned

    C'mon, give us some answers! And instructions...
  3. yonkman

    yonkman New Member

    Django and mod_wsgi

    I have set up ispconfig3 + django + mod_wsgi and have gotten it to run in a vhost just fine for me. Of course, it very well might not work for anyone else and there are no stated or implied guarantees this will work.

    I followed this tutorial


    1) installed django1.1 and latest mod_wsgi (latest version from source) as root in server (also, any other django projects that you want )


    Log into ISPCONFIG 3 admin and perform the following:
    1) create new website and user with SSH access
    2) create DB in IS

    1) ssh into your space and from your root dir (not web) enter following command:

    Code: startproject myprojectnamehere
    (replace last part with your proj name, of course)

    CD into your new project : i.e.
     cd myprojectnamehere
    create 3 directories (eggs,templates,.wsgi)

    open and edit the file and add your DB information and other settings and save the file.

    Next: (note you can use your own names here)
    cd into the .wsgi directory and create a file inside that dir called django.wsgi This will be your mod_wsgi configuration file that will be referenced in your apache config. The names of both the dir and file are up to you be remember to change them in the following options and wsgi files.

    Open and edit your .wsgi and add the following (making sure to change the paths to your server specs)

    import os
    import sys 
    os.environ['PYTHON_EGG_CACHE'] = '/var/www/clients/client1/web1/myprojectnamehere/eggs'
    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
    import django.core.handlers.wsgi
    application = django.core.handlers.wsgi.WSGIHandler()
    sys.stdout = sys.stderr

    Save the file and go back to the ISCONFIG3 ADMIN section

    go into your website section and click on the "Options" tab at the top of the section. In the Apache Directives section, enter the following making name changes where necessary.
    Alias /site-media/ "/var/www/clients/client1/web1/web/site-media/"
    	<Directory "/var/www/clients/client1/web1/web/site-media">
    		Order allow,deny
    		Options Indexes
    		Allow from all
    		IndexOptions FancyIndexing
    	Alias /admin-media/ "/usr/local/lib/python2.6/dist-packages/Django-1.1.1-py2.6.egg/django/contrib/admin/media/"
    	<Directory "/usr/local/lib/python2.6/dist-packages/Django-1.1.1-py2.6.egg/django/contrib/admin/media">
    		Order allow,deny
    		Options Indexes
    		Allow from all
    		IndexOptions FancyIndexing
    	<Directory "/var/www/clients/client1/web1/myprojectnamehere">
    		Options +ExecCGI
    		Allow from all
    WSGIScriptAlias / /var/www/clients/client1/web1/myprojectnamehere/.wsgi/django.wsgi

    It is very important that the WSGIScriptAlias directive come after your Apache Alias directives so that WSGI doesn't try to process /site-media/, /admin-media/ etc......

    Please note I use site-media and admin-media which have to be set in the file.

    That is pretty much it. Restart/Reload apache and it should work. I hope this saves someone else the time it took me to figure it all out.

    Some final Notes:

    I use setuptools to install django, and django projects that are available at pil. This creates the python egg issue addressed by the python egg cache config in the .wsgi file.

    I had to restart apache a couple of times during my trials, but I think it might work if you can get it right the first time.

    This is your basic project site for your django project. Please read all you can at about building your site and troubleshooting.
  4. Andre Silvestre

    Andre Silvestre New Member

    When I install libapache2-mod-wsgi, my apache stop working. All sites are off including ISPCOnfig...
  5. Raushan Raj

    Raushan Raj New Member

    Same here, Did you got any solution for this.
  6. ahrasis

    ahrasis Well-Known Member

    Well, I tested mailmain3 on Ubuntu 20.04 nginx web server which uses Django, among others, and it works. Not sure how difficult it can be on apache2 though.
  7. till

    till Super Moderator Staff Member ISPConfig Developer

    Check apache error.log to find out why it fails.

Share This Page