MattewBlade
Posts: 1
Joined: Mon Dec 23, 2013 1:28 pm

problem with CGI script !!!

Mon Mar 17, 2014 4:00 pm

Hi everyone!

I'm Mattew, i'm new about this beautiful forum, pleased to enjoy it!

I've a problem with my rpi in passing elaboration to a script i wrote through an html page.

Try to explain better:

i've installed apache2 on the rpi and wrote a simple html form where to pass some parameters. Theese parameters are passed to a script(GET method) that is stored in the /cgi-bin/ folder. This should sent me an html page with a resoult but when trying to do it gives me a message like "the usr/lib/cgi-bin/script.exe was not found on the server".

Could someon help me please ? I can give more informations if needed. Thanks a lot

Mattew

Sean.fr
Posts: 10
Joined: Fri Mar 21, 2014 5:35 pm

Re: problem with CGI script !!!

Fri Mar 21, 2014 6:28 pm

I have the same problem. The problem looks to be a bug. When you call with cgi-bin in the url, the text should by magically transformed to point to the absolute location usr/lib/cgi-in. As this script is not working you are point to a relative address of the servers root directory var/www/.
Moving your script to var/www/cgi-bin does not help, as your PHP,Perl,Bash CGI is not expecting to work from there.
You can not easily mod the call, as http://usr/lib/cgi-bin is treated as pointing to var/www/usr/lib/cgi-bin.

I am looking at two work arounds. Can I tell the modules to expects scripts elsewhere? Can I follow config structure to see why the alias script is not running. Sadly Debian/Raspbian does not use the same directors and config files as Apache2 on other hosts.
I have not checked the urls as, as I am in the middle of re-installing. Even if the detail is approximative, you get the principle.

User avatar
ragnarjensen
Posts: 333
Joined: Wed May 15, 2013 6:13 pm
Location: Stockholm, Sweden
Contact: Website

Re: problem with CGI script !!!

Fri Mar 21, 2014 10:55 pm

Have you enabled cgi scripting in the Apache configuration file(s)? IIRC it is not enabled by default.
This is what I have in the conf file:

Code: Select all

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>


ScriptAlias is what translates /cgi-bin/ in an URI to the absolute path /usr/lib/cgi-bin/ on disk.
Options +ExecCGI is what actually allows cgi scripts in that directory to be executed.

--
Ragnar

Sean.fr
Posts: 10
Joined: Fri Mar 21, 2014 5:35 pm

Re: problem with CGI script !!!

Fri Mar 28, 2014 6:43 am

I gave up on Apache, as I could not get cgi to perl work. cgi to PHP worked fine, and there are films showing this on youtube.
I installed nginx instead. Again I followed the a youtube film (from TechErudio lession 11) , step by step. Worked fine. When he download files from the web with wget, it is worth checking the files have gone where you expect, and have gotten you want. I mis typed the first go, and got error messages in the file, and not the contents I expected.

User avatar
simonmcc
Posts: 181
Joined: Mon Aug 19, 2013 10:07 pm

Re: problem with CGI script !!!

Fri Mar 28, 2014 3:18 pm

MattewBlade wrote:Hi everyone!

I'm Mattew, i'm new about this beautiful forum, pleased to enjoy it!

I've a problem with my rpi in passing elaboration to a script i wrote through an html page.

Try to explain better:

i've installed apache2 on the rpi and wrote a simple html form where to pass some parameters. Theese parameters are passed to a script(GET method) that is stored in the /cgi-bin/ folder. This should sent me an html page with a resoult but when trying to do it gives me a message like "the usr/lib/cgi-bin/script.exe was not found on the server".

Could someon help me please ? I can give more informations if needed. Thanks a lot

Mattew
Hi Mattew! Welcome along.

Have a look in /var/log/apache2/ for error files, you can see access.log which will tell you what requests the server is getting, and any errors will show in error.log. There are usually good clues as to the problem in these files.

You say "script.exe" - unless you are doing some magic, no .exe files will work on the pi (you need mono (at least))

Also, like someone else said, look into using php, the pi is quite slow at loading perl and I imagine php will be a lot faster for your needs. I switched some pi software from perl to php recently and it speeded up processing from about 3 seconds to less than 1/2 seconds.
simonmcc.blogspot.com/search/label/pi

asteroidmining
Posts: 2
Joined: Sat Nov 22, 2014 3:40 pm

Re: problem with CGI script !!!

Sun Jan 04, 2015 9:41 pm

ragnarjensen wrote:Have you enabled cgi scripting in the Apache configuration file(s)? IIRC it is not enabled by default.
This is what I have in the conf file:

Code: Select all

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>


ScriptAlias is what translates /cgi-bin/ in an URI to the absolute path /usr/lib/cgi-bin/ on disk.
Options +ExecCGI is what actually allows cgi scripts in that directory to be executed.

--
Ragnar



why dont you tell us where to find this apache file?>

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: problem with CGI script !!!

Sun Jan 04, 2015 9:55 pm

Read the apache docs, guys. Or google something like "Apache enable cgi scripts"

ScriptAlias for the script
Make sure mod_cgi is installed and enabled
Make sure you have an AddHandler directive to handle your extension
Manually enable ExecCGI on the directory.

/etc/apache2/sites-available/ is where you find your site definition(s).

If you are using python, skip cgi. Use wsgi.

C
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

User avatar
iinnovations
Posts: 621
Joined: Thu Jun 06, 2013 5:17 pm

Re: problem with CGI script !!!

Sun Jan 04, 2015 9:55 pm

And make sure your scripts are all outside your web root. /var/www/cgi-bin is not acceptable.
CuPID Controls :: Open Source browser-based sensor and device control
interfaceinnovations.org/cupidcontrols.html
cupidcontrols.com

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

Re: problem with CGI script !!!

Sun Jan 04, 2015 9:58 pm

The stuff is already in the default (as installed by apt-get) Apache2 configuration to run CGI scripts from /usr/lib/cgi-bin so why change it, just put your scripts in that directory.
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.

User avatar
ragnarjensen
Posts: 333
Joined: Wed May 15, 2013 6:13 pm
Location: Stockholm, Sweden
Contact: Website

Re: problem with CGI script !!!

Mon Jan 05, 2015 5:12 pm

I wrote:Have you enabled cgi scripting in the Apache configuration file(s)? IIRC it is not enabled by default.
DougieLawson wrote:The stuff is already in the default (as installed by apt-get) Apache2 configuration to run CGI scripts from /usr/lib/cgi-bin so why change it, just put your scripts in that directory.
Dougie is right, it is enabled by default. I didn't recall correctly.
asteroidmining wrote:why dont you tell us where to find this apache file?
I left that as an exercise for the reader... ;)
--
Ragnar

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: problem with CGI script !!!

Mon Apr 27, 2015 5:52 pm

I'm having this same problem on a Pi 2 running the latest raspbian. I haven't mucked around with either Perl or the Apache2 install so I'm not sure why this isn't working right out of the box.

When I run this simple script:

Code: Select all

#!/usr/bin/perl

#
#############################################################
# We use these fine modules...
use strict;
use warnings;
use CGI;
use CGI::Carp('fatalsToBrowser');
#use HTML::Template;
#############################################################
# Create a new CGI Object for the form input
my $Q = new CGI;

print $Q->header;
print $Q->start_html;
print "Hi Bill";
print $Q->end_html;

I get this error message (perl's least helpful message):

Code: Select all

[Mon Apr 27 12:05:03 2015] [error] (8)Exec format error: exec of '/usr/lib/cgi-bin/ezInvoice4/test.cgi' failed
[Mon Apr 27 12:05:03 2015] [error] [client 192.168.0.86] Premature end of script headers: test.cgi
When run the script from the terminal I get this:

Code: Select all

pi@pi /usr/lib/cgi-bin/ezInvoice4 $ perl test.cgi
Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
Hi Bill
</body>
</html>pi@pi /usr/lib/cgi-bin/ezInvoice4 $ 
In the "etc/apache2/sites-available/default" file is this:

Code: Select all

<VirtualHost *:80>
	ServerAdmin webmaster@localhost

	DocumentRoot /var/www
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /var/www/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>

	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>

	ErrorLog ${APACHE_LOG_DIR}/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel debug

	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And these are the permissions for the cgi-bin ( changed them to 777 while debugging this.):

Code: Select all

pi@pi /usr/lib $ ls -l
total 91812
drwxr-xr-x  7 root root     4096 Mar  7 10:38 apache2
...
drwxrwxrwx  3 root root     4096 Apr 26 19:53 cgi-bin
I figured I might need to set the filename extension for cgi scripts to ".cgi" so I added this "AddHandler cgi-script .cgi" line to the "/etc/apache2/sites-available/default" file:

Code: Select all

	ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
	<Directory "/usr/lib/cgi-bin">
		AllowOverride None
		Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
		AddHandler cgi-script .cgi
		Order allow,deny
		Allow from all
	</Directory>
But that still didn't work.

I went through the docs at apache for this but still have this issue.

Whatever the problem, I'd like to solve and document the solution instead of installing nginx or lighttpd. Those are great, but I run apache on my production server and I'm using it on this Pi for developing other stuff besides perl cgi right now.

BillStephenson
Posts: 254
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
Contact: Website

Re: problem with CGI script !!!

Mon Apr 27, 2015 7:49 pm

I found it. It's an issue with my ftp software, "Fetch". It's messing up line endings or something.

This has been an exercise I didn't need.

Return to “Networking and servers”