Page 1 of 1

cgi-bin how / where

Posted: Thu Mar 07, 2013 10:35 am
by vk4tec
Hello

I have apache2 running

I have PHP installed

How do I get the cgi-bin to work ?

Where should the directory live ?

What is needed to mod / install ?

- Andrew -

Re: cgi-bin how / where

Posted: Thu Mar 07, 2013 10:55 am
by malakai
Been a while since I configured Apache but this has a lot of info tons of guides should easily be available with a search http://docs.joomla.org/Should_PHP_run_a ... _module%3F

Re: cgi-bin how / where

Posted: Thu Mar 07, 2013 11:19 am
by vk4tec
I added this into apache2.conf

#
# CGI-BIN
#

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI -Includes
Order allow,deny
Allow from all
</Directory>

still looking - this did not work

Re: cgi-bin how / where

Posted: Thu Mar 07, 2013 11:23 am
by malakai
Did you reboot or stop and start Apache after the change?

Re: cgi-bin how / where

Posted: Thu Mar 07, 2013 1:25 pm
by vk4tec
Yeah sure

service apache2 restart

Its saying 404 - file not found to a test.cgi

Path problem - looking at my openSUSE mac MINI

- Andrew -

Found it

Posted: Thu Mar 07, 2013 1:36 pm
by vk4tec
The apache2 install for raspberry pi

Uses /etc/apache2/sites-available directory.

In there is a file default.

default contains the CGI directive

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

So the CGI directory is in fact /usr/lib/cgi-bin for raspberry pi

- Andrew -

Re: cgi-bin how / where

Posted: Thu Mar 07, 2013 1:39 pm
by redhawk
Do you have AddHandler cgi-script .cgi inside your configuration file??

What happens when you try to access the cgi-bin folder with your web browser i.e. http://192.168.1.101/cgi-bin/ (change IP to match your Pi).

Do you get access denied or not found??

Richard S.

Re: cgi-bin how / where

Posted: Thu Mar 07, 2013 2:20 pm
by vk4tec
Fixed and working

Wrong config file I was changing

- Andrew -

Re: cgi-bin how / where

Posted: Thu May 30, 2013 2:50 am
by geckus
so how do you do it.
im still getting a Internal Server Error
it is the /etc/apache2/sites-available/default
page that is holds the directives?
what else am i missing?

Re: cgi-bin how / where

Posted: Thu May 30, 2013 6:28 am
by rpdom
geckus wrote:im still getting a Internal Server Error
Have you looked at /var/log/apache2/error.log to see what the error was?

Re: cgi-bin how / where

Posted: Thu Feb 27, 2014 3:29 pm
by yvonnezoe
vk4tec wrote:Fixed and working

Wrong config file I was changing

- Andrew -
How exactly did you do it? I can't find my cgi-bin in var/www/ as well. :(

Re: cgi-bin how / where

Posted: Fri Feb 28, 2014 12:32 am
by DougieLawson
#1 Look at the access.log and error.log in /var/log/apache2
#2 It's /usr/lib/cgi-bin/ in the default configuration.

Re: cgi-bin how / where

Posted: Fri Feb 28, 2014 2:58 am
by yvonnezoe
DougieLawson wrote:#1 Look at the access.log and error.log in /var/log/apache2
#2 It's /usr/lib/cgi-bin/ in the default configuration.
Thanks for your reply. I found my cgi-bin under /usr/lib/ but according to this tutorial, http://www.tutorialspoint.com/python/py ... amming.htm, " the Linux server is configured to run only the scripts in the cgi-bin directory in /var/www". How can I move the cgi-bin to var/www or run my python script from /usr/lib/cgi-bin?

Re: cgi-bin how / where

Posted: Fri Feb 28, 2014 9:58 am
by redhawk
Everything is defined in the configuration file you need to edit that to change the folder locations.

Richard S.

Re: cgi-bin how / where

Posted: Wed Feb 10, 2016 9:10 am
by john4u
Hi ,

is this correct


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

Re: cgi-bin works! A simple solution.

Posted: Wed May 04, 2016 2:06 am
by rdmcginnes
I got cgi to work on the latest version of Raspian jessie.
I had apache2 setup and working from /var/www.
Then all I did is execute the following two statements:
------------------------------------------------------------------
cd /etc/apache2/mods-enabled
sudo ln -sT ../mods-available/cgi.load cgi.load
--------------------------------------------------------------------
and then I rebooted.

Notice the permissions for cgi-bin and env.pl
(a test program which prints environment variables)
pi@RPi3-0001:/usr/lib/cgi-bin $ ls -al
total 20
drwxr-xr-x 2 root root 4096 May 3 19:44 .
drwxr-xr-x 83 root root 12288 May 2 18:16 ..
-rwxr-xr-x 1 root root 218 May 3 19:44 env.pl
pi@RPi3-0001:/usr/lib/cgi-bin $

pi@RPi3-0001:/usr/lib/cgi-bin $ cat env.pl
#!/usr/bin/perl

print "Content-type: text/html\n\n";
print "<font size=+1>Environment</font>\n";
print "executing /usr/lib/cgi-bin/env.pl<p>";
foreach (sort keys %ENV)
{
print "<b>$_</b>: $ENV{$_}<br>\n";
}
exit;

-------------------------------------------------------------------
FYI, if you are interested in accessing your
web site by name instead of by IP address (even if it keeps changing) see my free, no ad, web site at eazyip.com. Now back to testing cgi.
----------------------------------------------------------------------

I entered the following into my firefox browser:
http://192.168.2.111/cgi-bin/env.pl

and got the following results:

Environment executing /usr/lib/cgi-bin/env.pl

CONTEXT_DOCUMENT_ROOT: /usr/lib/cgi-bin/
CONTEXT_PREFIX: /cgi-bin/
DOCUMENT_ROOT: /var/www/html
GATEWAY_INTERFACE: CGI/1.1
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.5
HTTP_CONNECTION: keep-alive
HTTP_HOST: 192.168.2.111
HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
QUERY_STRING:
REMOTE_ADDR: 192.168.2.106
REMOTE_PORT: 49697
REQUEST_METHOD: GET
REQUEST_SCHEME: http
REQUEST_URI: /cgi-bin/env.pl
SCRIPT_FILENAME: /usr/lib/cgi-bin/env.pl
SCRIPT_NAME: /cgi-bin/env.pl
SERVER_ADDR: 192.168.2.111
SERVER_ADMIN: webmaster@localhost
SERVER_NAME: 192.168.2.111
SERVER_PORT: 80
SERVER_PROTOCOL: HTTP/1.1
SERVER_SIGNATURE:
Apache/2.4.10 (Raspbian) Server at 192.168.2.111 Port 80

SERVER_SOFTWARE: Apache/2.4.10 (Raspbian)

Re: cgi-bin how / where

Posted: Tue Oct 10, 2017 4:14 am
by scchu
My Raspberry Pi 3 is using 2017-08-16-raspbian-stretch.img.
Install the Apache2 by:
sudo apt-get install apache2

Setup for use CGI by:
sudo a2enmod cgi

restart Apache2:
sudo systemctl restart apache2

create cgi file:
sudo nano /usr/lib/cgi-bin/hello.cgi

Enter lines in to hello.cgi and save:
#!/bin/bash
echo -e "Content-type: text/html\n\n"
echo "<h1>Hello World</h1>"

Change hello.cgi to be executable:
sudo chmod +x /usr/lib/cgi-bin/hello.cgi

At remote browser:
http://apache_server_IP/cgi-bin/hello.cgi

All above work for me. Good luck!!

Re: cgi-bin how / where

Posted: Sun Jan 21, 2018 12:42 am
by andrewclegg
I used the solution posted by scchu on my Raspberry Pi 3 and it worked perfectly.