[Fri Jan 29 20:23:28 2010] [error] [client] Premature end of script headers: header.php
[Sat Jan 30 10:22:42 2010] [error] [client] (8)Exec format error: exec of '/var/www/cgi-bin/header.php' failed

how to fix this ? basically a .cgi script loads header.php which contains javascripts and some php stuff.....

i notice .cgi script runs fine but none of the javascripts and php things work.

  • 4
    You've given us so little to go on that most of us will be making a complete shot in the dark answering this. Anything else you feel like you can tell us? Are you wanted someone to explain the error message or fix some script. You may want to try stackoverflow. – Patrick R Jan 30 '10 at 23:08

The best anybody can do without more information, since you've given almost none, is guess. Here's mine:

You've either got a missing semicolon or parenthesis or curly brace somewhere (or some other delimiter or bracketing character) or there are DOS line endings (\r\n) where there should be Unix ones (\n).


Long shot, but try adding

AddHandler application/x-httpd-php .php

to your apache configuration file.

  • Wow. I "accidentally" updated my laptops local webserver with the system together and was almost driven crazy. Found your answer, wanted to upvote, logged in and discovered that I upvoted this back in 2015 already... So thanks, again! – Julian F. Weinert Apr 18 '18 at 23:13

Try to see if your web server has something like this i.e in Apache:

ScriptAlias /cgi-bin/
<Directory /cgi-bin/>
   Options ExecCGI ...

The forces the entire directory to be executable ( like you're trying to run a python/perl script )

If you have that - make sure your file is executable ( chmod +x ... )

And check for the php interperter ( maybe ) at the first line of the CGI script like:


i've two ideas:

  • perhaps you have a permission problem with your php file. make sure it has the right permissions for owner and group.
  • perhaps you are mixing html header and body elements. be sure you are including the php file at the right position.

If by any chance you are running CGI you can't assign it to the main folder of your application as files such as CSS or JS will be tried to be "Exec"-ed by Apache resulting in AH01215: (8)Exec format error: exec of ERROR inside /var/log/apache2/error.log

Create separate folder for executable files only and add something like this to your /etc/apache2/sites-enabled/sub.domaian.com.conf

<VirtualHost *:80>
DocumentRoot "/var/www/html/yoursite"
ServerName sub.domain.com

<Directory "/var/www/html/yoursite">
allow from all
Require all granted

<Directory "/var/www/html/yoursite/CGI">
Options ExecCGI
SetHandler cgi-script

AddHandler cgi-script .py


Interesting enough: I had SetHandler cgi-script assign to main folder and in my situation I could open the page with no issue when I was accessing the page through LAN but not from WAN.


Another possibility (all previous answers might also be valid reasons):

Change this directive in /etc/apache2/php/php.ini :

ScriptAlias "/phptest/"   "/var/www/phptest/"  


Alias "/phptest/"   "/var/www/phptest/"

(All pathnames are made up by me - change to values that apply to your server setup)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.