C coded CGI scripts..


We got a customer who is tryin to run a cgi script he wrote with C…
But encountrin an error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Do you need any specific libs to be installed to run CGI script written in C?

Our server is running on linux (centOS)

Could you pls help?


The two places I would check would be the user’s error log, which is viewable in SiteWorx or at /home/<user>/var/<domain>/logs/error.log

and also the /var/log/httpd/suexec.log for any errors that appear when trying to run the CGI written in C.


CGI in C


You might need cgic to run CGI coded in C. Check http://www.boutell.com/cgic/ for more info. Hope that helps.


There is also the VERY likely error of bad code, the error logs will help with this. C isnt know for having ‘great’ error messages.

Speaking from experience, be careful w/ them, a c cgi crashing can take a whole system down, and if there are memory errors (you can overrite / read memeory you shouldnt) you can again kill a system. But they are crazy fast, and efficient.

CGIC is pretty handy (I’ll have to look into that) but not necessary (I’d use it, though).

CGI is pretty much just a promise that two programs will provided each other data. There isn’t anything special about it you can’t reproduce yourself.

So, I’d say check the logs as mentioned as it is most likley an error with the program or its output. If what you see doesn’t immediatly provide and anwser, run the program according to the CGI specs: http://hoohoo.ncsa.uiuc.edu/cgi/interface.html

Then you can see for yourself if the output is what it should be.

ok, thx everyone… Ill try and let you know… :slight_smile:

Hello all

To continue with the feroz’s thread (a carat-hosting guy) I’m very surprised to not see any of Options +ExecCGI in the /cgi directory in the /httpd/conf.d/domaine.conf file

I have commented the SuExecUserGroup as I did have problem with that when I installed CGI script on my own domain

So I changed the domain’s httpd conf files to this :


#sUexecUserGroup kelftpco kelftpco

DocumentRoot /home/kelftpco/kelftp.com/html
ServerName kelftp.com

ServerAlias www.kelftp.com ftp.kelftp.com mail.kelftp.com
ServerAdmin webmaster@kelftp.com

subdomain logic

RewriteEngine On
RewriteOptions inherit
RewriteCond %{HTTP_HOST} !^www.kelftp.com [NC]
RewriteCond %{HTTP_HOST} !^kelftp.com [NC]
RewriteCond %{HTTP_HOST} ^([A-Z0-9a-z-]+).kelftp.com [NC]
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule ^(.+) %{HTTP_HOST}/$1 [C]
RewriteRule ^([0-9A-Za-z-]+).kelftp.com/?(.*)$ %{DOCUMENT_ROOT}/$1/$2 [L]

end subdomain logic

ErrorLog /home/kelftpco/var/kelftp.com/logs/error.log
CustomLog /home/kelftpco/var/kelftp.com/logs/transfer.log combined

php_admin_flag engine On

cgi: 1

<Directory /home/kelftpco/kelftp.com/html>
AllowOverride AuthConfig FileInfo Options Limit Indexes
Options +ExecCGI

ScriptAlias /cgi-bin/ /home/kelftpco/kelftp.com/html/cgi-bin/


For me this should be OK.

And I said to this user to install the C librairy CGIC in his /CGI directory.

Thx to all


now I understand nothing.

I’ve created a little perl script. Downloaded it in /cgi-bin/ chmod to 755 and run it and I have the same error

The error

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@carat-hosting.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

the script (more esay you dead)

print "Content-type: text/html

print “Test de fonctionnement :-)”;

If I run it from the server directly it works !!

Where is the pbm ?

Help are really welcomed



I’m goinf mad. I have an other Perl script which works fine.

So I’v let the suexeusergroup and removed the Options +ExecCGI

This script works

#! /usr/bin/perl

$PrintDate = 1; # En: Display date? 1 Yes, 0 No (ex: Sonntag, May 30 1999)
# Fr: Affiche la date? 1 Oui, 0 Non (ex: Sonntag, May 30 1999)

$PrintTime = 1; # En: Display time? 1 Yes, 0 No (ex: 15:30:00)
# Fr: Affiche l’heure? 1 Oui, 0 Non (ex: 15:30:00)

$Lang = “En”; # Chose Language (Fr: French, Se: Swedish, Other: English)
# Changer de langue (Fr: Francais, Se: Suedoi, Autre: Anglais)
# Swedish version by rask, http://www.angen.net/~rask/

Nothing Below this line needs to be altered!


if ($Lang eq “Fr”) {
@WeekDays = (‘Dimanche’,‘Lundi’,‘Mardi’,‘Mercredi’,‘Jeudi’,‘Vendredi’,‘Samedi’);
@Months = (‘Janvier’,‘Février’,‘Mars’,‘Avril’,‘Mai’,‘Juin’,‘Juillet’,‘Août’,‘Septembre’,‘Octobre’,‘Novembre’,‘Decembre’);
} elsif ($Lang eq “Se”) {
@WeekDays = (‘Söndag’,‘Måndag’,‘Tisdag’,‘Onsdag’,‘Torsdag’,‘Fredag’,‘Söndag’);
@Months = (‘Januari’,‘Februari’,‘Mars’,‘April’,‘Maj’,‘Juni’,‘Juli’,‘Augusti’,‘September’,‘Oktober’,‘November’,‘December’);
} else {
@WeekDays = (‘Sunday’,‘Monday’,‘Tuesday’,‘Wednesday’,‘Thursday’,‘Friday’,‘Saturday’);
@Months = (‘January’,‘February’,‘March’,‘April’,‘May’,‘June’,‘July’,‘August’,‘September’,‘October’,‘November’,‘December’);

print "Content-type: text/html


($Sec,$Min,$Hour,$Day,$Month,$Year,$Week_Day) = (localtime);
$Year += 1900;
if ($Sec < 10) { $Sec = “0”.$Sec; }
if ($Min < 10) { $Min = “0”.$Min; }
if ($Hour < 10) { $Hour = “0”.$Hour; }
if ($Day < 10) { $Day = “0”.$Day; }

if ($PrintDate) {
if ($Lang eq “Fr”) {
print $WeekDays[$Week_Day]." “.$Day.” “.$Months[$Month].” “.$Year.”
} else {
print $WeekDays[$Week_Day].”, “.$Months[$Month].”, “.$Day.” “.$Year.”
if ($PrintTime) {
print "$Hour:$Min:$Sec

But not this one

print "Content-type: text/html

print “Test de fonctionnement :-)”;

So it confirms that the apache conf file for this domaine is fine.
I’ll test a very simply C script with CGIC


Have you checked both the user’s error log and the suexec log?
The user’s error log is located at /home/<user>/var/<domain>/logs/error.log and the suexec.log file is at /var/log/httpd/suexec.log.

One of those two log files should tell you something about what the problem is.


yep nothing special.

One it doesn’t work there is only this message in the error log

Premature end of script headers

that’s all

All CGI others than perl doesn’t work. (but not my little one lol )

For me the pbm is that the C program is not compiled on the server but on the workstation

I’ll try to compile a C source directly on the server with GCC

Let you know (but I’m pretty sure the pbm is this one)

Thanks Paul


print "Content-type: text/html 


I never checked to see how picky Apache is, but if you have an extra space at the end of your content-type header that might be an issue.

As Paul said, you’ve really got to check your logs. The server logs will tell you almost exactly what is wrong.

lol no pbm for my little script !!!

The begining of this thread was about CGI written in C.

As it didn’t work I did a simple test in the cgi-bin directory with this script and I 'd see that the Apache conf file was good… It was the goal of this step

Ok as I told you I made some tests.

Here is the result :

From now I can run CGI in C when I compile them directly on the server using GCC.
Using or not CGIC, it works.

I’m going to test mingw, cygwin and DevC++

I know (think to know) that they use a GCC compiler.

The goal is to be able to create C pgm on windows and run them on a http Linux server (cgi)

Thanks to all of you for your help.


IIRC, the lines for headers should be terminated with a carriage-return-newline sequence (i.e.
), not a newline-newline sequence.

Headers need to be terminated with 2 new lines. Newlines depend on the platform.


Mac OS is \r
Windows/DOS is

CGI should be happy with any, so long as two appear. Don’t quote me on that just yet though.

With perl cgis, IIRC, you need to include ::CGI.

For C CGIs you need to compile them on the same processor, and OS as the server. So compiling on Windows (in cygwin) on a p4 isnt the same as compiling on Linux on a PIII. C is VERY touchy.


Is a simple tutorial on how to make c cgis (Found using google: “c” cgi simple )

You never need to include anything CGI specific to do CGI programming. It is helpful, yes, as you get some cushy functions, but its never a necessity regardless of language, so long as it can work with STD{IN,OUT}, enviornment variables, and command line parameters.

Ah, ‘Learning Perl’ kinda drilled it into my head to include it, and I havent done c cgis in about 5 yrs, so im a bit foggy on it. :slight_smile:

I’ve had problems with CGI scripts when creating them in notepad (windowsXP) and uploading via FTP. When I just create the script in vi it works okay. But other times it works fine editing in windows and uploading, so I dont know??? :confused:

That’s probably because of the differences in how newlines are represented in various operating systems.