4

I followed this tutorial Building an SQLite temperature logger.

The python files work perfectly, no errors at all. However, I am not able to see the webpage, I get a 403 - forbidden error. I've been banging my head for the last couple of days. I'm hoping that anyone here would be able to help me.

I have to mention that the home page (my Raspberry Pi IP address) shows Apache's message "it works". I get the forbidden 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:

[Mon Feb 01 03:06:30.660229 2016] [mpm_event:notice] [pid 772:tid 1996390400] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 03:06:30.660430 2016] [core:notice] [pid 772:tid 1996390400] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 06:47:00.394013 2016] [mpm_event:notice] [pid 772:tid 1996390400] AH00491: caught SIGTERM, shutting down
[Mon Feb 01 06:47:02.080192 2016] [mpm_event:notice] [pid 29073:tid 1995436032] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 06:47:02.082154 2016] [core:notice] [pid 29073:tid 1995436032] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 07:18:36.216912 2016] [mpm_event:notice] [pid 29073:tid 1995436032] AH00491: caught SIGTERM, shutting down
[Mon Feb 01 07:18:36.793515 2016] [mpm_event:notice] [pid 6510:tid 1995792384] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 07:18:36.794238 2016] [core:notice] [pid 6510:tid 1995792384] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 07:23:05.045667 2016] [mpm_event:notice] [pid 6510:tid 1995792384] AH00491: caught SIGTERM, shutting down
[Mon Feb 01 07:23:06.668796 2016] [mpm_event:notice] [pid 8110:tid 1996374016] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 07:23:06.669492 2016] [core:notice] [pid 8110:tid 1996374016] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 07:36:51.258775 2016] [mpm_event:notice] [pid 8110:tid 1996374016] AH00491: caught SIGTERM, shutting down
[Mon Feb 01 07:36:51.850075 2016] [mpm_event:notice] [pid 12615:tid 1995730944] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 07:36:51.856968 2016] [core:notice] [pid 12615:tid 1995730944] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 07:43:39.883875 2016] [mpm_event:notice] [pid 12615:tid 1995730944] AH00491: caught SIGTERM, shutting down
[Mon Feb 01 07:43:40.492875 2016] [mpm_event:notice] [pid 15024:tid 1996095488] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 07:43:40.493716 2016] [core:notice] [pid 15024:tid 1996095488] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 07:56:09.254549 2016] [mpm_event:notice] [pid 15024:tid 1996095488] AH00491: caught SIGTERM, shutting down
[Mon Feb 01 01:56:15.623373 2016] [mpm_event:notice] [pid 757:tid 1996087296] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 01:56:15.626492 2016] [core:notice] [pid 757:tid 1996087296] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 02:04:15.666206 2016] [mpm_event:notice] [pid 757:tid 1996087296] AH00491: caught SIGTERM, shutting down
[Mon Feb 01 02:04:17.256207 2016] [mpm_event:notice] [pid 3681:tid 1995800576] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 02:04:17.256965 2016] [core:notice] [pid 3681:tid 1995800576] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 08:17:07.574037 2016] [mpm_event:notice] [pid 3681:tid 1995800576] AH00491: caught SIGTERM, shutting down
[Mon Feb 01 08:17:08.189818 2016] [mpm_event:notice] [pid 6885:tid 1996288000] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 08:17:08.190660 2016] [core:notice] [pid 6885:tid 1996288000] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 08:17:14.896981 2016] [authz_core:error] [pid 6889:tid 1979708464] [client 10.0.0.27:57454] AH01630: client denied by server configuration: /usr/lib/cgi-bin/webgui.py
[Mon Feb 01 08:17:17.516899 2016] [authz_core:error] [pid 6889:tid 1962931248] [client 10.0.0.27:57454] AH01630: client denied by server configuration: /usr/lib/cgi-bin/webgui.py
[Mon Feb 01 08:33:03.086356 2016] [mpm_event:notice] [pid 6885:tid 1996288000] AH00491: caught SIGTERM, shutting down
[Mon Feb 01 08:33:04.695080 2016] [mpm_event:notice] [pid 11555:tid 1995759616] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 08:33:04.695917 2016] [core:notice] [pid 11555:tid 1995759616] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 08:33:07.918094 2016] [authz_core:error] [pid 11559:tid 1978659888] [client 10.0.0.27:57455] AH01630: client denied by server configuration: /usr/lib/cgi-bin/webgui.py
[Mon Feb 01 09:39:54.641757 2016] [authz_core:error] [pid 11560:tid 1953494064] [client 10.0.0.27:57491] AH01630: client denied by server configuration: /usr/lib/cgi-bin/webgui.py
[Mon Feb 01 10:15:06.731390 2016] [authz_core:error] [pid 11559:tid 1970271280] [client 10.0.0.27:57492] AH01630: client denied by server configuration: /usr/lib/cgi-bin/webgui.py
[Mon Feb 01 10:26:37.696904 2016] [authz_core:error] [pid 11559:tid 1936716848] [client 10.0.0.27:57496] AH01630: client denied by server configuration: /usr/lib/cgi-bin/webgui.py
[Mon Feb 01 10:36:40.800221 2016] [mpm_event:notice] [pid 11555:tid 1995759616] AH00491: caught SIGTERM, shutting down
[Mon Feb 01 10:36:42.343070 2016] [mpm_event:notice] [pid 12744:tid 1995513856] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 10:36:42.343890 2016] [core:notice] [pid 12744:tid 1995513856] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 10:36:56.245325 2016] [authz_core:error] [pid 12749:tid 1978659888] [client 10.0.0.27:57630] AH01630: client denied by server configuration: /usr/lib/cgi-bin/webgui.py
[Mon Feb 01 10:36:59.308422 2016] [authz_core:error] [pid 12749:tid 1970271280] [client 10.0.0.27:57630] AH01630: client denied by server configuration: /usr/lib/cgi-bin/webgui.py
[Mon Feb 01 10:37:00.691738 2016] [authz_core:error] [pid 12749:tid 1961882672] [client 10.0.0.27:57630] AH01630: client denied by server configuration: /usr/lib/cgi-bin/webgui.py
[Mon Feb 01 11:04:09.501725 2016] [mpm_event:notice] [pid 12744:tid 1995513856] AH00491: caught SIGTERM, shutting down
[Mon Feb 01 11:04:10.076208 2016] [mpm_event:notice] [pid 20354:tid 1995669504] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Mon Feb 01 11:04:10.077068 2016] [core:notice] [pid 20354:tid 1995669504] AH00094: Command line: '/usr/sbin/apache2'
[Mon Feb 01 11:04:20.889227 2016] [authz_core:error] [pid 20359:tid 1978659888] [client 10.0.0.27:57641] AH01630: client denied by server configuration: /usr/lib/cgi-bin/webgui.py
[Mon Feb 01 11:04:29.145181 2016] [authz_core:error] [pid 20358:tid 1978659888] [client 10.0.0.27:57642] AH01630: client denied by server configuration: /usr/lib/cgi-bin/webgui.py

and here is ls -l run from the www/var directory

pi@raspberrypi:/var/www $ ls -l
total 32
-rw-r--r-- 1 www-data root     20352 Feb  2 00:07 dead.letter
drwxr-sr-x 2 root     root      4096 Jan 23 19:20 html
-rwxr-xr-x 1 www-data www-data  2048 Jan 23 01:17 templog.db
-rwxr-xr-x 1 www-data www-data  2048 Feb  1 23:36 weather.db

and finally this is where I keep the webgui.py

pi@raspberrypi:/usr/lib/cgi-bin $ ls -l
total 148
-rw-r--r-- 1 root     root     115130 Feb  2 00:07 2016-02-02-000732_1552x868_scrot.png
-rw-r--r-- 1 root     root       8747 Jan 31 01:08 Adafruit_BME280.py
-rw-r--r-- 1 root     root       6428 Jan 31 01:10 Adafruit_BME280.pyc
-rwxr-xr-x 1 www-data www-data   1269 Jan 31 18:07 BME280.py
-rwxr-xr-x 1 www-data www-data   7365 Jan 31 16:49 webgui.py

Here is what I get when I run the webgui.py

<html>
<head>
    <title>
Raspberry Pi Temperature Logger
    </title>

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
      google.load("visualization", "1", {packages:["corechart"]});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Time', 'Temperature'],
['2016-02-01 08:01:50', 77.889],
['2016-02-01 08:02:43', 77.887],
['2016-02-01 14:18:13', 77.311],
['2016-02-01 16:00:45', 77.07],
['2016-02-01 20:05:32', 79.3],
['2016-02-01 20:07:54', 79.325],
['2016-02-01 20:08:27', 79.338],
['2016-02-01 20:15:07', 79.432],
['2016-02-01 20:15:22', 79.45],
['2016-02-01 20:16:45', 79.517],
['2016-02-01 20:18:44', 79.457],
['2016-02-01 20:21:20', 79.608],
['2016-02-02 01:46:34', 79.858],
['2016-02-02 05:36:03', 79.404],
['2016-02-02 06:40:24', 79.488]

        ]);

        var options = {
          title: 'Temperature'
        };

        var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>
</head>
<body>
<h1>Raspberry Pi Temperature Logger</h1>
<hr>
<form action="/cgi-bin/webgui.py" method="POST">
        Show the temperature logs for  
        <select name="timeinterval">
<option value="6">the last 6 hours</option>
<option value="12">the last 12 hours</option>
<option value="24" selected="selected">the last 24 hours</option>
        </select>
        <input type="submit" value="Display">
    </form>
<h2>Temperature Chart</h2>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
<hr>
<h2>Minumum temperature&nbsp</h2>
2016-02-01 16:00:45&nbsp&nbsp&nbsp77.07C
<h2>Maximum temperature</h2>
2016-02-02 01:46:34&nbsp&nbsp&nbsp79.858C
<h2>Average temperature</h2>
78.956C
<hr>
<h2>In the last hour:</h2>
<table>
<tr><td><strong>Date/Time</strong></td><td><strong>Temperature</strong></td></tr>
</table>
<hr>
</body>
</html>

Update: I followed Pandalion98 solution and still no luck here is the outcome

pi@raspberrypi:/var/www $ ls -al
total 336
drwxrwsrwx  3 www-data www-data   4096 Feb  2 00:40 .
drwxr-xr-x 12 root     root       4096 Jan 23 01:15 ..
-rw-r--r--  1 www-data www-data 117435 Feb  2 00:08 2016-02-02-000815_1552x868_scrot.png
-rw-r--r--  1 www-data www-data 197160 Feb  2 07:04 dead.letter
drwxr-sr-x  2 www-data www-data   4096 Jan 23 19:20 html
-rwxr-xr-x  1 www-data www-data   2048 Jan 23 01:17 templog.db
-rwxr-xr-x  1 www-data www-data   2048 Feb  2 00:40 weather.db

pi@raspberrypi:/usr/lib/cgi-bin $ ls -al
total 164
drwxr-xr-x  2 www-data www-data   4096 Feb  2 00:07 .
drwxr-xr-x 86 root     root      12288 Jan 31 17:09 ..
-rw-r--r--  1 www-data www-data 115130 Feb  2 00:07 2016-02-02-000732_1552x868_scrot.png
-rw-r--r--  1 www-data www-data   8747 Jan 31 01:08 Adafruit_BME280.py
-rw-r--r--  1 www-data www-data   6428 Jan 31 01:10 Adafruit_BME280.pyc
-rwxr-xr-x  1 www-data www-data   1269 Jan 31 18:07 BME280.py
-rwxr-xr-x  1 www-data www-data   7365 Jan 31 16:49 webgui.py

Here is the contents of the cgi conf. file at this location etc/apache2/conf-enabled/server-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">
            AllowOverride All
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
                        Allow from all
                        AddHandler cgi-script .py
        </Directory>
    </IfDefine>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
9
  • 1
    If we look at similar questions such as ... stackoverflow.com/questions/18447454/… what we seem to see is that there is a request to look in the /var/log/apache2/error.log log file for further explanation for the error. I wonder if you can take a look in there and see if there are any clues?
    – Kolban
    Feb 2, 2016 at 5:58
  • 1
    please add the following to your question ls -la for the directory where your script is located, and the webgui configuration. Feb 2, 2016 at 6:02
  • 1
    Please add the output of webgui.py Feb 2, 2016 at 6:38
  • 1
    Is it possible that the webgui.py needs to be run as root in order to access some low level GPIO data? However, when the same script is run by apache it no longer has the internal permissions it needs? When you say "I run webgui.py" are you running it sudo?
    – Kolban
    Feb 2, 2016 at 13:17
  • 1
    You didn't skip this part did you? raspberrywebserver.com/cgiscripting/…
    – goldilocks
    Feb 2, 2016 at 13:52

3 Answers 3

3

Your public files are owned by root. Apache can't access it. Change the ownership so that it's owned by www-data.

To restore ownership of the files in your public directories, run these:

chown -R www-data /var/www
chgrp -R www-data /var/www

chown -R www-data /usr/lib/cgi-bin
chgrp -R www-data /usr/lib/cgi-bin

These will change the owner and group of the files in those directories to www-data.

The files will once again get owned by root if you edit it as root (usually by using sudo [editor] [file]). If that's the case, simply re-run the commands above.

If this is accessible online or if you decide to publish it publicly, you may want to set the permissions to 755 so random people can't hack modify your public files. If you're using it privately, it's probably okay to leave it as-is.

1
  • I just followed your solution but the problem still exists. I updated the post to show the outcome of the ls -al in both locations; www/var and usr/lib/cgi-bin
    – Julia_arch
    Feb 2, 2016 at 13:10
3

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
1

I have figured out this:

edit /etc/apache2/sites-avalaible/00-default.conf and add at top of file:

<Directory "/usr/lib/cgi-bin">
    AllowOverride All
    Options None
    Require all granted
</Directory>

<Directory "/mnt/hddweb/www/sites">         # <- specify your own html/sites dir here
  Options Indexes FollowSymLinks
  AllowOverride All
  Order allow,deny
  Allow from all
  Require all granted
</Directory>

This is working for me, all other answers don't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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