Django + PHP to run on the same domain

Posted by Daniel on Thursday, September 17th, 2009

Today I figured out how to put Django and PHP to run together on the same site using the Lighttpd web server.  I googled around to see if anyone else had accomplished this feat, but haven't found anyone that did, so I thought I'd post how I did it.

I have a website, fabrichound.com, that is a Django site but with a WordPress blog that should run from fabrichound.com/blog/.  The trick for me was to get a good lighttpd config.  I already have php-cgi running on a socket at /tmp/php.socket-0.  That's defined in a different file.  Here is my configuration:

            server.name          = "fabrichound.com"
            server.document-root = "/var/www/fabrichound.com/trunk/media"
            accesslog.filename   = "/var/www/fabrichound.com/log/access_log"
            alias.url            = (
                "/blog/"     => "/var/www/fabrichound.com/trunk/blog/",
            )
            url.rewrite-once     = (
                "^(/blog.*)$"        => "$1",
                "^(/.*)$"            => "/fabrichound.com.dispatch.fcgi$1",
            )
         
            fastcgi.server       = (
                "/fabrichound.com.dispatch.fcgi" => (
                    (
                        "check-local"           => "disable",
                        "socket"                => "/tmp/fabrichound.com.socket",
                        "broken-scriptfilename" => "enable",
                        "allow-x-send-file"     => "enable",
                    ),
                ),
               ".php"                            => (
                    (
                        "socket"                => "/tmp/php.socket-0",
                        "broken-scriptfilename" => "enable",
                        # 5
                        "allow-x-send-file"     => "enable",
                        # 6
                    ),
                ),
            )

That's it! Easy enough!  The trick is to tell Lighttpd to run all URLs that match /blog/ NOT through Django's fastcgi socket (that's what the alias and rewrite rules do).  The other part is to tell it that all files ending in .php are to go through the /tmp/php.socket-0 that is already running.


Categories: Daniel, Danemco, Django


Comments

No one has commented yet.