Basics of CGI
by Hiroshi on October 10th, 2007
Some basics and essentials of CGI which you must know before writing your first CGI code or your CGI scripts won’t work.
- Always Remember CHMOD that is the file permissions. Set it using your favorite ftp software. CGI script file it must be 755 and at folder which contains CGI scripts also 755 but for the folder which stores data it must be 777.
- Cgi pages use cgi-bin directory.
- The first line of many CGI scripts is: #!/usr/local/bin/perl or #!usr/bin/perl (if the script is written in Perl).
- Path to sendmail is
Use it while sending mails like this in a variable
my $sendmail = “/usr/sbin/sendmail”;
Path to perl
- When error occurs Cgi won’t guide you about exact error. You will have to see the error log in your hosting account.
CHMOD for cgi pages.. Must be 755.
Scripts pages permissions must be executable.
- 500 error occurs in cases of *File execution wrong permissions *First wrong interpreter line *Syntax error *Missing required file *Invalid HTTP headers sent as referred in point 5. *Wrong version of perl *Server configuration error
- The first output sent by a script must always be a valid HTTP header, i.e.
Content-type: text/html or Content-type: text/plain\n\n
The header must always be followed by two linefeeds.
Some Useful resources Links