Bash / CGI – Premature end of script headers

Issue

When trying to add a image to your CGI script you recieve the following error and the image isnt displayed.

[root@localhost cgi-bin]# cat /var/log/httpd/error_log
[Fri Jul 10 20:51:39 2009] [error] [client 10.2.2.5] Premature end of script headers: picture2.jpg, referer:
[Fri Jul 10 20:57:57 2009] [error] [client 10.2.2.5] (8)Exec format error: exec of ‘/var/www/cgi-bin/picture2.jpg’ failed, referer:

Solution

Add to your httpd.conf or apache.conf file an alias such as,

Alias /images/legacy/ /usr/share/images/legacy/

Once added restart you httpd/apache daemon. And add your images to the directory.

#!/bin/sh
unset PATH
echo “Content-type: text/html”
echo “”
echo “<html>”
echo    “<body>”
echo            “<img src=”/images/legacy/picture.jpg”>”
echo    “</body>”
echo “</html>”

 Your page should now display the picture.

Rick Donato

Want to become a Linux expert?

Here is our hand-picked selection of the best courses you can find online:
Linux Mastery course
Linux Administration Bootcamp
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial