General CGI FAQ

Frequently asked questions about installing and troubleshooting CGI scripts.

Q1: What does chmod xxx mean? What is chmod?

Short Answer

chmod is a Unix command that changes file permissions, allowing users and groups to read, write, and/or execute files.

Long Answer

For CGI scripts, the web server's user ID (uid) must have permission to execute Perl scripts and read/write data files. Different chmod values are used for different purposes:

Executable Scripts (755)

Perl scripts in the cgi-bin must be executable by the web server:

chmod 755 filename.pl

This allows everyone to read and execute the file, but only you can write to it.

Writable Files (777)

Files that are automatically updated by scripts must be writable and readable by all:

chmod 777 filename.html
chmod 777 filename.txt

This allows everyone to read and write to your files.

Understanding Permission Numbers
Number Permission Meaning
4ReadCan view file contents
2WriteCan modify file
1ExecuteCan run as program
7rwxRead + Write + Execute (4+2+1)
5r-xRead + Execute (4+1)

The three digits represent: Owner | Group | Others

  • 755 = Owner: rwx, Group: r-x, Others: r-x
  • 777 = Owner: rwx, Group: rwx, Others: rwx
  • 644 = Owner: rw-, Group: r--, Others: r--
More Information

For detailed documentation, type at the Unix prompt:

man chmod

Q2: What are the server requirements?

To run our CGI scripts, your server needs:

RequirementDetails
PerlVersion 5.x or higher
CGI SupportServer must execute .pl or .cgi files
cgi-bin DirectoryA directory configured for CGI execution
File PermissionsAbility to set 755 permissions

Optional requirements depending on script:

  • Sendmail: For scripts that send email
  • SSI Support: For Server Side Includes
  • Write Access: For scripts that save data

Q3: How do I upload scripts to my server?

Follow these steps to upload CGI scripts:

  1. Connect via FTP using a client like FileZilla
  2. Set transfer mode to ASCII (not binary) for .pl files
  3. Navigate to your cgi-bin directory
  4. Upload the script file
  5. Set permissions to 755:
    • In your FTP client: Right-click > Permissions
    • Or via SSH: chmod 755 script.pl
Important: Always upload Perl scripts in ASCII mode to prevent line ending issues between Windows and Unix systems.

Q4: What permissions do I need?

Different file types require different permissions:

File TypePermissionCommand
CGI Scripts (.pl, .cgi)755chmod 755 script.pl
Data Files666chmod 666 data.txt
Directories755chmod 755 dirname
Configuration Files644chmod 644 config.txt

Permission numbers explained:

  • 7 = Read + Write + Execute
  • 6 = Read + Write
  • 5 = Read + Execute
  • 4 = Read only

Q5: Why do I get a 500 Internal Server Error?

A 500 error usually indicates one of these problems:

  1. Wrong permissions: Set script to 755
  2. Wrong Perl path: Check the first line of the script:
    #!/usr/bin/perl
  3. Syntax error: Test the script from command line:
    perl -c script.pl
  4. Line ending issues: Upload in ASCII mode, not binary
  5. Missing modules: Check if required Perl modules are installed
Tip: Check your server's error log for the specific error message.

Q6: How do I find the correct Perl path?

To find your server's Perl path:

  1. Via SSH/Telnet:
    which perl
  2. Ask your hosting provider

Common Perl paths:

  • /usr/bin/perl - Most common
  • /usr/local/bin/perl - Alternative location
  • /bin/perl - Some systems

Update the first line of your script with the correct path:

#!/usr/bin/perl

Q7: How do I test if a script is working?

Several ways to test your CGI scripts:

  1. Direct browser access:
    http://yourdomain.com/cgi-bin/script.pl
  2. Command line test:
    perl -c script.pl  # Check syntax
    perl script.pl      # Run directly
  3. Check error logs: Look at your server's error_log file
  4. Add debugging:
    use CGI::Carp qw(fatalsToBrowser);
Note: Remove fatalsToBrowser in production for security.

Q8: How do I set up Server Side Includes?

To enable Server Side Includes:

  1. Name your files with .shtml extension
  2. Or add to .htaccess:
    AddType text/html .html
    AddHandler server-parsed .html

SSI syntax examples:

<!--#include virtual="/header.html"-->
<!--#exec cgi="/cgi-bin/script.pl"-->
<!--#echo var="DATE_LOCAL"-->
Note: Not all hosts enable SSI by default. Contact your hosting provider if SSI isn't working.

Q9: Can I modify the scripts?

Yes! All scripts in this archive are free to modify. You may:

  • Customize the output and appearance
  • Add new features
  • Integrate with other scripts
  • Use for personal or commercial projects

We only ask that you:

  • Keep the author credits in the script comments
  • Don't redistribute modified versions as your own work
  • Share improvements with the community if possible
Tip: Make a backup of the original script before modifying, so you can restore it if needed.

Q10: Where can I get help with scripts?

Several resources are available for help:

  1. Script-specific FAQ pages - Check the FAQ for each script
  2. Readme files - Detailed installation instructions
  3. Examples - Working demonstrations of each script
  4. General FAQ - Common CGI troubleshooting

External resources:

  • Your web hosting provider's support team
  • Perl documentation at perldoc.perl.org
  • Stack Overflow for programming questions

Q11: How do I check for script updates?

To check for updates:

  1. Check the script's page on this site for the current version number
  2. Compare with your version: Look at the version number in your script's header comments
  3. Download the latest version if available

When updating:

  • Back up your current configuration settings
  • Upload the new script
  • Re-apply your configuration changes
  • Test thoroughly before going live
Tip: Keep notes of any customizations you've made to scripts so you can reapply them after updates.

Q12: How do I keep my scripts secure?

Follow these security best practices:

  1. Use latest versions: Keep scripts updated with security patches
  2. Proper permissions:
    • Scripts: 755 (not 777)
    • Data files: 644 or 666 only if needed
  3. Configure referers: Limit which domains can access your scripts
  4. Validate input: Don't trust user-submitted data
  5. Protect data files: Store them outside the web root if possible
  6. Use .htaccess: Restrict access to sensitive directories
Warning: Never set permissions to 777. This is a major security risk.
Back to FAQ