Tips for fixing common problems….-cgi files generate Internal Server Error
Tips for fixing common problems….-cgi files generate Internal Server Error-This means that the cgi script did not execute properly.
Note There are several causes that can generate this error so a few things would need to be checked then.
1) check the /var/log/httpd/suexec_log. It will contain any errors that would be as a result of not having correct permissions on the file.
The file needs to be in a cgi-bin and must have the owner/group as the username who owns the site.
If it is owned by anyone else, it will not run. Also, the script must have execute permission. The most common chmod permission is 755.
Go through all directories from the public_html down to the directory the script is in, and make sure they are all set to 755 (public_html can be 750 *only* if it has a group of apache).
If the suexec_log only shows the script being run, then the cause may be with the script code itself. The easiest way to figure out script coding problems is to first run the script manually from an ssh prompt.
cd /home/username/domains/domain.com/public_html/cgi-bin
./script.cgi
One common error is to use an incorrect interpreter. The 2 most common interpreters are:
#!/usr/bin/perl
and
#!/usr/local/bin/php
This code must appear on the first line of the script. Sometimes a file is uploaded in windows format so the trailing newline (return) character is formed incorrectly and the file would need to be re-uploaded in a different format.
Other errors that would be generating when running the script manually from ssh would be missing perl modules, in which case you will need to install them yourself.
Cpan is the easiest method to install new perl modules, eg:
perl -e shell -MCPAN
install Bundle::DBD::mysql
or
perl -MCPAN -e ‘install Bundle::DBD::mysql’
Log File paths
The first place you should go when trying to debug a problem is the log file for that program. The list of Log Files are as following:
DirectAdmin:
/var/log/directadmin/error.log
/var/log/directadmin/errortaskq.log
/var/log/directadmin/system.log
/var/log/directadmin/security.log
Apache:
/var/log/httpd/error_log
/var/log/httpd/access_log
/var/log/httpd/suexec_log
/var/log/httpd/fpexec_log
/var/log/httpd/domains/domain.com.error.log
/var/log/httpd/domains/domain.com.log
/var/log/messages (generic errors)
Proftpd:
/var/log/proftpd/access.log
/var/log/proftpd/auth.log
/var/log/messages (generic errors)
PureFTPd:
/var/log/pureftpd.log
Dovecot and vm-pop3d:
/var/log/maillog
/var/log/messages
named (bind):
/var/log/messages
exim:
/var/log/exim/mainlog
/var/log/exim/paniclog
/var/log/exim/processlog
/var/log/exim/rejectlog
(on FreeBSD, they have “exim_” in front of the filenames)
mysqld:
RedHat:
/var/lib/mysql/server.hostname.com.err
FreeBSD and Debian:
/usr/local/mysql/data/server.hostname.com.err
crond:
/var/log/cron
To view a log file, run:
less /var/log/filename
Where /var/log/filename is the path of the log you wish to view. If the log is too large you can use the “tail” command:
tail -n 30 /var/log/filename
Where 30 is the number of lines from the end you wish to view.