Python – Lighttpd, Python, MySQLdb Python Module and Permissions

fastcgilighttpdpython

After restarting a lighttpd server recently I haven't been able to get it up and running again. I am running a python built API service on it, and am relying on the web.py module to run the application.

I am having difficulty getting the MySQLdb Python module to import. That specific import causes everything to error out and produce a 500 error when I try and hit the API.

Initially, I thought that it was just a matter of permissions since I was able to import the module when running python from the command line. When I saw that running MySQLdb from the command line worked, I went on and changed the permissions of the Python code and the Python egg for the module to 755. This hasn't fixed the problem, however. I am not exactly certain what will be most helpful to post here, so I will include some configuration settings and other general facts about the server.

To clarify, I am able to get a Hello, World! message to print with my lighttpd setup, and have also confirmed that the lighttpd server is using the correct Python version (i.e 1.7.3).

Location of MySQLDb Python Module code:

/home/pythoninstall/MySQL-python-1.2.3c1

Location of Python 3rd Party Modules/eggs:

/opt/python2.7/lib/python2.7/site-packages

Lighttpd FastCGI Setup for Python:

server.modules = ("mod_fastcgi","mod_accesslog","mod_rewrite", "mod_access",       "mod_redirect", "mod_proxy")
server.document-root = "/home/OverLord/"
fastcgi.server = ( "/code.py" =>
    ((      "bin-environment" => (
                    "REAL_SCRIPT_NAME" => ""
            ),
            "socket" => "/tmp/fastcgi.socket",
            "bin-path" => "/opt/python2.7/bin/python /home/OverLord/code.py",
            "check-local" => "disable",
            "max-procs" => 1
    ))
)

Any ideas would be great. I have spent too much time losing my mind over this. Thanks!

Best Answer

FCGI is changing the name of your socket, somehow. You declare it as:

"socket" => "/tmp/fastcgi.socket"

But it is erroring on:

request sent: 1154 on socket: unix:/tmp/fastcgi.socket-0

Bashing google a bit suggests the php people have a lot of trouble with this. If FCGI keeps appending a -0 to your socket name and then barfing, it might be time to dig in to wsgi.

EDIT: adding a config from somebody who seems to have solved the issue. Use this for your socket definition:

"socket" => "/tmp/php.socket" + var.PID,