Solved

Problem to running  CGI script

Posted on 2004-10-22
169 Views
Last Modified: 2013-11-18
Hi
I am using fedora core1 and i also install apache web server on my machine. I place my website in /var/www/HTML and place my CGI script in /var/www/cgi-bin and everything working properly. But now i want to run my CGI script from other directory whatever i like. I change my HTML document and place my CGI script in other directory. I also change  /usr/local/apache/conf/httpd.conf
as
Addhandler cgi-script .cgi
options Indexes FollowSymLinks Multiviews ExecCGI
and my CGI script is with .cgi extension.
NOw my problem is my CGI is executing but giving some garbage value. Can u tell me whats wrong.Please reply me ASAP.
0
Question by:lazii
    10 Comments
     
    LVL 4

    Expert Comment

    by:TomDavidson
    Is your script giving an error? what's in the error log?

    Try a very simple "hello world" script and see if that works, then you'll know if it's a configuration problem or a script problem.

    If the script does not execute at all try looking at your ScriptAlias directive & the associated <Directory> block in httpd.conf
    0
     

    Author Comment

    by:lazii
    My script is executing. Like i design a registration page and script will take input from my page and write it a file for me and give customer a confirmation message. When i run it from cgi-bin directory its working properly and returning confirmation message to client browser but when i place my cgi-script in different directory then it returning some garbage value then some c coding and confirmation message as not a browsing style like a C coding.

    Note: I write my script in C.
    0
     
    LVL 15

    Expert Comment

    by:periwinkle
    I would suspect that your web hosting is set up to only allow CGI scripts in the cgi-bin directory.  It's possible as well that you will not be able to override this with an .htaccess handler.

    Try placing the following in your base directory:

    <Limit GET POST>
    order allow,deny
    allow from all
    </Limit>

    I can't remember off the top of my head, but I beleive that these directives may need to go in a <directory> container, like:

    <Directory /full/path/to/your/cgi-bin>
    <Limit GET POST>
    order allow,deny
    allow from all
    </Limit>
    </Directory>
    0
     

    Author Comment

    by:lazii
    I change what u tell me.......but still have asame problem
    0
     
    LVL 15

    Expert Comment

    by:periwinkle
    as mentioned, overrides may not be possible by the .htaccess file - can you change the httpd.conf file?
    0
     

    Author Comment

    by:lazii
    i write a simple script as
    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    <html> <head>
    <title>Example of a Forms page</title>
    </head>

    <body>
    <h1>Forms Page 1</h1>
    This page is an example of a forms page with a submit button. This is the
    first of 2 forms pages. Both pages call the same script. How does the
    script know which page has been used?
    <p>
    <form action="/cgi-bin/test2.cgi" method="post">
    A text field <input type="TEXT" name="text1" size="24">
    <p>
    Some radio buttons. Select one<br>
    Button 1 <input type="RADIO" name="radio" value=1 checked>
    Button 2 <input type="RADIO" name="radio" value=2 >
    Button 3 <input type="RADIO" name="radio" value=3 >
    Button 4 <input type="RADIO" name="radio" value=4 >
    <p>
    <input type="RESET" value="Reset">
    <input type="SUBMIT" value="Submit" name="form1">
    </form>
    </body> </html>

    When i place test2.cgi in cgi-bin directory then it give me the value what i want but when i place it in different folder it gives me some garbage result.


    what configuration i need to change in httpd.conf file  



    0
     
    LVL 15

    Expert Comment

    by:periwinkle
    That's correct.  If your server isn't set up to allow you to run CGI programs in directories outside of the cgi-bin, you'll get the CGI file rendered as text, instead of executing the code.

    You need to locate your virtualhost entry, and add:

    <Directory /full/path/to/your/cgi-bin>
    <Limit GET POST>
    order allow,deny
    allow from all
    </Limit>
    </Directory>
    0
     

    Author Comment

    by:lazii
    probably u r right.  You  mean to change  this tag

    <VirtualHost *:80>
        ServerAdmin webmaster@dummy-host.example.com
        DocumentRoot /www/docs/dummy-host.example.com
        ServerName dummy-host.example.com
        ErrorLog logs/dummy-host.example.com-error_log
        CustomLog logs/dummy-host.example.com-access_log common
    </VirtualHost>

    or what.......if it is not..............i already write

     <Directory "/usr/local/apache/cgi-bin">
            AllowOverride None
            Options ExecCGI
            Order allow,deny
            Allow from all
            <Limit GET POST>
            order allow,deny
            allow from all
            </limit>
        </Directory>
     on my http.conf but afterthat still same problem
    0
     

    Author Comment

    by:lazii
    My CGI script executing and returning some test message on my browser........which is some garbage and some of my script codding......but when it come from cgi-bin then it gives a message in my browser that i write in my script for show when my script is runing properly
    0
     
    LVL 15

    Accepted Solution

    by:
    Your CGI script is a C program, correct?  Then the 'garbage' is the text rendition of the binary file.

    What directory does your html files reside in?  That's the directory that you need to allow get and post;  if it is /www/docs/dummy-host.example.com, then:

    <Directory "/www/docs/dummy-host.example.com">
            AllowOverride None
            Options ExecCGI
            Order allow,deny
            Allow from all
            <Limit GET POST>
            order allow,deny
            allow from all
            </limit>
    </Directory>

    BTW, AllowOverride None is what disables the use of the .htaccess file .
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    875 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

    11 Experts available now in Live!

    Get 1:1 Help Now