1
votes

I know that there are tons of discussions in several forums, but unfortunately none of the answers and suggestions worked for me. I want to execute a very Simple Python script and view the output in the browser. I followed the instructions according to http://raspberrywebserver.com/cgiscripting/writing-cgi-scripts-in-python.html.

My "hello.py" Python file is located in /usr/lib/cgi-bin. When running it as python hello.py from the Terminal everything works fine. My Apache2 Webserver also seems to run perfectly as it shows:

"It works! This is the default web page for this server. The web server software is running but no content has been added, yet."

when typing the IP of the Raspberry Pi (xxx.xxx.x.xx) in the browser.

When I add the path to my Python file like 192.168.0.12/cgi-bin/hello.py it says 404 - Not Found.

My Apache config file looks like this:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            AddHandler cgi-script .cgi .py
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

Any ideas so far?

1
Not sure about this but have you tried the AddHandler line with only the .py extension, i.e. without .cgi, exactly as per the RasPi example you linked to? Also have you done the chmod +x? Don't know maybe you need a #!/bin/python (or whatever the path is to your python) as first line of the script, but it doesn't look Apache is getting that far. You might not have to include cgi-bin in the url.balmy
Thank you for your reply. I removed the AddHandler extension .cgi from the Apache config file but that didn´t change anything. I also did the chmod +x for the Python file. My Python installation is located in /usr/bin/python so I assume the #!usr/bin/python is right.Axel.Foley
Is your updated config file definitely being loaded by Apache?balmy
I´m not sure what you mean, but when I run the command sudo service apache2 reload after manipulating the Apache config file I get: [ok] Reloading web server config: apache2 not running.Axel.Foley

1 Answers

0
votes

Finally solved it. I haven't noticed that I ran Lighttpd on port 80 and Apache also listens to that port. By setting the Apache to listen to port 8080 it works perfectly. Despite all that I want to thank everyone who contributed to solve my problem.