2.2 KiB

Apache Configuration

Here's some tips on getting Rophako set up on Apache.

mod_fcgid and mod_rewrite

For I needed to set it up using mod_fcgid because my site has a lot of legacy URLs to old static files, so Rophako needs to serve the main website pages and Apache needs to serve everything else.

Apache configuration:

# Rophako
<VirtualHost *:80>
    DocumentRoot /home/kirsle/www
    CustomLog /home/kirsle/logs/access_log combined
    ErrorLog /home/kirsle/logs/error_log
    SuexecUserGroup kirsle kirsle

    <Directory "/home/kirsle/www">
        Options Indexes FollowSymLinks ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all

    <Directory "/home/kirsle/www/fcgi">
        SetHandler fcgid-script
        Options +ExecCGI
        AllowOverride all
        Order allow,deny
        Allow from all

.htaccess configuration:

This goes in ~/www/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /fcgi/index.fcgi/$1 [QSA,L]
    RewriteRule ^$ /fcgi/index.fcgi/ [QSA,L]

FastCGI script

This is my FastCGI script I wrote to launch Rophako. Important things to note:

  • The shebang line points to the Python binary in my virtualenv.
  • I modify sys.path and chdir to my git checkout folder for Rophako.
  • The ScriptNameStripper allows mod_rewrite to work best. Without it you'll sometimes get URL paths like /fcgi/index.fcgi/blog/entry/... etc. from Flask because that's what it thinks its path is.

import os
import sys

from flup.server.fcgi import WSGIServer
from rophako import app

class ScriptNameStripper(object):
    def __init__(self, app): = app

    def __call__(self, environ, start_response):
        environ["SCRIPT_NAME"] = ""
        return, start_response)

app = ScriptNameStripper(app)

if __name__ == "__main__":