vk4tec

cgi-bin how / where

Thu Mar 07, 2013 10:35 am

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 -

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: cgi-bin how / where

Thu Mar 07, 2013 10:55 am

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
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

vk4tec

Re: cgi-bin how / where

Thu Mar 07, 2013 11:19 am

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

User avatar
malakai
Posts: 1382
Joined: Sat Sep 15, 2012 10:35 am
Contact: Website

Re: cgi-bin how / where

Thu Mar 07, 2013 11:23 am

Did you reboot or stop and start Apache after the change?
http://www.raspians.com - always looking for content feel free to ask to have it posted. Or sign up and message me to become a contributor to the site. Raspians is not affiliated with the Raspberry Pi Foundation. (RPi's + You = Raspians)

vk4tec

Re: cgi-bin how / where

Thu Mar 07, 2013 1:25 pm

Yeah sure

service apache2 restart

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

Path problem - looking at my openSUSE mac MINI

- Andrew -

vk4tec

Found it

Thu Mar 07, 2013 1:36 pm

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 -

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: cgi-bin how / where

Thu Mar 07, 2013 1:39 pm

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.

vk4tec

Re: cgi-bin how / where

Thu Mar 07, 2013 2:20 pm

Fixed and working

Wrong config file I was changing

- Andrew -

geckus
Posts: 6
Joined: Thu May 30, 2013 2:46 am

Re: cgi-bin how / where

Thu May 30, 2013 2:50 am

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?

User avatar
rpdom
Posts: 17572
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: cgi-bin how / where

Thu May 30, 2013 6:28 am

geckus wrote:im still getting a Internal Server Error
Have you looked at /var/log/apache2/error.log to see what the error was?

yvonnezoe
Posts: 127
Joined: Thu Feb 14, 2013 2:10 am
Contact: Website

Re: cgi-bin how / where

Thu Feb 27, 2014 3:29 pm

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. :(
Just started my Raspberry Pi journey >> http://yvonnezoe.wordpress.com

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

Re: cgi-bin how / where

Fri Feb 28, 2014 12:32 am

#1 Look at the access.log and error.log in /var/log/apache2
#2 It's /usr/lib/cgi-bin/ in the default configuration.
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 fake doctors are on my foes list.

yvonnezoe
Posts: 127
Joined: Thu Feb 14, 2013 2:10 am
Contact: Website

Re: cgi-bin how / where

Fri Feb 28, 2014 2:58 am

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?
Just started my Raspberry Pi journey >> http://yvonnezoe.wordpress.com

User avatar
redhawk
Posts: 3465
Joined: Sun Mar 04, 2012 2:13 pm
Location: ::1

Re: cgi-bin how / where

Fri Feb 28, 2014 9:58 am

Everything is defined in the configuration file you need to edit that to change the folder locations.

Richard S.

john4u
Posts: 1
Joined: Wed Feb 10, 2016 9:08 am

Re: cgi-bin how / where

Wed Feb 10, 2016 9:10 am

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>

rdmcginnes
Posts: 9
Joined: Thu Mar 21, 2013 10:08 am

Re: cgi-bin works! A simple solution.

Wed May 04, 2016 2:06 am

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)

scchu
Posts: 1
Joined: Thu Dec 24, 2015 6:52 am

Re: cgi-bin how / where

Tue Oct 10, 2017 4:14 am

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!!

andrewclegg
Posts: 1
Joined: Sun Jan 21, 2018 12:39 am

Re: cgi-bin how / where

Sun Jan 21, 2018 12:42 am

I used the solution posted by scchu on my Raspberry Pi 3 and it worked perfectly.

Return to “General discussion”