1

I've installed lighttpd and gotten it to serve /var/www/index.html just fine, but I haven't gotten it to run a Python script yet.

I enabled CGI and set it's match case and directory as instructed in this SO answer. In short, I added mod_cgi to server.modules() and gave it a regex rule

$HTTP["url"] =~ "^/cgi-bin/" {
    cgi.assign = ( ".py" => "/usr/bin/python" )
}

For my test file /var/www/cgi-bin/test.py:

print "Content-Type: text/html"     
print ""                              
print "<body>"
print "TEST"
print "</body>"
print "</html>"

When I enter the url raspberrypi.local or my IP, I get the file /var/www/index.html as expected. When I request the url raspberrypi.local/cgi-bin/test.py or raspberrypi.local/test.py I get a 404 error.

How can I solve this problem?

EDIT: I've also found this tutorial which is very good, and says pretty much the same thing. I'm still getting the 404 error.

2 Answers 2

0

Please follow this steps:

First enable cgi by

sudo lighttpd-enable-mod cgi

This creates a new configuration file for Lighttpd:

/etc/lighttpd/conf-enabled/10-cgi.conf

Edit the configuration file nano /etc/lighttpd/conf-enabled/10-cgi.conf, to look similar to this

server.modules += ( "mod_cgi" )

$HTTP["url"] =~ "^/cgi-bin/" {
        alias.url += ( "/cgi-bin/" => "/var/www/cgi-bin" )
        cgi.assign = (
                ".py"  => "/usr/bin/python",
        )
}

Make sure python 2 is installed by executing:

/usr/bin/python --version

Now, restart

sudo /etc/init.d/lighttpd force-reload

Good luck!

1
  • This just almost got it working: the alias should refer to "/var/www/cgi-bin/", with a slash at the end.
    – xtofl
    Nov 4, 2018 at 12:54
0

If it helps 2 years later, if you enabled it via lighty-mod-enable, or perhaps this is a version specific thing ( Using lighttpd 1.4.55 ), the link that is created in /etc/lighttpd/conf-enabled/ from the sample file at /etc/lighttpd/conf-available that is 10-cgi.conf, contains

alias.url += ( "/cgi-bin/" => "/usr/lib/cgi-bin/" )

Which aliases the /cgi-bin folder to the one in /usr/lib, which it took me a good minute to figure out after reading this post.

Regardless, you can remove this line if you do want to use the cgi-bin in /var/www/html/.../cgi-bin, or put your files at /usr/lib/cgi-bin

Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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