1

First, I should mention I'm pretty new to working with the pi, the os, lighttpd, fastcgi, etc. I've been following this: http://davstott.me.uk/index.php/2013/03/17/raspberry-pi-controlling-gpio-from-the-web/

I've been able to get it working, though my version is just getting some random numbers from python as opposed to turning on the gpio pins (just playing with the web to python part for now).

I do have two questions:

I notice all of my python goes to just running the same python script (doStuff.py), regardless of the actual called python script on the webserver: I upload /var/www/hello.py and go to it in the browser, but it runs doStuff.py instead.

This is probably due to the config from following the site (the bin-path line):

 fastcgi.server = (
   ".py" => (
     "python-fcgi" => (
       "socket" => "/tmp/fastcgi.python.socket",
       "bin-path" => "/var/www/doStuff.py",
       "check-local" => "disable",
       "max-procs" => 1)
    )
 )

How would I change this so that it does actually run any desired python scripts as opposed to being 'locked/stuck' to doStuff.py ? The idea just popped in to my head that maybe I can just leave off the doStuff.py on the "bin-path" part (though can't try this yet). Or another idea was to have doStuff.py take in inputs which are used to call other python scripts, though this doesn't seem like it would be the 'correct way'...

My second question is simpler: Every time I make a change/update files on the server (be it .html or .py files), I keep getting my old files when I go to them in the browser until I restart lighttpd. This doesn't seem normal that I need to restart after every single file change... any ideas?

If it helps, my end goal is to create a web ui to control various things and play sounds at various times (possibly via pygame as was suggested somewhere).

3
  • Have you solved your problem? If so, please mark the answer that helped you, or if you solved it on your own, create a self-answer and mark it as such. We are trying to get the site Q:A ratio up and marking answers is what does that. If you resolved it and mark then people in the future will be able to profit from what you did and it helps move the site closer to graduation. Thanks! Mar 23, 2014 at 16:48
  • No, I haven't. Though, you can probably guess that I stopped attempting to solve it quite a while ago. I just used the workaround mentioned in my question.
    – mitim
    Mar 23, 2014 at 22:12
  • Cool. Sorry we couldn't resolve your issue. Hope we are able to help later on. Mar 23, 2014 at 22:14

3 Answers 3

3

I think the 'bin-path' variable has been abused; from the docs of lighttpd :

"bin-path": path to the local FastCGI binary. 

So it should be that, not the .py script. This configuration hard-binds any .py script to doStuff.py, as you have noticed. However, I'm not sure there is a fastcgi python interface, in contrast to PHP. You may have to list your scripts one by one, like so:

 fastcgi.server = ( "/first.py" =>
 (( "socket" => "/tmp/fastcgi.code.socket",
    "bin-path" => "/path-to/webpy-app/code.py",
    "max-procs" => 1,
    "check-local" => "disable"
 )),
 "/second.py" =>
 (( "socket" => "/tmp/fastcgi.second.socket",
    "bin-path" => "/path-to/webpy-app/second.py",
    "max-procs" => 1,
    "check-local" => "disable"
 ))
 )

What may not be obvious is the socket connection must be a unique name as you are running a host process there. When bound to a static file each one must have it's own fastcgi instance, and hence it's own socket.

2

Your bin path should only be "/var/www/" or whatever directory you like and you have rights to read/write.

To not only run the same script again, you could make an "index.html" which contains different forms/buttons and calls different scripts when you click them. For example:

<form action = "firstScript.py" methode = "GET" >
  <input type = "submit" value = "Run script" />
</form>

"firstScript.py" has to be in the bin path and will be executed. As described here

Regarding with the update/upload problem. I don´t think it´s lighttpd, but rather your browser which caches the old sites. Try Reloading the page (usually F5) and/or emptying your browser cache (CTRL + F5).

1
  • if I change it to just "/var/www/"(also tried with no trailing slash), lighttpd appears to die. The error log says: "the fastcgi-backend /var/www/ failed to start:" followed by "child exited with status 13 /var/www/" and finally "[ERROR]: spawning fcgi failed. Configuration of plugins failed. Going down." I have seen that link before (from another question asked here) and tried that as well, but it results in just getting my python script source in the browser, not actually being executed.
    – mitim
    Sep 25, 2013 at 4:35
1

On the second line of your lighttpd fastcgi configuration: ".py => (" change to: "doStuff.py => ("

I had the same problem then remembered this post afterwards. Making the above changed solved the issue for me.

Reason: I believe the ".py" directive tells lighttpd to map all python executables to your "doStuff.py". By being more specific i.e. replacing with "doStuff.py" resolves the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.