Why does my script fail to run in the cgi-bin?


There are a number of reasons as to why you cannot get a script to run in your cgi-bin. They can range from an (unexpected) error in the script, to an invalid return, even down to not switching on CGI support. Therefore, please check each of the following points to make sure they true and/or are working first.

Note that mod_perl works differently and does not run via the cgi-bin. If you are using mod_perl and the script is not in the cgi-bin, these instructions do not apply.

  • Your cgi-bin is enabled: Make sure that the cgi-bin you are working with is enabled (the main domains, all subdomains and all web users can have their own cgi-bin with their own settings). mod_perl, Python and PHP are handled differently and are not affected by the CGI setting.
  • Your script has been uploaded using FTP in ASCII mode: Windows, Macintosh and Unix/Linux use different methods to tell the system when a line has ended. This can confuse the server if an unexpected character is in the shebang line (see here for more information).
  • Your program runs sucessfully: Double check to make sure that the program runs successfully using the command-line on either your system or (preferably) our system using SSH access (contact our Support Team to switch on SSH access if need it).
  • The first line(s) returned specifies the Content-Type: As the program is a script, Apache doesn't know what the content returned will be, therefore you must specifically state this by making sure that the first line returned specifies the Content-Type header (i.e. echo 'Content-Type: text/html\n\n'). Again, this should be checked on the command-line.

Our servers do not make use of the xhack setting available with Apache whereby the script must be set with the executable-bit set (i.e. the system/server it told that this is a file which can be run). The script can have a mode of 0640 or 0750 (-rw-r--r-- or -rwx-r-xr-x), although 0640 is preferred unless you intend the program to run outside of the web site as well.

If the script still cannot run, then there is a problem with the setup of the file on the system. The Plesk Control Panel makes use of the suEXEC security system, which checks the settings of the script along with the files and/or directories around it, making sure that the file is safe to run.

This is done using a series of twenty tests, although not all are related directly to the file itself. Some cover the server and the suEXEC system itself.

Below are the tests which the file (and surrounding directories) must pass in order for the script to be run. Please also check these to make sure they all pass so the script can run:

  • Is the directory NOT writable by anyone else? The cgi-bin directories should only be able to be written to by the domain's (or subdomain's/webuser's) user. Group and World writable permissions are NOT allowed and prevents others from changing the directory and/or script. If not sure, the directory should not have a mode not greater than 0755 (although 0750 is normal).
  • Is the target script NOT writable by anyone else? Again, this is used make sure the script can't be altered by anyone else. A mode of no greater than 0644 or 0755 is allowed (although 0640 and 0750 are usually best).
  • Is the target script NOT set to setuid/setgid? As script shouldn't be set to change it's privileges (although this doesn't work with an interpreted script). Setting the file to modes in the last set will clear an setuid/setgid permissions.
  • Is the target script the same user and group as the domain's user and group? If you just upload the script as normal using FTP, the file will be given your username and the group of 'psacln'. If it is set to anything else, the script will not be allowed to run. This prevents anyone else installing scripts into your cgi-bin by accident.

All other tests cover the system. If after satisfying all these conditions, the script still cannot run, contact the Support Team giving details of which script and any error messages you are getting (either from the browser or the command line). Further details about the suEXEC mechanism can be found here.

Also, if you are unsure about any of the settings or steps and do not want to do anything you are not comfortable with, also contact the Support Team who will assist you.

  • 103 utilizatori au considerat informația utilă
Răspunsul a fost util?

Articole similare

Where is the perl interpreter (or program) located?

If you are running a script via the command line (and you have SSH access enabled), or you are...

Can I install programs such as phpBB and Mambo?

All our accounts provide access to a wide-range of languages and utilities Using these, you are...

How do I enable register_globals (PHP)?

Since version 4.2.0 of PHP, the register_globals setting has been disabled by default on all new...

What is my Web Root or Document Root?

Some scripts/programs may ask you for your web root (or document root) when performing the...

How do I create a cron job?

A cron job (run by the cron daemon, or cron service) is a request for the server to run a...