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.

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!

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

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.