Blue Ribbon Campaign for Free Speech Frequently Asked Questions

for CGI Made Really Easy

  1. Why won't my CGI script run?
  2. Here is my script. Please look at it and tell me why it doesn't work.
  3. Can I test CGI scripts on my own machine?
  4. How do I configure a Web server on my machine?
  5. Do I have to compile hello.c, or just rename it to hello.cgi?
  6. Can a CGI script do <insert-task-here>?
  7. How do I write a CGI script that does <insert-task-here>?
  8. Do you have a CGI script that does <insert-task-here>?
  9. Will you write me a CGI script that does <insert-task-here>?
Back to Main Page


Why won't my CGI script run?

Make sure you read the footnote about Placing Your Script on the Server. If nothing there works, then find out how CGI scripts should be configured on your server. Ask your webmaster, or system administrator, or whoever is in charge of your Web server. If you are running your own server, then read the server documentation.

Install one of the sample scripts to make sure your CGI setup is working.

Every server is configured differently. You are in a better position to figure out your own server than I am.

Here is my script. Please look at it and tell me why it doesn't work.

Nothing personal, but I don't have time to debug everybody's CGI scripts. Use normal debugging techniques, like you would for any other program: Isolate exactly what is going wrong by removing as much as possible from your program. Add debugging commands that print the values of certain variables at certain points in your program. Compare it to a working program (like one of the samples). If your question is language-related, then ask someone who knows the language. You know, the same old stuff.

Again, this tutorial is not meant to teach you programming. That is a very broad topic that takes much longer to learn. Programming experience is a prerequisite to this tutorial.

Can I test CGI scripts on my own machine?

You cannot run CGI scripts by merely loading them in your browser. CGI scripts must be run by a Web server, to properly set up the environment and I/O used by the CGI script. Therefore, you can only test them on machines that are running a Web server.

Web servers are available for most platforms; see the next question.

How do I configure a Web server on my machine?

Unix is by far the best platform to run a Web server on, since Internet technology has always been developed on, for, and with Unix. Contrary to popular belief, Unix runs on any cheap PC. It's free, easy to use, much more powerful and stable than Windows, and requires less hardware. You can add Unix to your PC without removing your old operating system. Unix is also available for Macs and other platforms. Linux and FreeBSD are good free versions; commercial versions are also available.

If you're running Unix, I recommend the Apache server. It's free, and often included as part of Unix. It's a solid product, used by the majority of Web sites in the world.

If you're running another operating system, here is Yahoo's list of Web servers, sorted by operating system.

For help in configuring your server to support CGI scripts, read the server documentation. If people send me links to good help pages, I may add them here.

Do I have to compile hello.c, or just rename it to hello.cgi?

(You wouldn't believe how many times I get asked this question.) Yes, you have to compile hello.c, as you do for any C program. You must compile it on the machine where it will run.

A CGI program must be an executable program, just like any other program. C source code is not executable. A Perl script usually is. These are basic programming concepts. I do not recommend writing CGI programs until you have at least minimal programming experience.

Can a CGI script do <insert-task-here>?

A CGI script is a program running on the server that reads input, generates output, and does whatever else you tell it to, normally with the same permissions as the Web server. It can do anything such a program can do, including file I/O, network I/O, database interaction, etc.

How do I write a CGI script that does <insert-task-here>?

How would you write a non-CGI program to do the same thing? The only part that's specific to CGI has to do with the input, the output, and the environment variables.

Avoid asking me general programming questions; that's a much bigger teaching task than I have time for.

Do you have a CGI script that does <insert-task-here>?

I don't keep a collection of CGI scripts, but there are many such collections on the Web. Here's a pretty good one, sorted by programming language, then script function.

Often, you can find an existing script that's close to what you need, then modify it.

Will you write me a CGI script that does <insert-task-here>?

Many people who ask this mean "for free". The answer is No, I'm way too busy. That's why I wrote this tutorial, to teach other people how to write scripts, because I don't have time to write all of them.

If you mean you want to pay someone to write CGI scripts, that's a slightly different story. I do such consulting for a living, but I'm normally too busy to take on new work. However, I often know someone who can help; feel free to ask.

Back to Main Page


© 1998 James Marshall

Last Modified: April 18, 1998 http://www.jmarshall.com/easy/cgi/easy_cgi_faq.html