Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

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.
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

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] unable to include "cgi-bin/echo.cgi"     in parsed file /var/data/www/

... but they are accompanied by:

[Sun Dec 11 07:31:39 2011] [error] [client] malformed header from script. Bad header=/var/data/www/ 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


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.