TheLukaBoss
Posts: 12
Joined: Fri Feb 21, 2020 11:16 am

Apache2 & CGI Setup

Fri Feb 21, 2020 11:27 am

Hello,
This is my first post. So if you would like any more info, please just ask.

I have setup Apache2 & CGI on my RPi 1 B+ (Jessie). This took a while in itself.
I have routed 'IP/cgi-bin/' to 'usr/lib/cgi-bin/', and this seems to work fine.

However when I visit my webpage 'IP/cgi-bin/test.cgi', which contains the following code:

Code: Select all

#!/usr/lib/python3.4
import os
import cgi
cgi.test()
cgi.print_environ()
the 500 error appears. In the error.log file:

Code: Select all

[Fri Feb 21 09:37:28.380583 2020] [mpm_event:notice] [pid 2182:tid 3069706768] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 09:37:28.383697 2020] [core:notice] [pid 2182:tid 3069706768] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:08:02.182560 2020] [mpm_event:notice] [pid 2182:tid 3069706768] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 10:08:04.081508 2020] [mpm_event:notice] [pid 4386:tid 3069612560] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 10:08:04.082572 2020] [core:notice] [pid 4386:tid 3069612560] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:08:32.990267 2020] [authz_core:error] [pid 4389:tid 3019895856] [client 192.168.1.10:51161] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:09:34.603844 2020] [authz_core:error] [pid 4390:tid 3045061680] [client 192.168.1.10:51170] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:09:35.757106 2020] [authz_core:error] [pid 4390:tid 3036673072] [client 192.168.1.10:51170] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:10:02.920711 2020] [authz_core:error] [pid 4389:tid 3011507248] [client 192.168.1.10:51174] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:10:03.929164 2020] [authz_core:error] [pid 4389:tid 3053450288] [client 192.168.1.10:51174] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:10:04.088015 2020] [authz_core:error] [pid 4389:tid 3003118640] [client 192.168.1.10:51174] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:11:22.264664 2020] [mpm_event:notice] [pid 4386:tid 3069612560] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 10:11:24.237280 2020] [mpm_event:notice] [pid 4794:tid 3069751824] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 10:11:24.238373 2020] [core:notice] [pid 4794:tid 3069751824] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:11:28.694277 2020] [authz_core:error] [pid 4798:tid 3011507248] [client 192.168.1.10:51186] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:11:29.911101 2020] [authz_core:error] [pid 4798:tid 3019895856] [client 192.168.1.10:51186] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:17:55.482193 2020] [mpm_event:notice] [pid 4794:tid 3069751824] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 10:17:57.466701 2020] [mpm_event:notice] [pid 5352:tid 3069170192] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 10:17:57.473787 2020] [core:notice] [pid 5352:tid 3069170192] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:18:01.577341 2020] [authz_core:error] [pid 5357:tid 3035624496] [client 192.168.1.10:51218] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:19:35.887709 2020] [mpm_event:notice] [pid 5352:tid 3069170192] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 10:19:38.455313 2020] [mpm_event:notice] [pid 5646:tid 3069342224] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 10:19:38.462656 2020] [core:notice] [pid 5646:tid 3069342224] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:19:41.776689 2020] [authz_core:error] [pid 5651:tid 3052401712] [client 192.168.1.10:51235] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:19:42.903448 2020] [authz_core:error] [pid 5651:tid 3044013104] [client 192.168.1.10:51235] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:20:34.161306 2020] [mpm_event:notice] [pid 5646:tid 3069342224] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 10:20:35.949006 2020] [mpm_event:notice] [pid 5857:tid 3069575696] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 10:20:35.953978 2020] [core:notice] [pid 5857:tid 3069575696] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:21:39.639390 2020] [mpm_event:notice] [pid 5857:tid 3069575696] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 10:21:41.601314 2020] [mpm_event:notice] [pid 6025:tid 3070042640] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 10:21:41.609012 2020] [core:notice] [pid 6025:tid 3070042640] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:21:49.188417 2020] [authz_core:error] [pid 6030:tid 3053450288] [client 192.168.1.10:51251] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:23:30.251261 2020] [authz_core:error] [pid 6029:tid 3036673072] [client 192.168.1.10:51268] AH01630: client denied by server configuration: /etc/apache2/usr
[Fri Feb 21 10:27:39.501633 2020] [mpm_event:notice] [pid 6025:tid 3070042640] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 10:27:41.481409 2020] [mpm_event:notice] [pid 6654:tid 3070169616] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 10:27:41.488885 2020] [core:notice] [pid 6654:tid 3070169616] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:27:44.674677 2020] [cgid:error] [pid 6658:tid 3036673072] [client 192.168.1.10:51279] AH01264: script not found or unable to stat: /etc/apache2/usr
[Fri Feb 21 10:27:46.803310 2020] [cgid:error] [pid 6658:tid 3028284464] [client 192.168.1.10:51279] AH01264: script not found or unable to stat: /etc/apache2/usr
[Fri Feb 21 10:28:55.572308 2020] [cgid:error] [pid 6658:tid 3045061680] [client 192.168.1.10:51288] AH01264: script not found or unable to stat: /etc/apache2/usr
[Fri Feb 21 10:30:18.382045 2020] [cgid:error] [pid 6658:tid 2986341424] [client 192.168.1.10:51299] AH01264: script not found or unable to stat: /etc/apache2/usr
[Fri Feb 21 10:30:24.649016 2020] [cgid:error] [pid 6659:tid 3036673072] [client 192.168.1.10:51303] AH01264: script not found or unable to stat: /etc/apache2/usr
[Fri Feb 21 10:30:26.958988 2020] [cgid:error] [pid 6659:tid 3028284464] [client 192.168.1.10:51303] AH01264: script not found or unable to stat: /etc/apache2/usr
[Fri Feb 21 10:35:04.669875 2020] [mpm_event:notice] [pid 6654:tid 3070169616] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 10:35:06.601128 2020] [mpm_event:notice] [pid 7192:tid 3069653520] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 10:35:06.602608 2020] [core:notice] [pid 7192:tid 3069653520] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:35:09.997199 2020] [cgid:error] [pid 7258:tid 3069653520] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:35:10.001684 2020] [cgid:error] [pid 7196:tid 3035624496] [client 192.168.1.10:51396] End of script output before headers: test.cgi
[Fri Feb 21 10:38:52.703158 2020] [cgid:error] [pid 7503:tid 3069653520] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:38:52.707859 2020] [cgid:error] [pid 7198:tid 3044013104] [client 192.168.1.10:51419] End of script output before headers: test.cgi
[Fri Feb 21 10:50:29.458117 2020] [cgid:error] [pid 8272:tid 3069653520] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:50:29.462544 2020] [cgid:error] [pid 7198:tid 3035624496] [client 192.168.1.10:51508] End of script output before headers: test.cgi
[Fri Feb 21 10:50:32.690253 2020] [cgid:error] [pid 8274:tid 3069653520] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.py' failed
[Fri Feb 21 10:50:32.700761 2020] [cgid:error] [pid 7198:tid 3027235888] [client 192.168.1.10:51509] End of script output before headers: test.py
[Fri Feb 21 10:54:34.098505 2020] [mpm_event:notice] [pid 7192:tid 3069653520] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 10:54:36.050077 2020] [mpm_event:notice] [pid 8556:tid 3069219344] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 10:54:36.053785 2020] [core:notice] [pid 8556:tid 3069219344] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:54:39.250599 2020] [cgid:error] [pid 8663:tid 3069219344] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.py' failed
[Fri Feb 21 10:54:39.255243 2020] [cgid:error] [pid 8560:tid 3052401712] [client 192.168.1.10:51587] End of script output before headers: test.py
[Fri Feb 21 10:54:43.333385 2020] [cgid:error] [pid 8665:tid 3069219344] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:54:43.337790 2020] [cgid:error] [pid 8561:tid 3018847280] [client 192.168.1.10:51588] End of script output before headers: test.cgi
[Fri Feb 21 10:54:54.695985 2020] [cgid:error] [pid 8668:tid 3069219344] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:54:54.700193 2020] [cgid:error] [pid 8560:tid 3027235888] [client 192.168.1.10:51593] End of script output before headers: test.cgi
[Fri Feb 21 10:55:08.858162 2020] [mpm_event:notice] [pid 8556:tid 3069219344] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 10:55:10.811131 2020] [mpm_event:notice] [pid 8721:tid 3069776400] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 10:55:10.812610 2020] [core:notice] [pid 8721:tid 3069776400] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:55:13.484937 2020] [cgid:error] [pid 8787:tid 3069776400] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:55:13.489387 2020] [cgid:error] [pid 8725:tid 3036673072] [client 192.168.1.10:51602] End of script output before headers: test.cgi
[Fri Feb 21 10:55:14.456680 2020] [cgid:error] [pid 8788:tid 3069776400] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:55:14.461178 2020] [cgid:error] [pid 8727:tid 3053450288] [client 192.168.1.10:51601] End of script output before headers: test.cgi
[Fri Feb 21 10:55:14.692635 2020] [cgid:error] [pid 8790:tid 3069776400] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:55:14.696993 2020] [cgid:error] [pid 8725:tid 3045061680] [client 192.168.1.10:51603] End of script output before headers: test.cgi
[Fri Feb 21 10:55:15.765793 2020] [cgid:error] [pid 8792:tid 3069776400] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:55:15.775028 2020] [cgid:error] [pid 8727:tid 3045061680] [client 192.168.1.10:51604] End of script output before headers: test.cgi
[Fri Feb 21 10:55:23.943419 2020] [cgid:error] [pid 8795:tid 3069776400] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:55:23.947818 2020] [cgid:error] [pid 8725:tid 3028284464] [client 192.168.1.10:51605] End of script output before headers: test.cgi
[Fri Feb 21 10:56:54.017925 2020] [mpm_event:notice] [pid 8721:tid 3069776400] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 10:56:55.980589 2020] [mpm_event:notice] [pid 8937:tid 3069948432] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 10:56:55.988038 2020] [core:notice] [pid 8937:tid 3069948432] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 10:59:54.195696 2020] [cgid:error] [pid 9228:tid 3069948432] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:59:54.200006 2020] [cgid:error] [pid 8942:tid 3053450288] [client 192.168.1.10:51705] End of script output before headers: test.cgi
[Fri Feb 21 10:59:54.892635 2020] [cgid:error] [pid 9229:tid 3069948432] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 10:59:54.897026 2020] [cgid:error] [pid 8941:tid 3036673072] [client 192.168.1.10:51706] End of script output before headers: test.cgi
[Fri Feb 21 11:01:04.421909 2020] [cgid:error] [pid 9285:tid 3069948432] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 11:01:04.426286 2020] [cgid:error] [pid 8942:tid 3036673072] [client 192.168.1.10:51726] End of script output before headers: test.cgi
[Fri Feb 21 11:02:11.911488 2020] [cgid:error] [pid 9387:tid 3069948432] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 11:02:11.915828 2020] [cgid:error] [pid 8942:tid 3028284464] [client 192.168.1.10:51750] End of script output before headers: test.cgi
[Fri Feb 21 11:06:08.654170 2020] [mpm_event:notice] [pid 8937:tid 3069948432] AH00491: caught SIGTERM, shutting down
[Fri Feb 21 11:06:10.631669 2020] [mpm_event:notice] [pid 9631:tid 3070202384] AH00489: Apache/2.4.10 (Raspbian) configured -- resuming normal operations
[Fri Feb 21 11:06:10.633148 2020] [core:notice] [pid 9631:tid 3070202384] AH00094: Command line: '/usr/sbin/apache2'
[Fri Feb 21 11:06:13.610543 2020] [cgid:error] [pid 9697:tid 3070202384] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 11:06:13.615053 2020] [cgid:error] [pid 9635:tid 3036673072] [client 192.168.1.10:51837] End of script output before headers: test.cgi
[Fri Feb 21 11:06:14.486623 2020] [cgid:error] [pid 9698:tid 3070202384] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 11:06:14.490822 2020] [cgid:error] [pid 9637:tid 3053450288] [client 192.168.1.10:51836] End of script output before headers: test.cgi
[Fri Feb 21 11:06:17.110330 2020] [cgid:error] [pid 9637:tid 3045061680] [client 192.168.1.10:51839] AH01265: attempt to invoke directory as script: /usr/lib/cgi-bin/
[Fri Feb 21 11:06:27.391725 2020] [cgid:error] [pid 9703:tid 3070202384] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.py' failed
[Fri Feb 21 11:06:27.396180 2020] [cgid:error] [pid 9635:tid 3028284464] [client 192.168.1.10:51844] End of script output before headers: test.py
[Fri Feb 21 11:09:09.813617 2020] [core:error] [pid 9637:tid 3036673072] (13)Permission denied: [client 192.168.1.10:51902] AH00035: access to /cgi-bin/test.py denied (filesystem path '/usr/lib/cgi-bin/test.py') because search permissions are missing on a component of the path
[Fri Feb 21 11:09:13.528296 2020] [core:error] [pid 9637:tid 3028284464] (13)Permission denied: [client 192.168.1.10:51902] AH00035: access to /cgi-bin/test.cgi denied (filesystem path '/usr/lib/cgi-bin/test.cgi') because search permissions are missing on a component of the path
[Fri Feb 21 11:09:36.262925 2020] [cgid:error] [pid 9943:tid 3070202384] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 11:09:36.267540 2020] [cgid:error] [pid 9637:tid 3011507248] [client 192.168.1.10:51912] End of script output before headers: test.cgi
[Fri Feb 21 11:09:37.064402 2020] [cgid:error] [pid 9944:tid 3070202384] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 11:09:37.068711 2020] [cgid:error] [pid 9635:tid 3053450288] [client 192.168.1.10:51913] End of script output before headers: test.cgi
[Fri Feb 21 11:09:48.623289 2020] [cgid:error] [pid 9635:tid 3011507248] [client 192.168.1.10:51917] AH01265: attempt to invoke directory as script: /usr/lib/cgi-bin/
[Fri Feb 21 11:10:14.335627 2020] [cgid:error] [pid 9635:tid 2994730032] [client 192.168.1.10:51927] AH01265: attempt to invoke directory as script: /usr/lib/cgi-bin/
[Fri Feb 21 11:10:19.607870 2020] [cgid:error] [pid 10000:tid 3070202384] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 11:10:19.612210 2020] [cgid:error] [pid 9637:tid 2994730032] [client 192.168.1.10:51926] End of script output before headers: test.cgi
[Fri Feb 21 11:10:54.903240 2020] [cgid:error] [pid 10012:tid 3070202384] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 11:10:54.907689 2020] [cgid:error] [pid 9637:tid 2977952816] [client 192.168.1.10:51943] End of script output before headers: test.cgi
[Fri Feb 21 11:11:36.926277 2020] [cgid:error] [pid 10063:tid 3070202384] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 11:11:36.931575 2020] [cgid:error] [pid 9637:tid 2961175600] [client 192.168.1.10:51956] End of script output before headers: test.cgi
[Fri Feb 21 11:12:01.191499 2020] [cgid:error] [pid 10115:tid 3070202384] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 11:12:01.196034 2020] [cgid:error] [pid 9635:tid 2977952816] [client 192.168.1.10:51964] End of script output before headers: test.cgi
[Fri Feb 21 11:15:14.978992 2020] [cgid:error] [pid 10296:tid 3070202384] (13)Permission denied: AH01241: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Fri Feb 21 11:15:14.983357 2020] [cgid:error] [pid 9635:tid 2969564208] [client 192.168.1.10:52028] End of script output before headers: test.cgi
.

In main config:

Code: Select all

# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream's suggested way to configure the web server. This is because Debian's
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.

# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
#	/etc/apache2/
#	|-- apache2.conf
#	|	`--  ports.conf
#	|-- mods-enabled
#	|	|-- *.load
#	|	`-- *.conf
#	|-- conf-enabled
#	|	`-- *.conf
# 	`-- sites-enabled
#	 	`-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
#   together by including all remaining configuration files when starting up the
#   web server.
#
# * ports.conf is always included from the main configuration file. It is
#   supposed to determine listening ports for incoming connections which can be
#   customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
#   directories contain particular configuration snippets which manage modules,
#   global configuration fragments, or virtual host configurations,
#   respectively.
#
#   They are activated by symlinking available configuration files from their
#   respective *-available/ counterparts. These should be managed by using our
#   helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
#   their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
#   the default configuration, apache2 needs to be started/stopped with
#   /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
#   work with the default configuration.


# Global configuration
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the Mutex documentation (available
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
Mutex file:${APACHE_LOCK_DIR} default

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5


# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel warn

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf


# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
	Options FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

<Directory /usr/share>
	AllowOverride None
	Require all granted
</Directory>

<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

#<Directory /srv/>
#	Options Indexes FollowSymLinks
#	AllowOverride None
#	Require all granted
#</Directory>




# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
	Require all denied
</FilesMatch>


#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
In 000-default.conf:

Code: Select all

<VirtualHost *:80>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "usr/lib/cgi_bin">
	AddHandler cgi-script .py
	AddHandler cgi-script .cgi
	AddHandler cgi-script .sh
	AllowOverride None
	Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
	Require all granted
</Directory>
<Directory "/etc/apache2/usr">
	Require all granted
</Directory>
	# The ServerName directive sets the request scheme, hostname and port that
	# the server uses to identify itself. This is used when creating
	# redirection URLs. In the context of virtual hosts, the ServerName
	# specifies what hostname must appear in the request's Host: header to
	# match this virtual host. For the default virtual host (this file) this
	# value is not decisive as it is used as a last resort host regardless.
	# However, you must set it for any further virtual host explicitly.
	#ServerName www.example.com

	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html

	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
	# error, crit, alert, emerg.
	# It is also possible to configure the loglevel for particular
	# modules, e.g.
	#LogLevel info ssl:warn

	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined

	# For most configuration files from conf-available/, which are
	# enabled or disabled at a global level, it is possible to
	# include a line for only one particular virtual host. For example the
	# following line enables the CGI configuration for this host only
	# after it has been globally disabled with "a2disconf".
	#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I understand the issue is to do with permissions (I think), however I do not know what chmod setup to use where.

Any help would be greatly appreciated.
Thanks!
:idea: Anyone with a light bulb moment should help me. I am not lucky enough to get them.

Also thanks to everyone for everything! Have a good day!

knute
Posts: 550
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Apache2 & CGI Setup

Fri Feb 21, 2020 9:04 pm

So enabling CGI is very simple with current apache. You don't need to edit ANY files. Just run the command:

sudo a2enmod cgid

Next put your CGI files in the /usr/lib/cgi-bin directory. They need to be executable by www-data.

That's it!

I would guess that your 500 error is caused by some permission problem. Try setting the owner of your CGI program file to www-data:www-data and the permissions to 750.

TheLukaBoss
Posts: 12
Joined: Fri Feb 21, 2020 11:16 am

Re: Apache2 & CGI Setup

Fri Feb 21, 2020 9:18 pm

knute wrote:
Fri Feb 21, 2020 9:04 pm
So enabling CGI is very simple with current apache. You don't need to edit ANY files. Just run the command:

sudo a2enmod cgid

Next put your CGI files in the /usr/lib/cgi-bin directory. They need to be executable by www-data.

That's it!

I would guess that your 500 error is caused by some permission problem. Try setting the owner of your CGI program file to www-data:www-data and the permissions to 750.
Ok thanks!
Step number 1 I already tried, it was already running.
The other steps seem to make no difference.
Thanks!
:idea: Anyone with a light bulb moment should help me. I am not lucky enough to get them.

Also thanks to everyone for everything! Have a good day!

User avatar
DougieLawson
Posts: 38882
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: Apache2 & CGI Setup

Fri Feb 21, 2020 9:18 pm

Code: Select all

#!/usr/lib/python3.4
import os
import cgi
cgi.test()
cgi.print_environ()
Your shebang line is incorrect. It should be

Code: Select all

#!/usr/bin/python3
or

Code: Select all

#!/usr/bin/env python3
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

TheLukaBoss
Posts: 12
Joined: Fri Feb 21, 2020 11:16 am

Re: Apache2 & CGI Setup

Fri Feb 21, 2020 9:31 pm

DougieLawson wrote:
Fri Feb 21, 2020 9:18 pm

Code: Select all

#!/usr/lib/python3.4
import os
import cgi
cgi.test()
cgi.print_environ()
Your shebang line is incorrect. It should be

Code: Select all

#!/usr/bin/python3
or

Code: Select all

#!/usr/bin/env python3
Ah thanks, hoped you'd reply!
Of course the first shebang path worked a treat!
Kudos to you.
Thanks once more.
:idea: Anyone with a light bulb moment should help me. I am not lucky enough to get them.

Also thanks to everyone for everything! Have a good day!

Return to “Raspberry Pi OS”