RSS

Installing AnW

Attention: This guide has been written for AnW version 1.0. Since then there have been a series of changes to Django, AnW and its dependencies. Proceed with caution. This guide will be updated soon...

Download

The latest stable and trunk (development) releases are now available on launchpad.net. Use the Bazaar version control system to check the sources out of the repo. If you are interested in the more experimental version try the trunk branch. I strongly recommend the stable branch.

Installation Guide

Before installing this project you need to get Python and Django running successfully on your server. How to get the mini (development) web-server comming with Django up and running is explained in the official tutorial [1]. This guide will only cover the setup of a production server running on an Apache server with MySQL database.

Python and Django

Installing Python and Django is rather trivial. Simply install Python from your repository. If you distro does not offer Python2, get it from python.org and install it.

The Django version in your distro’s repository might be a bit old; therefore I suggest downloading and installing the latest version from the project’s homepage [2].

Apache & MySQL

When installing MySQL (or any other database supported by Django) you should be fine. Just create a user and a database to which the user has access.

When you are using the Apache coming with your repo you should be very fine when you follow the instructions [3] given by the Django Team. As an example here is the configuration of the Apache server of my virtual machine I used for testing and development in the days before releasing a version.

  1. Enable mod_wsgi
  2. Create the file django.wsgi in a subfolder (e.g. "apache") in the project’s root with the following content.
    import os
    import sys
    import django.core.handlers.wsgi
    paths = [ "/home/andi/","/home/andi/aintnowiki/" ]
    for p in paths:
        if p not in sys.path:
            sys.path.append(p)
    
    os.environ["DJANGO_SETTINGS_MODULE"] = "aintnowiki.settings"
    
    application = django.core.handlers.wsgi.WSGIHandler() 
    
  3. Tell your Apache to serve the Wiki, e.g. in /etc/apache2/sites-enabled/default.
    NameVirtualHost 192.168.56.101:80
    <VirtualHost *:80>
        ServerAdmin webmaster@hasenkopf2000.net 
        ServerName 192.168.56.101 
        RewriteEngine on 
        RewriteOptions Inherit 
    
        # RewriteRule ^/users(.*) https://192.168.56.101 /users/$1
        # RewriteCond %{REQUEST_URI}% ^/admin/filebrowser/browse/.*$
        # RewriteRule ^/admin/(.*) $https://192.168.56.101/admin/$1
    
        # RewriteCond %{REQUEST_URI}% !^/admin/filebrowser/.*$
        # RewriteRule ^/admin(.*) https://192.168.56.101/admin/$1
    
        WSGIScriptAlias / /home/andi/aintnowiki/apache/django.wsgi
        Alias /media/ /home/andi/aintnowiki/media/
    
        <Directory /home/andi/aintnowiki/media>
            Order deny,allow
            allow from all
        </Directory>
        
        ErrorLog /var/log/apache2/error.log
        LogLevel warn
        CustomLog /var/log/apache2/access.log combined
    </VirtualHost>
    
  4. Edit settings.py to match your project’s requirements. Take a close look on all variables containing path informations! Also take a look at ADMINS, ALLOWED_HOSTS, DATABASES (user, password, DB name, etc.), INSTALLED_APPS (comment out apps you don’t need, but be careful not to comment out important apps).
    If your server does not support HTTPS, make sure to set HTTPS_SUPPORT = False!
  5. In the project’s root run python manage.py syncdb to setup the required tables and initial data in the DB.
  6. Restart Apache

Notice the importance of restarting Apache after making changes to its config or the Python files of the project!

Enabling HTTPS

In order to protect your server and the data of your users it is a good idea to set up a secure host, too. If you are afraid of spending an ass-load of money on an SSL certificate, you can simply make your own one and set up a HTTPS host.

  1. Install openssl and run it.
    openssl req -new -x509 -days 1825 -nodes -out server.pem -keyout server.pem
    
  2. The resulting certificate server.pem should be put in a location where you and Apache can find it, e.g. in the subfolder "apache" in the project’s root.
  3. Tell Apache to serve the project also via HTTPS, e.g. in /etc/apache2/sites-enabled/ssl.
    NameVirtualHost 192.168.56.101:443 
    <VirtualHost *:443>
        ServerAdmin webmaster@hasenkopf2000.net
        ServerName 192.168.56.101
    
        RewriteEngine On
    
        RewriteCond %{REQUEST_URI}% !^/admin/filebrowser/browse.*$
        RewriteRule ^/admin/filebrowser/(.*)$ http://192.168.56.101/admin/filebrowser/$1
    
        WSGIScriptAlias / /home/andi/aintnowiki/apache/django.wsgi
        Alias /media/ /home/andi/aintnowiki/media/
        Alias /admin_media/ /usr/local/lib/python2.6/dist-packages/django/contrib/admin/media/
    
        <Directory /home/andi/aintnowiki/media>
            Order deny,allow
            allow from all
        </Directory>
    
        ErrorLog /var/log/apache2/error.log
        LogLevel warn
        CustomLog /var/log/apache2/access.log combined
    
        SSLEngine on
        SSLCertificateFile /home/andi/aintnowiki/apache/server.pem
    </VirtualHost>
    
  4. Uncomment the Rewrite... statements in the Apache HTTP config.
  5. Restart Apache.

Notice the Condition in front of the redirection of the /admin URL. This is due to the effect, that a Flash-based upload button does not support HTTPS. Therefore Apache needs to serve this button using HTTP.

References

  1. https://docs.djangoproject.com/en/dev/intro/overview/
  2. https://www.djangoproject.com/download/
  3. https://docs.djangoproject.com/en/1.6/howto/deployment/modwsgi/