1
[Fri Jan 29 20:23:28 2010] [error] [client 23.23.23.23] Premature end of script headers: header.php
[Sat Jan 30 10:22:42 2010] [error] [client 23.23.23.23] (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.

1
  • 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, 2010 at 23:08

6 Answers 6

3

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

3

Long shot, but try adding

AddHandler application/x-httpd-php .php

to your apache configuration file.

1
  • 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! Apr 18, 2018 at 23:13
2

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

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

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:

#!/usr/bin/php
1

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

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

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

to

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

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

0

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

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>

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

AddHandler cgi-script .py

</VirtualHost>

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.

0

You must log in to answer this question.