Support / KnowledgeBase

 
Search the KnowledgeBase Search

Troubleshooting CGI/PERL scripts

  • Applies to: (dv) 3.5, (dv) 4.0, (gs)

  • Difficulty: Medium

  • Time needed: 20 minutes

  • Tools needed: SSH

 
  • Applies to: (gs)
    • Difficulty: Medium
    • Time Needed: 20
    • Tools Required: SSH, vi knowledge
  • Applies to: (dv) 4.0
    • Difficulty: Medium
    • Time Needed: 20
    • Tools Required: SSH, vi knowledge
  • Applies to: (dv) 3.5
    • Difficulty: Medium
    • Time Needed: 20
    • Tools Required: SSH, vi knowledge

Overview

This article provides some basic troubleshooting steps to follow for CGI and Perl scripts.

This article is provided as a courtesy. (mt) Media Temple is in no way responsible for troubleshooting your scripts. If, after reviewing these tips, you continue to have problems with your script, we respectfully request that you contact the script's author for support.

Requirements

Most of the troubleshooting steps described here require SSH access to your server. Please see the following article for assistance with SSH:

End of Life Warning

This service has a pending End of Life. Please move to a current service as soon as possible. For more information, please see: (dv) Dedicated-Virtual 4.0: Migration Information.

READ ME FIRST

This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.

READ ME FIRST

This article is provided as a courtesy. Installing, configuring, and troubleshooting third-party applications is outside the scope of support provided by (mt) Media Temple. Please take a moment to review the Statement of Support.

Troubleshooting Tips

Paths

Executable scripts should be in your cgi-bin by default and for security.

Make sure that all modules and include files required by your script have been uploaded to the server and are in the locations called by the script.

Ownership and permissions

Your script, and any files it includes, must be owned by the administrative user for the domain that uses it. If you uploaded the script using FTP, it probably has the correct ownership already. However if, for example, you extracted the script from a backup made on another server, it may have the wrong ownership. Here is the correct ownership and group for your files:

  • serveradmin:serveradmin
  • domainuser:psaserv for the script; domainuser:psacln for included files in your httpdocs directory

Use the chown command to change the permissions on your files. Example:

chown serveradmin:serveradmin myscript.pl
chown domainuser:psaserv myscript.pl

If your script belongs to the wrong owner and you receive a "permission denied" error after running the above command, you will need to open a support request in your AccountCenter.

Your script must be executable. 700 permissions are generally recommended in this case. The domain user, at least, must have execute permissions.

chmod 700 myscript.pl

Your script and any files it uses must NOT be group or world writeable; e.g. 777 permissions are NOT recommended.

Permissions for the cgi-bin MUST be 755. Here is an example for setting permissions to 755 on the (gs) Grid-Service (replace 00000 with your site number and example.com with your domain):

chmod 755 /home/00000/domains/example.com/cgi-bin/

Permissions for the cgi-bin MUST be 755. Here is an example for setting permissions to 755 on the (dv) Dedicated-Virtual Server (replace example.com with your own domain name):

chmod 755 /var/www/vhosts/example.com/cgi-bin/

Make sure CGI and Perl support are enabled for your domain. For detailed instructions, please see: (dv) How do I enable FastCGI?

  1. Log into Plesk.
  2. Click on your Domains.
  3. Click on the specific domain.
  4. Click on Setup.
  5. Under Services, select CGI Support and Perl Support.
  6. Click OK.

TIP:

For a discussion of file permissions and security, please see File Permissions. Stricter permissions (for added security) may be possible for your cgi-bin and your scripts when you are not trying to write to the directory.

Encoding

  1. Use ASCII mode to upload your script from your local computer via FTPFTPFTP. On the other hand, if you're using an FTP connection from another server, use BINARY mode.
  2. Make sure that you create and edit your files using a plain text editor. Use vi, Emacs, or Pico for UNIX; Simple Text for Mac OS X; or Notepad for Windows. Do not use a program like Microsoft Word for editing your scripts.

Script syntax

  1. The first line in all Perl scripts must contain the path to Perl:

    Filename: myscript.pl

    #!/usr/bin/perl
  2. Check for lines in your code that do not end with ; and for routines that are not properly closed. A syntax highlighting editor, such as Notepad++ for Windows, can help you identify syntax errors like these.
  3. Check your script's HTTP headers. In Perl, just below the "shebang" line (#!/usr/bin/perl), add the following line:

    Filename: myscript.pl

    #!/usr/bin/perl
    print "Content-type: text/html\n\n"

Error logging

  1. Add a -w to the first line of your script to enable verbose error logging:

    Filename: myscript.pl

    #!/usr/bin/perl -w
  2. Enable error logs for your server. See Where are the access_log and error_log files for my server? for instructions.
  3. Check your error logs to view any errors that your script generates. It is especially useful to view your error logs live while you execute the script. To do this, first open up a browser window pointing to your script, or open up a second SSH connection to the server. Then, run the following command to view your error log live:
    tail -f /home/00000/logs/error_log
    tail -f /var/www/vhosts/example.com/statistics/logs/error_log

    Now, run the script a few times by using the refresh button in your browser, or by executing the script in your shell:

    ./path/to/script/myscript.pl

    Watch the error log while the script is running to get live error reporting.

Resources


User Comments

No visitor comments posted. Post a comment
Fields marked with an asterisk(*) are required. Comment on this article
Fill out the form below if you would like to comment on this article.
 
 
 

(code is not case-sensitive)
 
Submit
 
 

Continue