Getting Started with CGI Programming in C on Ubuntu 8.10


This is an introduction to writing CGI programs in the C language. The reader is assumed to know the basics of C as well how to write simple forms in HTML and to be able to install CGI scripts on a Web server. The principles are illustrated with very simple examples.

  1. Cek modul cgi in your apache webserver. Cek in directory /etc/apache2/mods-enable/cgi.load
  2. Make directory cg-bin in /var/www/ with command mkdir /var/www/cgi-bin
  3. Make C program and save with coba.c name.
    #include
    int main(void) {
      printf("Content-Type: text/plain;charset=us-ascii\n\n");
      printf("Hello world\n\n");
      return 0;
    }
  4. Compile coba.c with gcc. gcc coba.c and you result a.out file
  5. Rename that file a.out became a.cgi and copy to /usr/lib/cgi-bin
    cp a.out a.cgi
    cp a.cgi /usr/lib/cgi-bin/
  6. Open firefox and run this program : http://localhost/cgi-bin/a.cgi and result like
    Hello World

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s