LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-22-2014, 03:11 AM   #1
mia_tech
Member
 
Registered: Dec 2007
Location: FL, USA
Distribution: CentOS 5.3, Ubuntu 9.04
Posts: 245

Rep: Reputation: 16
problem executing cgi bash script in apache


I have the following file
Code:
#!/bin/bash

echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<head><title>hello</title></head>"
echo "<body>"
echo "hello world"
echo "</body>"
echo "</html>"
I have tried to execute from the browser, but all it does it downloading the file. I placed the file in the /usr/lib/cgi-bin directory. I tried executing the file with cgi, and sh extensions with the same result. And I have execute permissions to the file. I'm assuming it might be bad configuration of apache.
any help appreciated
 
Old 04-22-2014, 04:41 AM   #2
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
If you are using apache2, are these the content there in your file /etc/apache2/sites-available/default
Code:
	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>
Restart apache2 after putting it there.

If you are using CentOS, have you checked following code in /etc/httpd/conf/httpd.conf
Code:
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
#"/var/www/cgi-bin" should be changed to whatever your ScriptAliased CGI directory exists,if you have that configured.
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
Restart httpd after enabling this code.

Have you executing it in following way?
http://localhost/cgi-bin/filename
or
http://server-IP/cgi-bin/filename

Your code is working fine on my apache.

Last edited by eklavya; 04-22-2014 at 04:52 AM.
 
1 members found this post helpful.
Old 04-22-2014, 04:20 PM   #3
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
I have tried to execute from the browser, but all it does it downloading the file. I placed the file in the /usr/lib/cgi-bin directory. I tried executing the file with cgi, and sh extensions with the same result.
From the location of the cgi-bin directory I guess you're running apache on debian or debian based distro.
If that's the case, in addition of what eklavya said above, you need to enable also the cgi module:
Code:
sudo a2enmod cgi
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cgi script downloads - instead of executing sathiyamoorthy Linux - Server 1 04-23-2008 08:24 AM
Problem Executing cgi Script from Plans Calendar jjp001 Linux - Server 3 10-24-2007 07:51 AM
CGI File Not Executing on Apache Server kaplan71 Linux - Software 2 10-21-2004 07:12 AM
Apache cgi-script problem palanisaravanan Linux - General 6 02-07-2004 09:41 AM
apache displays .cgi file instead of executing it hewsonism Linux - Software 2 01-13-2004 09:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration