Perl or cgi script cannot be executed: 500 Internal Server Error

Started by Suhitha, Dec 22, 2025, 12:33 AM

Previous topic - Next topic

Suhitha

Question: Perl or cgi script cannot be executed: 500 Internal Server Error


Applicable to:

  • Plesk for Linux

Symptoms

  • Perl or CGI script located inside of /var/www/vhosts/example.com/httpdocs/cgi-bin/ directory cannot be executed with the error:
500 Internal Server Error
  • Apache error log /var/log/httpd/error_log or domain's error log /var/www/vhosts/system/example.com/logs/error_log contain one of the following errors:

AH02811: script not found or unable to stat: /var/www/vhosts/example.com/cgi-bin
[client 203.0.113.2:55719] End of script output before headers: script.pl
[client 203.0.113.2:55719] End of script output before headers: script.cgi
  • The error below can be found in suexec.log:

  • on CentOS/RHEL-based distributions at: /var/log/httpd/suexec.log

  • on Debian/Ubuntu-based distributions at: /var/log/apache2/suexec.log

uid: (10000/johndoe) gid: (1003/1003) cmd: script.pl
target uid/gid (10000/1003 or 1002) mismatch with directory (10000/1003) or program (0/0)


Cause

Incorrect permissions are set for /var/www/vhosts/example.com/httpdocs/cgi-bin/script.pl file or entire /var/www/vhosts/example.com/httpdocs/cgi-bin/ directory.


Resolution

1.Connect to the server using SSH

2.Find the system user of the subscription example.com:

# plesk db -Ne "select su.login from domains d, hosting h, sys_users su where d.id=h.dom_id and h.sys_user_id=su.id and d.name='example.com';"
johndoe

3.Set correct permissions and ownership for the directory and script with the system user obtained on the previous step:

# chown -R johndoe:psacln /var/www/vhosts/example.com/httpdocs/cgi-bin

# chmod ug+x /var/www/vhosts/example.com/httpdocs/cgi-bin/script.pl

Note:script.pl should be changed to the real cgi or perl script name.

4.Only if issue is not fixed, apply the following to restore default permissions for the domain:

# plesk repair fs example.com

                  As a workaround: Make CGI scripts run out of cgi-bin folder

1.Log into Plesk.

2.Make sure that FastCGI or CGI PHP handler is selected in Domains > example.com > PHP settings.

3.Add the following content both to additional HTTP and HTTPS Apache directives:

SetHandler cgi-script .cgi .pl
4.If the script still does not execute, in addition to the line from step 3, add the following content into additional HTTP and HTTPS Apache directives:

<Directory "/var/www/vhosts/example.com">
Options FollowSymLinks Includes ExecCGI
</Directory>