|
My CGI Scripts do not work
Often times, the most common causes for CGI scripts to fail are : (1)Presence of control characters in the script (2)Permissions problems (read/write/execute) (3)Coding issues [Control Characters] Control characters are caused by editors such as Notepad on Windows (and many other editors) that insert their interpetation of a carriage return/line feed when you press the enter key. Most standards compliant editors simply denote with the meta charater "$" , but editors that cause problems us a "^M$", which causes problems with Unix systems attempting to run these scripts. Your best option is editing the scripts with something like WordPad (Windows) and just saving the file (i.e. open file, when done with changes just "Save", not "Save As", etc) to try and avoid this. Also a command line session using an editor such as vi or pico on your SSH login for you account is another good way to edit files. Sometimes though, prior to editing scripts have control characters in them. To check for the existance of control characters in a file from a command line run this command: cat -A FILENAME if you see "^M"s throughout the file, you will need to strip those out. This can be done using the dos2unix command like so: dos2unix FILENAME i.e. - dos2unix admin.pl you will need to correct permissions after running this program (and possibly ownership as well). [Permissions Problems] Permissions problems ususally occur when a file needs to be executable, but is not, or needs to be written to but the write operation fails. The failure occurs most often because the file is owned by your user, but the script is running as the web server user and group (typically either nobody or apache). The simplest way to correct this is to change the *group* ownership to the web server user (on our servers this is almost always the "nobody" group) and to make sure that the file is group writable. You do not want to change the owner of the file to the web server user, because you will not be able to overwrite or delete the file once you have done this. For more information on changing permissions and ownerships, search the knowledge base for the subject "permissions" or "ownership". [Coding Issues] If all other options are ruled out, there is usually a problem with the code somewhere in the script. The best way to check for these issues are to make sure the call to the perl interpreter has a "-w" included (i.e. - #!/usr/bin/perl -w) and to call the script from a command line like so: perl MYSCRIPT.pl This will usually provide warnings or other error messages. Additionally, if writing your own scripts, making sure that good coding standards are in place (i.e. options in the script like "use strict") will always help to not only avoid errors, but to identify them when they occur. support@mercuryd.com |