How to Enable CGI Scripts in cPanel
CGI (Common Gateway Interface) scripts allow you to create dynamic and interactive websites by running scripts written in languages such as Perl, Python, or C. If you’re hosting your website on a Linux-based server, cPanel makes it easy to enable and manage CGI scripts.
In this guide, we’ll walk you through how to enable CGI scripts in cPanel, best practices, and common troubleshooting tips.
What Are CGI Scripts?
CGI scripts are programs that run on the server to generate dynamic content for web pages. They are often used for:
-
Contact forms
-
Guestbooks
-
Counters and trackers
-
File upload/download tools
How to Enable CGI Scripts in cPanel
Step 1: Log in to cPanel
Visit yourdomain.com/cpanel
and log in using your hosting account credentials.
Step 2: Go to Software Section
In the Software section of your cPanel dashboard, look for Optimize Website or CGI Center (depending on your cPanel theme).
Step 3: Enable CGI Support
-
Navigate to CGI Center (if available).
-
If CGI is not enabled by default, you may need to adjust Apache handlers.
-
Go to Advanced → Apache Handlers.
-
Add a handler for
.cgi
and.pl
extensions using:
-
Step 4: Upload Your CGI Scripts
-
Place your CGI scripts in the
cgi-bin
directory inside your public_html folder. -
Ensure the script files have the correct permissions:
-
Use a shebang line at the top of your script (example for Perl):
Step 5: Test Your Script
Access the script in your browser:
If properly configured, your script will execute instead of showing raw code.
Best Practices for CGI Scripts
-
Always set correct file permissions (
755
). -
Keep scripts inside
cgi-bin
for security and organization. -
Validate all inputs to prevent exploits.
-
Use HTTPS (with a free Let’s Encrypt SSL from Sternhost) to secure form submissions.
Troubleshooting CGI Errors
-
500 Internal Server Error – Check file permissions and shebang path.
-
Script Download Instead of Execution – Apache handler for
.cgi
or.pl
might be missing. -
Permission Denied – Ensure ownership and permissions are correctly set.
Conclusion
Enabling CGI scripts in cPanel is straightforward and allows you to create dynamic, interactive websites. With just a few adjustments in your cPanel settings and correct script permissions, you can deploy powerful server-side scripts in minutes.
At Sternhost, we provide fast, reliable hosting with full CGI support so you can focus on building feature-rich websites without worrying about server setup.