PDA

View Full Version : CGI in C? To gcc or not to gcc...



abitaskew
06-16-2010, 02:54 PM
I'm just getting started with my basic site design, but I really need to create a cgi backend that Hostmonster.com will support.
I dig using C libraries for cgi abunch but I'm not sure how to use code I've written in C for my site with Hostmonster.com.
I have enough problems getting apache to handle my cgiC locally let alone a remote server.

A question that could walk me through the answers to these other Qs would be:
What would need to be done for someone to get a very simple "<b>Hello, World!</b>" program in ANSI-C to printf through the gateway as a CGI program on Hostmonster?
Impossible? Then should I pick up perl, php instead? *sigh*:rolleyes:


How would I go about creating/debugging cgi "scripts" in C through HM.com?
Would it have to be compiled on my home server with GCC and then uploaded to Hostmonster? Do I need some kind of tricky flags for gcc compiler?
Or does the source code need to be compiled locally on the server?
Is three a simple way to do this via ftp/http or should I apply for ssh access to get it done via cmd? I hesitate to Fax away my Licence, CC, SS, 1st born...etc.


`
Also, Is there an IRC(undernet, efnet, dalnet) channel for developers to chat and ask questions?
Thank you so much. I am still looking through the posts. I am loving hostmoster.com and I am very impressed by the collective effort of of the forums admin/s and all us users! Thanks again for the Help!

Treeluvin
06-20-2010, 01:15 AM
1. Shell access would be the only way, really.
2. Either way, although doing it on the host would be easier, I think. No special flags needed.
3. See 2
4. I would highly recommend getting SSH access.

Here's a very simple "Hello, World" script:


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
puts("Content-type: text/html\r\n\r\n");
puts("<b>Hello World!</b>");
return 0;
}

And then we compile it and give it execute permissions

gcc -Wall index.c -o index.cgi
chmod +x index.cgi

abitaskew
07-12-2010, 09:17 AM
Well done Treeluvin and thank you so much for the example. There couldn't have been a more clear answer.
I used to use an fopen() and fprintf()s before. I'm learning alot about libs and their portability. I'll get SSH as soon as I get to a scanner to mail my ID.
I hope your answer might encourage others to code in C. It's fun and can be a learning experience in secure programming.

-askew