# C coded CGI scripts..

**URL:** <https://forums.interworx.com/t/c-coded-cgi-scripts/9261>\
**Category:** General Inquries\
**Created:** [October 27, 2004, 12:28pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261 "2004-10-27T12:28:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 27, 2004, 12:28pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/1 "2004-10-27T12:28:43Z")

</div>

Hello,

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?

Thx.

---

<div class="post-metadata">

**Author:** ![Paul](https://forums.interworx.com/user_avatar/forums.interworx.com/paul/32/6_2.png) [@Paul](https://forums.interworx.com/u/Paul)\
**Post date:** [October 27, 2004, 12:31pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/2 "2004-10-27T12:31:56Z")

</div>

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.

Paul

---

<div class="post-metadata">

**Author:** ![IWorx-Bojan](https://forums.interworx.com/letter_avatar_proxy/v4/letter/i/e9bcb4/32.png) [@IWorx-Bojan](https://forums.interworx.com/u/IWorx-Bojan)\
**Post date:** [October 27, 2004, 12:40pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/3 "2004-10-27T12:40:12Z")

</div>

CGI in C

feroz,

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

Bojan

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 27, 2004, 1:11pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/4 "2004-10-27T13:11:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 27, 2004, 1:23pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/5 "2004-10-27T13:23:45Z")

</div>

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](http://hoohoo.ncsa.uiuc.edu/cgi/interface.html)

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

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 27, 2004, 1:42pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/6 "2004-10-27T13:42:36Z")

</div>

ok, thx everyone… Ill try and let you know… 🙂

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 27, 2004, 3:02pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/7 "2004-10-27T15:02:43Z")

</div>

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 :

> 

\<VirtualHost 65.110.36.141:80\>

#sUexecUserGroup kelftpco kelftpco

DocumentRoot /home/kelftpco/kelftp.com/html  
ServerName [kelftp.com](http://kelftp.com)

ServerAlias [www.kelftp.com](http://www.kelftp.com) [ftp.kelftp.com](http://ftp.kelftp.com) [mail.kelftp.com](http://mail.kelftp.com)  
ServerAdmin [webmaster@kelftp.com](mailto: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  
\</Directory\>

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

\</VirtualHost\>

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

Pascal

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 27, 2004, 3:47pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/8 "2004-10-27T15:47:18Z")

</div>

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](mailto: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)

> 

#!/usr/bin/perl  
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

Thks

pascal

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 27, 2004, 4:17pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/9 "2004-10-27T16:17:34Z")

</div>

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/](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

> 

#!/usr/bin/perl  
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

Pascal

---

<div class="post-metadata">

**Author:** ![Paul](https://forums.interworx.com/user_avatar/forums.interworx.com/paul/32/6_2.png) [@Paul](https://forums.interworx.com/u/Paul)\
**Post date:** [October 27, 2004, 5:15pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/10 "2004-10-27T17:15:48Z")

</div>

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.

Paul

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 27, 2004, 6:33pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/11 "2004-10-27T18:33:53Z")

</div>

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

Pascal

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 27, 2004, 6:35pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/12 "2004-10-27T18:35:43Z")

</div>

```auto
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.

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 27, 2004, 9:06pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/13 "2004-10-27T21:06:20Z")

</div>

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.

@++  
pascal

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 28, 2004, 6:17am UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/14 "2004-10-28T06:17:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 28, 2004, 9:15am UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/15 "2004-10-28T09:15:04Z")

</div>

> [@sonicgroup](#):
>
> 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.

UNIX is

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.

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 28, 2004, 9:57am UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/16 "2004-10-28T09:57:34Z")

</div>

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.

[http://www.cs.tut.fi/~jkorpela/forms/cgic.html](http://www.cs.tut.fi/~jkorpela/forms/cgic.html)

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

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 28, 2004, 12:12pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/17 "2004-10-28T12:12:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 28, 2004, 1:21pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/18 "2004-10-28T13:21:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Justec](https://forums.interworx.com/letter_avatar_proxy/v4/letter/j/e47774/32.png) [@Justec](https://forums.interworx.com/u/Justec)\
**Post date:** [October 28, 2004, 1:33pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/19 "2004-10-28T13:33:17Z")

</div>

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??? 😕

---

<div class="post-metadata">

**Author:** ![system](https://forums.interworx.com/uploads/default/original/2X/4/40ab17cc34b792a0172b48ad1333b9ba9299a9a1.png) [@system](https://forums.interworx.com/u/system)\
**Post date:** [October 28, 2004, 10:19pm UTC](https://forums.interworx.com/t/c-coded-cgi-scripts/9261/20 "2004-10-28T22:19:31Z")

</div>

> [@Justec](#):
>
> 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??? 😕

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

[Next page](https://forums.interworx.com/t/c-coded-cgi-scripts/9261.md?page=2)
