On my Raspberry Pi Zero-W I like to control my GPIO in and outputs with a webserver. I chose lighttpd as server since I can use cgi scrips with c++.

But my setup has issues. I configured lighttpd without problem. Normal HTML pages are running without problem. I used the command "lighty-enable-mod cgi" as mentioned on the default welcome page to enable cgi scripts.

I made a small C++ test program:

#include <iostream>
using namespace std;
int main()
    cout<<"Content-type: text/plain"<<endl<<endl;
    cout<<"Hello World!"<<endl;
    return 0;

I compile it with G++ rename the binary output to hello.cgi and place this file in the directory /usr/www/cgi-bin/.

I restart lighttpd and on my pc I type the IP address of my Pi in the web browser and get the default welcome page. the I extend my the web browsers address with /hello.cgi and get error 404 Not Found.

Then I saw a web page telling me to change lighttpd.conf. So did I:

server.modules = (

server.document-root        = "/var/www/html"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80

index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

$HTTP["url"] =~ "/cgi-bin/" {
    cgi.assign = ( "" => "" )

cgi.assign     = (
    ".cgi" => ""

I still get error 404 Not found.

What am I doing wrong? Should I use an other URL? Should I use an other lighttpd.conf ? Should I put my cgi executable file in an other location than /usr/www/cgi-bin/ ?

  • Have you tried accessing <your local host address>/cgi-bin/hello.cgi in your browser? Does that work instead?
    – Aurora0001
    Nov 1, 2017 at 15:44
  • Yes I did just do that, but only 404 result
    – R. Warning
    Nov 1, 2017 at 18:42

2 Answers 2


You need indicate where actually the "cgi-bin" path is, by adding the line below:

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

Don't forget make .cgi file executable.

Then access your cgi by host/cgi-bin/xxx.cgi.


If you were accessing the cgi as http://host/cgi-bin/hello.cgi, then according to your config, the cgi-bin would be expected under your document-root (that is '/var/www/html/cgi-bin/'). The rule will match the /cgi-bin/ in the URL, but won't be able to find the sub-dir.

Thus, you either need to move your cgi-bin under the document-root, or create an alias as @Owl City suggested.

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.