CGI scripts fail with 'exec format error'

A CGI script must begin with a valid 'interpreter line' also called 'shebang'. That must be the first line in the file and must start in the first column. It should begin with the two characters '#!', followed by a path to an interpreter, followed by any options.

For example:

#!/usr/bin/php

will run the script through the PHP interpreter at /usr/bin/php.

#!/usr/bin/perl -w

runs the script through /usr/bin/perl with the -w flag to enable warnings.

An 'exec format error' is the result of an invalid interpreter line. That could be because the interpreter line is missing, or indented with a tab, for instance.

  • 71 Users Found This Useful
Was this answer helpful?

Related Articles

When I try and view my website I get an HTTP Error 403 - Forbidden message.

A '403 Forbidden' message means that the browser has requested a page that it is not permitted to...

My CGI/ASP/PHP script is giving an error when trying to write to a file.

This applies to Linux hosting accounts only.This is almost certainly down to incorrect...

A custom filetype isn't being recognised, how can I make sure it is?

You can force this through using a '.htaccess' file. Remember that the directives inside an...

My CGI/Perl scripts are failing with error 500 (Internal Server Error)

These errors are nearly always related to a coding error within the script, or bad variables...

I can't see the images on my website. Why?

There are several possible reasons why your images are not showing up on your pages as...