# Troubleshooting CGI scripts

> Fix CGI scripts that will not run by checking permissions, the shebang line, command-line output and error logs.

Source: https://helpcenter.ruachost.com/developers/web-servers/troubleshooting-cgi-scripts/

CGI (Common Gateway Interface) scripts allow web servers to run external programs, often written in Perl, Python, or other languages. On **ruachost.com**, CGI scripts run under your user ID, so proper configuration is essential for them to work correctly.

## Common Issues and Fixes

### Step 1: Verify Script File Permissions

- CGI scripts must have **execute permissions**.
- Set permissions using:

  ```bash
  chmod 755 script.cgi
  ```
- Incorrect permissions are one of the most common causes of failure.

### Step 2: Verify the Shebang Line

- The first line of your script must specify the correct interpreter.
- Example for Perl:

  ```bash
  #!/usr/bin/perl
  ```
- If the shebang is missing or incorrect, Apache won’t know how to run the file.

### Step 3: Run the Script from the Command Line

- Debugging through a browser often hides useful error messages.
- Log in via SSH and run:

  ```bash
  ./script.cgi
  ```
- This will display syntax errors or missing module issues directly.

### Step 4: Check Web Server Error Logs

- Errors such as **500 Internal Server Error** or **403 Forbidden** are logged.
- Access logs via **cPanel → Metrics → Errors** or SSH:

  ```bash
  tail -100 /var/log/apache2/error.log
  ```
- Review logs for permission issues, syntax errors, or misconfigurations.

### Step 5: Contact Support

- If all else fails, open a [Support Ticket.](https://dashboard.ruachost.com/submitticket.php?step=2&deptid=2)
- Provide details: script name, error messages, and steps you’ve tried.
- The Ruachost support team can assist further.

> **Important Notes:**
- Always upload scripts in **ASCII mode** if using FTP.
- Ensure scripts are placed in the correct directory (e.g., `/cgi-bin`).
- Avoid Windows line endings (`\r\n`) — use Unix line endings (`\n`).
- Test scripts incrementally to isolate issues.
