LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 07-11-2009, 10:13 PM   #1
jabberwok
LQ Newbie
 
Registered: Apr 2009
Posts: 18

Rep: Reputation: 0
Unhappy setting up cgi scripts on apache2


I have configured two virtual hosts on my apache2 server but neither can execute cgi scripts

I can navigate to the script (cgi-bin lies outside web root) using mysite.com/cgi-bin/test.pl but it just displays the code

here is my httpd.conf section for one of the two sites, they are both the same.

<VirtualHost *>
# Basic setup
ServerName mysite.com

DocumentRoot /usr/local/apache2/htdocs-sa/

# HTML documents, with indexing.
<Directory />
Options +Includes
</Directory>

# CGI Handling
ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/
<Location "/usr/local/apache2/cgi-bin/">
Options ExecCGI
AddHandler cgi-script cgi pl
</Location>

# Logfiles
ErrorLog /usr/local/apache2/logs/error.log
CustomLog /usr/local/apache2/logs/access.log combined
ServerAlias www.mysite.com
</VirtualHost>

In httpd.conf I have commented out everything else to do with cgi except

<IfModule cgid_module>
#
# ScriptSock: On threaded servers, designate the path to the UNIX
# socket used to communicate with the CGI daemon of mod_cgid.
#
#Scriptsock logs/cgisock
</IfModule>

I have tried chmod 755 cgi-bin and chmod a+x test.pl but no luck

I really need help with this one, thanks for any help
 
Old 07-11-2009, 11:16 PM   #2
jabberwok
LQ Newbie
 
Registered: Apr 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Hi thanks for looking at this for me

I have now got it to the point where if I change the test file extension to .pl the browser tries to save the file localy.

this tells me apache does not know how to serve it.

it will execute on the command line though

any ideas
 
Old 07-13-2009, 05:14 AM   #3
routers
Member
 
Registered: Aug 2005
Location: Malaysia - KULMY / CNXTH
Distribution: Slackware, Fedora, FreeBSD, Sun O/S 5.10, CentOS
Posts: 771
Blog Entries: 6

Rep: Reputation: 75
use this sample

Code:
<VirtualHost  *:80>
        ServerName rou.tprsb.com
        ServerAdmin  noc@tprsb.com
        DocumentRoot /home/routers/www
        TransferLog /home/routers/logs/access-log
        ScriptAlias /cgi-bin/ /home/routers/www/cgi-bin/
</VirtualHost>
and check your syntax with

apachectl configtest


and make sure you have perl installed
 
Old 07-13-2009, 11:31 AM   #4
jabberwok
LQ Newbie
 
Registered: Apr 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
[error] VirtualHost *:80 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results
Syntax OK
this is what I get from apachectl configtest after including the above code in httpd.conf

If I run apachectl configtest w/out the above code I get
Quote:
Syntax OK
 
Old 07-13-2009, 12:02 PM   #5
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,910

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
Quote:
# CGI Handling
ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/
<Location "/usr/local/apache2/cgi-bin/">
Options ExecCGI
AddHandler cgi-script cgi pl
</Location>
You don't need a <Location ...> directive here. Replace it with <Directory ...>
 
Old 07-13-2009, 12:19 PM   #6
jabberwok
LQ Newbie
 
Registered: Apr 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Code:
<VirtualHost example.com>
        # Basic setup
	ServerAdmin admin@example.com
	ServerName example.com
        DocumentRoot /usr/local/apache2/htdocs/
	ServerAlias www.example.com

	# HTML documents, with indexing.
        <Directory />
        Options +Includes
        </Directory>

        # CGI Handling
       ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/
          <Directory "/usr/local/apache2/cgi-bin/" >
          Options +ExecCGI +SymLinksIfOwnerMatch
          AddHandler cgi-script .cgi .pl
          </Directory> 

        # Logfiles
        ErrorLog  /usr/local/apache2/logs/error_dog.log
        CustomLog /usr/local/apache2/logs/access_dog.log combined
        TransferLog /usr/local/apache2/logs/access-log-dog

</VirtualHost>
This is what my httpd.conf currently looks like, there is a second virtualhost identical to the first except for example.com becomes example2.com

cgi still does not work

also I am getting this error

Quote:
[warn] NameVirtualHost *:0 has no VirtualHosts
my 000-default file is empty

Last edited by jabberwok; 07-13-2009 at 12:22 PM. Reason: adding more information
 
Old 07-13-2009, 12:33 PM   #7
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,910

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
Quote:
also I am getting this error

Quote:
[warn] NameVirtualHost *:0 has no VirtualHosts
my 000-default file is empty
In general to setup vhosts you need a
Code:
NameVirtualHost *:80
and later on in the vhosts definition you should use the same syntax:
Code:
<VirtualHost  *:80>
not
Quote:
<VirtualHost example.com>

Last edited by bathory; 07-13-2009 at 12:46 PM.
 
Old 07-13-2009, 12:47 PM   #8
jabberwok
LQ Newbie
 
Registered: Apr 2009
Posts: 18

Original Poster
Rep: Reputation: 0
I got rid of the NameVirtuaHosts error by removing the NameVirtualHosts * from my httpd.conf. thanksfor the help.

I am still not able to execute cgis

I have discovered that on startup apache is complaining that the /etc/rc.d/init.d/functions dir does not exist. I have looked and in fact /etc/rc.d does not exist

do you think this has a bearing on the problem?

I do have /etc/rc0.d through /etc/rc6.d and /etc/rcS.d

I am using a debian etch server
 
Old 07-13-2009, 12:57 PM   #9
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,910

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
Quote:
I have discovered that on startup apache is complaining that the /etc/rc.d/init.d/functions dir does not exist. I have looked and in fact /etc/rc.d does not exist
No, it only affects the apache startup. How did you installed apache and you missed the init scripts?
Regarding the cgi scripts, do you get any error, or it still prompts you to save the script?
 
Old 07-13-2009, 01:10 PM   #10
jabberwok
LQ Newbie
 
Registered: Apr 2009
Posts: 18

Original Poster
Rep: Reputation: 0
yes .cgi files output their code onscreen
and .pl files are opening a box to download

I have a custom install of apache2 in /usr/local

I tried to install an apache-perl package hoping that might help my problem but it installed apache-2.2 with it into the default location

I had to replace the apache2 init script with the backup to get my original server booting again
 
Old 07-13-2009, 01:27 PM   #11
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,910

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
It should work by now!
Could you post the contents of test.pl?
 
Old 07-13-2009, 01:39 PM   #12
jabberwok
LQ Newbie
 
Registered: Apr 2009
Posts: 18

Original Poster
Rep: Reputation: 0
Code:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><body><div>Hello world!</div></body></html>";
I can execute it on the comand line, is it possible I need an apache perl extenxion module
 
Old 07-13-2009, 02:12 PM   #13
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,910

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
It works on my apache.
Remove the ScriptAlias line and use the following in the <Directory ...>section:
Code:
AllowOverride Options
Options +ExecCGI +SymLinksIfOwnerMatch
SetHandler cgi-script
Why you need "+SymLinksIfOwnerMatch"? Is this test.pl a symlink to a different location?
 
Old 07-13-2009, 02:41 PM   #14
jabberwok
LQ Newbie
 
Registered: Apr 2009
Posts: 18

Original Poster
Rep: Reputation: 0
I made the above changes and restarted apache
but no joy.

it seems if it works for you, there must be something wrong with my apache setup.

I just wish I new what

Last edited by jabberwok; 07-13-2009 at 02:45 PM.
 
Old 07-13-2009, 04:38 PM   #15
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,910

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
Looking back at your posts, I think that you've mixed the apache that came with debian, with the one you've compiled from source in /usr/local/apache2.
Stop apache and then run
Code:
/usr/local/apache2/apachectl start
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cgi is not running through Apache2 ----- help xudonw1 Linux - Server 2 04-07-2007 05:42 AM
Apache2 on Debian won't execute perl cgi scripts, have tried chmod, Options ExecCGI dewert Linux - Software 1 07-03-2006 12:44 PM
cgi on apache2? sharadshankar Linux - Software 5 02-19-2006 04:40 PM
CGI With Apache2 karthik85nitt Linux - Newbie 2 07-15-2005 04:11 AM
help setting up Apache to use cgi scripts limiter Linux - Software 2 03-25-2004 01:59 PM


All times are GMT -5. The time now is 07:28 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration