WikklyText A wikitext server and rendering library


files/feed-icon-14x14.png Recently Edited Valid XHTML 1.0 Strict
Apache+CGI edit
frank, 26 September 2009 (created 21 September 2009)
Tags: apache cgi server
Please read before continuing
  • These instructions are for WikklyText 1.9.x. If you are running an earlier version, see BehindApache instead.
  • If you are upgrading from WikklyText 1.6.x or earlier, you can delete the file wikboot.py in your wiki folder. It is no longer used.
This recipe shows a very basic CGI setup. I assume that you can run CGI scripts from any location. If that is not true, you might want to read Apache+CGI+mod_rewrite+cgi-bin instead.

For this example, I'll assume you are using the following locations. Adjust as needed:
Wiki filesystem location
/var/www/wikis/mywiki
Public URL
http://example.com/wikis/mywiki/serve.py

Create wiki


You can copy an existing wiki to /var/www/wikis/mywiki, but for this example I'll just create a new one:
mkdir -p /var/www/wikis/mywiki
cd /var/www/wikis/mywiki
wik init
Select the type of storage you want and accept the rest of the defaults. (The server options have nothing to do with your Apache setup so its safe to accept the defaults.)

On (at least) Unix/Linux systems, the wiki needs to be owned by the userid that runs the Apache process. For example, on my server the Apache process is owned by www-user, so I do:
chown -R www-user /var/www/wikis/mywiki


Add CGI script


Create a CGI script in your wiki folder:

/var/www/wikis/mywiki/wiki.py
#!/usr/bin/python
#
# Set the above line to the full path of your Python executable

#--------------------------------------------------------------------
# You PROBABLY don't need to change anything below here, but take
# a quick glance just in case.
#--------------------------------------------------------------------

# If wiki.py is in your wiki directory, you can leave WIKIPATH alone.
# However, if your CGI scripts are in a seperate directory, you'll need
# to set this to point to your wiki path.
import os
WIKIPATH = os.path.split(os.path.abspath(__file__))[0]

# Normally you can leave this set to None, but if needed, you set it like this:
#     My wiki URL = http://example.com/my/wiki/serve.py
#     SCRIPT_NAME = '/my/wiki/serve.py'
SCRIPT_NAME = None

# set True to use logging
USE_LOGGING = False

# nothing else to configure -- serve wiki
import wikklytext.wiki.frontend.ws_cgi as ws_cgi
ws_cgi.init(WIKIPATH, USE_LOGGING)
ws_cgi.serve_wiki(WIKIPATH, SCRIPT_NAME)


Make the file executable:
chmod a+x /var/www/wikis/mywiki/wiki.py


Configure Apache


Edit your Apache configuration (i.e. httpd.conf, .htaccess, etc.) to enable the CGI script to run in the wiki directory:
<Directory "/var/www/wikis/mywiki">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    # whatever extensions you want to use ...
    AddHandler cgi-script .py
    Order allow,deny
    Allow from all
</Directory>
The procedure for using custom CGI scripts varies widely between webhosts. The above is just one example. Check with your provider for additional documentation if needed. If you have a better suggestion please post to the MailingList.


Ready to go!


You should now be able to browse to http://example.com/wikis/mywiki/serve.py and see your wiki.

If you want to use a nicer URL scheme that hides the CGI script name, take a look at Apache+CGI+mod_rewrite.