Symptoms
When attempting to access or execute a Perl script on your cPanel server, you may find that the script produces a 500 error in your browser. The 500 error may actually explicitly say that it is a 500 error, or it may just produce a blank white page depending on the way that the script was accessed and how the server is configured.
You may also find an error simliar to the following in the Apache error log:
/etc/apache2/logs/error_log
[Fri Jul 16 22:53:31.528787 2021] [cgi:error] [pid 1288] [client xxx.xxx.xxx.xxx:52846] AH01215: suexec policy violation: see suexec log for more details: /home/cpanelusername/public_html/cgi-bin/index.cgi
[Fri Jul 16 22:53:31.528838 2021] [cgi:error] [pid 1288] [client xxx.xxx.xxx.xxx:52846] End of script output before headers: index.cgi
When checking the suexec log as prompted in the above error message you may find an error similar to the following:
/etc/apache2/logs/suexec_log
[2021-07-16 22:45:37]: (2)No such file or directory: exec failed (index.cgi)
[2021-07-16 22:48:53]: uid: (1001/cpanelusername) gid: (1003/cpanelusername) cmd: index.cgi
The page may also display an error similar to the following:
lscgid: execve():/home/username/public_html/file.cgi: No such file or directory
Description
This issue typically occurs due to corruption within the script.
The corruption may be due to having Windows style line endings, or from other various issues such as having binary data within the file somewhere.
Resolution
- Use the file command to check and see what kind of file your script is detected as.
The following example shows what a perl script should be detected as:# file /home/cpanelusername/public_html/cgi-bin/index.cgi
/home/cpanelusername/public_html/cgi-bin/index.cgi: Perl script, ASCII text executable
The following example shows that the file has binary data within it, which will cause the script to fail:# file /home/cpanelusername/public_html/index.cgi
/home/cpanelusername/public_html/index.cgi: data
The following example shows that the file has Windows line endings which will cause the script to fail:# file /home/cpanelusername/public_html/cgi-bin/index.cgi
This can be confirmed with the
/home/cpanelusername/public_html/cgi-bin/index.cgi: Perl script, ASCII text executable, with CRLF line terminatorscat -e
command; note the^M$
terminators which are used by Windows systems:# cat -e index.cgi
#!/usr/bin/perl^M$
print "Content-type: text/html\n\n";^M$
print "Hello, World."; - If your file has problematic characters in it, install the dos2unix utility:
yum install dos2unix
- Run the utility on the file.
If the file was detected as a binary file, the dos2unix utility will helpfully tell you which line has the binary symbol that is causing the issue:# dos2unix /home/cpanelusername/public_html/cgi-bin/index.cgi
You would then need to open the file with a text editor and remove any binary symbols that may be present. Otherwise you may need to restore the script from a backup if the file is too corrupted.
dos2unix: Binary symbol found at line 191
dos2unix: Skipping binary file /home/cpanelusername/public_html/cgi-bin/index.cgi
Otherwise, the dos2unix utility will automatically fix the Windows line endings for you if they were present. - Now you should be able to execute the Perl script successfully unless there are other unrelated errors occurring.