WikklyText A wikitext server and rendering library


files/feed-icon-14x14.png Recently Edited Valid XHTML 1.0 Strict
Apache+CGI+mod_rewrite+cgi-bin edit
frank, 02 October 2009 (created 22 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 covers a configuration commonly available on shared webhosts where you are allowed to run CGI scripts, but you are required to place them in a predetermined cgi-bin directory. The following locations are assumed — adjust as needed:
Wiki filesystem location
/var/www/wikis/mywiki
CGI script directory
/var/www/cgi-bin
Public URL
http://example.com/my/wiki

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 cgi-bin folder:

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

# Set this to the full path where the wiki is stored
WIKIPATH = '/var/www/wikis/mywiki'

# Set this to match the public URL path:
SCRIPT_NAME = '/my/wiki'

# You can set True if desired to enable 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.cgi


Configure Apache


Edit your Apache configuration (i.e. httpd.conf, .htaccess, etc.) and add a Location section:
<Location /my/wiki>
    # redirect /my/wiki -> /cgi-bin/wiki.cgi
    RewriteEngine on
    RewriteBase /my/wiki
    # don't change if already rewritten
    RewriteCond %{REQUEST_URI} !wiki.cgi
    RewriteRule /my/wiki/(.*)$ /cgi-bin/wiki.cgi/$1
</Location>


Restart Apache.

Ready to go!


You should now be able to browse to http://example.com/my/wiki and see your wiki.