3

I previously posted a similar question because I used to get a 403 error message (Forbidden). So I decided to get a new micro SD card, and I installed a fresh Apache server then I re-followed this tutorial from scratch again

http://raspberrywebserver.com/cgiscripting/rpi-temperature-logger/

The python files work perfectly, no errors at all. However, I am not able to see the webpage, I get a "404 Not found" error.

I have to mention that the home page (my Raspberry Pi IP address) shows Apache's message "it works". I get the "Not Found" error when I try to access http://localhost/cgi-bin/webgui.py . This makes me think that the problem is related to webgui.py file that I have in the /usr/lib/cgi-bin directory. The owner of this file is www-data.

Below is the content of the error log file:

[Sat Feb 06 06:09:57.064276 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Sat Feb 06 06:09:57.065180 2016] [core:notice] [pid 23244:tid 1996058624] AH00094: Command line: '/usr/sbin/apache2'
[Sat Feb 06 06:34:54.636785 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00493: SIGUSR1 received.  Doing graceful restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Sat Feb 06 06:34:54.686137 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Sat Feb 06 06:34:54.686303 2016] [core:notice] [pid 23244:tid 1996058624] AH00094: Command line: '/usr/sbin/apache2'
[Sat Feb 06 06:40:57.310454 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00493: SIGUSR1 received.  Doing graceful restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Sat Feb 06 06:40:57.370112 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Sat Feb 06 06:40:57.370250 2016] [core:notice] [pid 23244:tid 1996058624] AH00094: Command line: '/usr/sbin/apache2'
[Sat Feb 06 06:48:38.331262 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00493: SIGUSR1 received.  Doing graceful restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Sat Feb 06 06:48:38.374504 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Sat Feb 06 06:48:38.374642 2016] [core:notice] [pid 23244:tid 1996058624] AH00094: Command line: '/usr/sbin/apache2'
[Sat Feb 06 06:54:27.344333 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00493: SIGUSR1 received.  Doing graceful restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Sat Feb 06 06:54:27.396548 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Sat Feb 06 06:54:27.396689 2016] [core:notice] [pid 23244:tid 1996058624] AH00094: Command line: '/usr/sbin/apache2'
[Sat Feb 06 06:56:31.820692 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00493: SIGUSR1 received.  Doing graceful restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Sat Feb 06 06:56:31.884533 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Sat Feb 06 06:56:31.884664 2016] [core:notice] [pid 23244:tid 1996058624] AH00094: Command line: '/usr/sbin/apache2'
[Sat Feb 06 06:58:53.227557 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00493: SIGUSR1 received.  Doing graceful restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Sat Feb 06 06:58:53.277910 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Sat Feb 06 06:58:53.278082 2016] [core:notice] [pid 23244:tid 1996058624] AH00094: Command line: '/usr/sbin/apache2'
[Sat Feb 06 07:04:22.082634 2016] [mpm_event:notice] [pid 23244:tid 1996058624] AH00491: caught SIGTERM, shutting down
[Sat Feb 06 01:04:22.660809 2016] [mpm_event:notice] [pid 6529:tid 1996279808] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Sat Feb 06 01:04:22.661581 2016] [core:notice] [pid 6529:tid 1996279808] AH00094: Command line: '/usr/sbin/apache2'
[Sat Feb 06 01:15:24.857952 2016] [mpm_event:notice] [pid 6529:tid 1996279808] AH00493: SIGUSR1 received.  Doing graceful restart
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
[Sat Feb 06 01:15:24.912566 2016] [mpm_event:notice] [pid 6529:tid 1996279808] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Sat Feb 06 01:15:24.912741 2016] [core:notice] [pid 6529:tid 1996279808] AH00094: Command line: '/usr/sbin/apache2'

Here is the ls -al in both locations

pi@raspberrypi:/usr/lib/cgi-bin $ ls -al
total 48
drwxr-xr-x  2 www-data www-data  4096 Feb  6 00:42 .
drwxr-xr-x 83 root     root     12288 Feb  6 00:09 ..
-rwxr-xr-x  1 www-data www-data  8747 Feb  6 00:28 Adafruit_BME280.py
-rw-r--r--  1 www-data www-data  6428 Feb  6 00:32 Adafruit_BME280.pyc
-rwxr-xr-x  1 www-data www-data  1272 Feb  6 00:24 BME280.py
-rwxr-xr-x  1 www-data www-data  7368 Feb  6 00:47 webgui.py
pi@raspberrypi:/usr/lib/cgi-bin $ cd
pi@raspberrypi:~ $ cd /var/www
pi@raspberrypi:/var/www $ ls -al
total 16
drwxr-xr-x  3 www-data www-data 4096 Feb  6 00:46 .
drwxr-xr-x 12 root     root     4096 Feb  6 00:09 ..
drwxr-xr-x  2 www-data www-data 4096 Feb  6 00:09 html
-rw-r--r--  1 www-data www-data    0 Feb  6 00:46 weather.db
-rw-r--r--  1 www-data www-data 2048 Feb  6 00:46 weatherlog.db

and finally here is the content of the file named serve-cgi-bin.conf

<IfModule mod_alias.c>
    <IfModule mod_cgi.c>
        Define ENABLE_USR_LIB_CGI_BIN
    </IfModule>

    <IfModule mod_cgid.c>
        Define ENABLE_USR_LIB_CGI_BIN
    </IfModule>

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

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
2

I just figured it out, what I did is I added this line

Require all granted

between the directory tages to the etc/apache2/conf-avilable/serve-cgi-bin.conf. Then I added the following line to the /etc/apache2/apache2.conf file:

ServerName localhost

Then

a2enmod cgi
service apache2 restart

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.