Available article translations:

500 Internal server error appears when I try to call my cgi script by URL using a browser. What could it be in this case?


1. Check /etc/httpsd/logs/suexec_log or /var/log/httpsd/suexec_log for errors while attempting to run CGI scripts. Suexec catches permission and ownership errors.

Make sure that the cgi-bin/ folder has the following permissions and ownership:

drwxr-x--- myuser psaserv cgi-bin

The script itself must be owned by domain FTP user but group must be 'psacln':

-rwxr-xr-x myuser psacln script.cgi

Make sure that the permissions of the script file and the directory tree (relative to the server's document root) are set not higher than 755 or user: read, write, execute; group: read, execute; other: read, execute (-rwxr-xr-x).

2. Plesk uses it's own suexec file and it might have been replaced by the original one that comes with standard apache package. In this case you need to restore it using the command:
# /bin/cp /usr/sbin/psa-suexec /usr/sbin/suexec

If SuSe 9.x is being used then /usr/sbin/suexec2 should be replaced with the original one.
# /bin/cp /usr/sbin/psa-apache2-suexec /usr/sbin/suexec2

For Debian operation system please use this command line:
# /bin/cp /opt/psa/suexec/psa-suexec2 /usr/lib/apache2/suexec2

For details how to upgrade Apache on the Plesk based server please follow article 762.

3. Script may contain Windows carriage-return symbols at the end of each line which were not removed when you uploaded file onto the server by FTP from Windows workstation.

End of lines in files are marked with 'carriage-return' (CR) and line-feed (LF) hidden characters on Windows systems, while Unix systems mark end of line with LF character only.

It is needed to upload text files in ASCII transfer mode from Windows box, in this case CR,LF characters will be replaced with LF only. If CGI scripts are uploaded in BINARY mode, the files are uploaded as is without converting. When script is executed, CR characters are recognized as part of text and are not interpreted correctly, for example:

use strict;CR

You can also set the default transfer mode to ASCII server wide in the /etc/proftpd.conf file:

DefaultTransferMode ascii

To check and correct already uploaded script with CR characters manually use one of the following variants:

a) remove CR with col utility:
# cd /home/httpsd/vhosts/
# col -bx < script.cgi > script2.cgi
# ls -l
total 84
-rw-r--r-- 1 myuser psacln 27683 Jun 14 15:51 script2.cgi
-rwxr-xr-x 1 myuser psacln 25753 Jun 14 11:20 script.cgi
# mv script2.cgi script.cgi
mv: overwrite `script.cgi'? y
# chmod 755 script.cgi
# chown myuser:psacln script.cgi

Please use name of the script's owner instead of myuser.

b) open file in pico text editor and save it then, it will remove CR symbols from the file.
# pico script.cgi

4. Run the script from the command line and check for errors.
# cd /home/httpsd/vhosts/
# ./script.cgi
: bad interpreter: No such file or directory

Check the script to make sure that magic comment specifies where perl is located: #!/usr/bin/perl and/or check for CR symbol in the end of #!/usr/bin/perl line, as described in option 3.

# ./script.cgi
String found where operator expected at sc.cgi line 3, near "xcprint """
(Do you need to predeclare xcprint?)
syntax error at sc.cgi line 3, near "xcprint """
Execution of sc.cgi aborted due to compilation errors.

This example shows that there is some syntax error in this script and it won't work until you correct it.

Was this article helpful?
Tell us how we may improve it.
Yes No