Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a page site.shtml on an Apache server in which I am trying to include a few CGI scripts, like so:

    <p><pre><!--#include virtual="files/testfile" --></pre></p>
    <p><pre><!--#include virtual="cgi-bin/randhtml.cgi"--></pre></p>
    <p><pre><!--#include virtual="cgi-bin/echo.cgi" --></pre></p>
    <p><pre><!--#include virtual="echo.cgi" --></pre></p>
    <p><pre><!--#include virtual="cgi-bin/echo.cgi?test" --></pre></p>

In this case, files/testfile is a text file, cgi-bin/randhtml.cgi is a preinstalled CGI executable, and both instances of echo.cgi are the script:

#!/bin/sh
echo $0;
echo $*;

All scripts have permissions set to 755 and can be executed from the shell, where they behave as expected (random output or echoing back arguments).

When I try to load the web page, the file and random script are executed correctly and I get the expected output. The echo scripts are not and I get a number of errors in the page:

This is a test text file.
random
An error occurred while loading this page.
An error occurred while loading this page.
An error occurred while loading this page.

The error log contains only:

unable to include "cgi-bin/echo.cgi" in parsed file /home1/user/public_html/site.shtml
unable to include "echo.cgi" in parsed file /home1/user/public_html/site.shtml
unable to include "cgi-bin/echo.cgi?test" in parsed file /home1/user/public_html/site.shtml

I've tested with various other scripts, both shell and perl, named .cgi and .pl (Apache is set up to handle both as CGI scripts), and all appear to give this error. I've double-checked the permissions and tried them with 777, to no avail. I've written the virtual paths as cgi-bin/ and /cgi-bin/, neither works.

Is there some limitation I'm running into, a syntax error, or some strange server issue?

share|improve this question

1 Answer 1

You may need to add a Content-type header to your CGI output.

Are you sure that nothing else shows up nearby in your Apache error logs? (Are you grepping them, or looking at them unfiltered?) When I tried to recreate your problem, I see lines like this:

[Sun Dec 11 07:27:47 2011] [error] [client 192.0.2.1] unable to include "cgi-bin/echo.cgi"     in parsed file /var/data/www/www.example.org/ssi-test.shtml

... but they are accompanied by:

[Sun Dec 11 07:31:39 2011] [error] [client 192.0.2.1] malformed header from script. Bad header=/var/data/www/www.example.org: echo.cgi

I suspect that if you add:

echo "Content-type: text/html"
echo ""

... to the top of your script, before any other output appears, your problem will go away ... or at least this part of it will. :-)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.