Solved

Cannot get cgi-bin working

Posted on 2010-08-18
17
783 Views
Last Modified: 2012-05-10
Hi,
I have gone through the apache2 docs and can't figure out what I am missing here.  Hopefully someone can help.  When I go to load the cgi script it prints out the source code instead of executing it.

the apache page I checked was here:

http://httpd.apache.org/docs/2.0/howto/cgi.html

I'm installing big brother on an existing apache server as a virtualhost.  OS is sles10sp2.  Apache is 2.0.63.    The cgi-bin directory does not seem to work for my virtual host. Below is my existing configuration.  I am sure some of it is redundant in the <Directory> directive since I already configured with the "ScriptAlias" line but I was basically at throw-spaghetti-on-the-wall mode at this point


<VirtualHost server:80>
    DocumentRoot /home/bb/bb1.9i-btf/www
    ServerName bb.server
    ScriptAlias /cgi-bin/ "/home/bb/bb1.9i-btf/www/cgi-bin/"
    ErrorLog  logs/bb_error_log
    CustomLog logs/bb_access_log combined

        <Directory "/home/bb/bb1.9i-btf/www/cgi-bin">
        Options ExecCGI
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
        </Directory>

</VirtualHost>

My cgi script is in the above bb cgi-bin dir

server:/home/bb/bbhome/www/cgi-bin# cat test.pl
#!/usr/bin/perl

print "Content-type:text/html\n\n";

print "HEllo World"
server:/home/bb/bbhome/www/cgi-bin#

I've already run it successfully from the command line and I also ran it on another server that has cgi working sucessfully (no virtual hosts though)

On this server when I load up

http://bb.server/cgi-bin/test.pl

it loads up the source/content of the test.pl instead of executing.

Anyway, what should I look for? What am I missing?

Thanks!
0
Comment
Question by:uayneb
  • 9
  • 8
17 Comments
 
LVL 9

Expert Comment

by:jeremycrussell
Comment Utility
You need to add a handler for the suffix(es) so your webserver knows its a cgi script.

AddHandler cgi-script .cgi .pl

If you had used ScriptAlias directive, this wouldn't be required.
0
 
LVL 9

Expert Comment

by:jeremycrussell
Comment Utility
Sorry, just noticed that you *are* using the ScriptAlias, so, that should be working.  Although if using ScriptAlias you shouldn't need the <Directory> Option ExecCGI stuff.

One may be overriding the other which, in this case the addhandler should fix it.

0
 
LVL 5

Author Comment

by:uayneb
Comment Utility
You're correct ...  I had tried both (throwing spaghetti) that's why they are both in there .  My original virtual host config is below (which I've just changed it back to - still not working)

I did have the addhandler in there also because big brother uses bash scripts (.sh).  So I did have

AddHandler .pl .cgi .sh

it doesn't do any good right now since it seems my cgi directory is still not being recognized as a script directory



<VirtualHost server:80>
    DocumentRoot /home/bb/bb1.9i-btf/www
    ServerName bb.server
    ScriptAlias /cgi-bin/ "/home/bb/bb1.9i-btf/www/cgi-bin/"
    ErrorLog  logs/bb_error_log
    CustomLog logs/bb_access_log combined

<Directory "/home/bb/bb1.9i-btf/www/cgi-bin/">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

Any other thoughts?  Thanks for the post
0
 
LVL 9

Expert Comment

by:jeremycrussell
Comment Utility
Your AddHandler directive,  is it as you show here or like below, including "cgi-script"?

AddHandler cgi-script .cgi .pl

In you're config example, I wouldn't have the scriptalias, I would just leave that out, and then just apply the ExecCGI option to the Document Root.

The way you have this setup, in using virtual hosts, you don't seem to be configuring your DocumentRoot for the VH.
0
 
LVL 5

Author Comment

by:uayneb
Comment Utility
Here's my current
<VirtualHost server:80>
    DocumentRoot /home/bb/bb1.9i-btf/www
    ServerName bb.server
    ErrorLog  logs/bb_error_log
    CustomLog logs/bb_access_log combined
<Directory "/home/bb/bb1.9i-btf/www/">
    AddHandler cgi-script .cgi .pl
    AllowOverride None
    Options +ExecCGI
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

Still not working though, outputting to the screen

Now that the ScriptAlias is out, I'm getting some other weird behavior.  this doesn't need to be fixed but it may lend some ideas to what's wrong with my setup?

With BB, there is a link in the dirctory /home/bb/bb1.9i-btf/www  that is

ln -s . bb

server:/home/bb/bb1.9i-btf/www# ls -l bb
lrwxrwxrwx 1 bb root 1 Aug 12 16:30 bb -> .
server:/home/bb/bb1.9i-btf/www#

This is because in big brother it is hardcoded sometimes that it tries to get to

http://bb.server/bb

instead of

http://bb.server/

So anyway what that means is

http://bb.server/cgi-bin/test.pl
and
http://bb.server/bb/cgi-bin/test.pl
are the same file

Taking ScriptAlias out,

Accessing:  http://bb.server/cgi-bin/test.pl  
now results in   "NOT FOUND The requested URL /cgi-bin/test.pl was not found on this server"

Accessing:http://bb.server/bb/cgi-bin/test.pl
results in the familiar (and incorrect) source output of the the test.pl script instead of apache server executing the script.

even though it's the same file with the bb symbolic link.

Does that give any help to what could be misconfigure in my setup?

0
 
LVL 9

Expert Comment

by:jeremycrussell
Comment Utility
Right, I should have added..  now you should be able to just stick test.pl in your DocumentRoot or any sub directory under root. ( create a dir named cgi-bin, with proper permissions, under root, if needed.)

For the Symlink, just added the followsymlinks option so the webserver will follow it.

Since removing the ScriptAlias, webserver no longer knows about your current cgi-bin directory.
0
 
LVL 5

Author Comment

by:uayneb
Comment Utility
Right, but the cgi-bin directory physically is in document root so shouldn't it see it?

If document root is
/home/bb/bb1.9i-btf/www
Then if I have
/home/bb/bb1.9i-btf/www/cgi-bin/test.pl

Shouldn't
http://bb.server/cgi-bin/test.pl

still work?

0
 
LVL 5

Author Comment

by:uayneb
Comment Utility
Okay I put test.pl in document root
It still is not executing at all.

Loading

http://bb.server/test.pl

Outputs the source code of the test.pl instead of executing.

Thanks for the help so far!  Do you have other thoughts?



0
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
LVL 9

Expert Comment

by:jeremycrussell
Comment Utility
One first question, yes it should see it just fine.

On second...

Very odd.

Does the webserver have permissions to these, to read and execute...

If webserver user is not owner, or member of owning group make sure world has rx to cgi-bin and test.pl.
0
 
LVL 5

Author Comment

by:uayneb
Comment Utility
Scripts are all world executable.  and directories are all world readable and executable

*confounded*
0
 
LVL 9

Expert Comment

by:jeremycrussell
Comment Utility
Goodness...

Ok.. so, everything looks fine.  one thing perhaps is to move the AddHandler out of the VH into the main server config.

Does there happen to be anything in the error_log or access_log, do you get a 200 for accessing the test.pl file?

Still thinking...
0
 
LVL 5

Author Comment

by:uayneb
Comment Utility
Nope nothign in the error log.   I think it just sees all the dirctories as serving content and not as a script/cgi directory.  Perhaps there is a module of some sort not compiled in?  I dont' know how Apache was compiled and installed on this server, but as an example I just found that the "DirectoryIndex" does not work, so whatever module is reponsible for that was not compiled in.  Is there something that is required for CGI to work?
0
 
LVL 5

Author Comment

by:uayneb
Comment Utility
Specifically
error log (debug mode)

[Thu Aug 19 16:40:11 2010] [debug] mod_deflate.c(468): [client 172.16.96.1] Zlib: Compressed 20826 to 2339 : URL /index.html
[Thu Aug 19 16:43:11 2010] [debug] mod_deflate.c(468): [client 172.16.96.1] Zlib: Compressed 20826 to 2338 : URL /index.html
[Thu Aug 19 16:46:14 2010] [debug] mod_deflate.c(468): [client 172.16.96.1] Zlib: Compressed 17487 to 4843 : URL /bb/help/bb-files.html, referer: http://bb.server/bb/help/bb-help.html
[Thu Aug 19 16:53:29 2010] [debug] mod_deflate.c(468): [client 172.16.96.1] Zlib: Compressed 75 to 70 : URL /test.pl

access log

172.16.96.1 - - [19/Aug/2010:16:46:14 -0400] "GET /bb/help/bb-files.html HTTP/1.1" 200 4861 "http://bb.server/bb/help/bb-help.html" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; CMDTDF)"
172.16.96.1 - - [19/Aug/2010:16:46:35 -0400] "GET /bb/help/purple.html HTTP/1.1" 304 - "http://bb.server/bb/help/bb-help.html" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; CMDTDF)"
172.16.96.1 - - [19/Aug/2010:16:53:29 -0400] "GET /test.pl HTTP/1.1" 200 88 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.9) Gecko/20100315 Firefox/3.5.9"
0
 
LVL 9

Accepted Solution

by:
jeremycrussell earned 500 total points
Comment Utility
Yes, you would need mod_cgi.  That's quite possible the issue.

DirectoryIndex would also require a module.

If you don't have AddModule, LoadModule directives in your config, there are a couple things you can check.

httpd -l , so see if they are compiled into the httpd binary, or, perhaps in a libexec, mod, or lib directory in the ServerRoot there modules are present, just that the directives are not.  If those are not there, then you'll have to install the modules.

I would think though that apache should be blowin' up when you try to start it with those directives.  Does a config check (i.e. apachectl -S)  give anything?
0
 
LVL 9

Expert Comment

by:jeremycrussell
Comment Utility
If you do have the modules, the next thing you might try is disabling mod deflate(noticed in your logs)..  I doubt its an issue, but its one more thing to rule out..
0
 
LVL 5

Author Comment

by:uayneb
Comment Utility
There is no loadmodule or addmodule.  Below is the httpd -l .
Looks like you're correct.  On the server I have working httpd -l does not have a mod_cgi but it does do a LoadModule mod_cgi.so



server:/usr/local/apache2# ./bin/httpd -l
Compiled in modules:
  core.c
  mod_perl.c
  mod_access.c
  mod_deflate.c
  mod_log_config.c
  mod_env.c
  mod_expires.c
  mod_headers.c
  mod_setenvif.c
  prefork.c
  http_core.c
  mod_mime.c
  mod_negotiation.c
  mod_alias.c
  mod_so.c
server:/usr/local/apache2#

That is the issue then.  Not sure I can load it because I don't want to interfere with the existing app but at least now I know where to look and let them know why it's not working.

Thanks!
0
 
LVL 5

Author Closing Comment

by:uayneb
Comment Utility
Thanks!!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now