Suso Logo suso
Support Site
main site     webmail    

This document covers other problems you might have trying to run your CGI programs. If you are having trouble with suexec, see this document instead.

Shbangs! Shbangs! (#!)

On a Linux system, scripted or interpreted programs like those written in Perl, Python or shell scripting need to have a line at the top of their program file that indicates to the computer what language interpreter to run when running the program. This is called a shbang (prounced shuh-bang) line because the # character is called a hash and the ! is called a bang. For a perl program, that line will look like this:


The line might have some options at the end of it as well that get passed to the perl interpreter.

The most important part here is to make sure that the path to the interpreter is correct. On, the paths for the different interpreters are listed below:

perl /usr/bin/perl
python /usr/bin/python
php /usr/bin/php (this is for CGI mode PHP)
sh /bin/sh
bash /bin/bash
csh /bin/tcsh

Windows/DOS files and CR, LF characters

Another common problem people encounter with CGI scripts is when a file is in DOS ASCII mode. This happens when a file was edited on a windows machine and then uploaded the file using scp or something like that. The lines might have an invisible character at the end called a carriage return (CR). To see if this is the case, you can run the file command on the program file and it will tell you.


If you get the error " ASCII text, with CRLF line terminators", then this file is a dos file.

Also, some text editors might tell you that the file is in dos format. The CR character is something that Linux doesn't use and must be removed if your program is going to work properly. To convert your file from the DOS format, you can use the program called dos2unix:


Printing out data before the Content-type line

In order for your CGI program to work properly with the web server, the first line that it needs to send is "Content-type: text/html" followed by two newline characters. Like this:

Content-type: text/html

You can't see newline characters normally, but you can write programs that will print them out to a file or to the screen. The command in Perl to send this output is:

print "Content-type: text/html\n\n";

If anything is sent to the webserver before this line then you will wind up with a 500: Internet Server Error. This might happen if you are using the -w option to the perl interpreter or if you accidently print out a line for debugging to early in the output.