This guide explains how to enable and verify ExecCGI using an .htaccess file on a cPanel hosting account.
1. Choose Where Your CGI Scripts Will Live
Most cPanel hosting providers expect CGI scripts to be placed in the following directory:
/public_html/cgi-bin/
This is the safest and most compatible location because many shared hosting environments allow CGI execution only inside the cgi-bin directory.
2. Create or Edit the .htaccess File
Follow these steps in cPanel:
2. Navigate to the relevant directory (usually public_html).
3. Create or edit the .htaccess file. If the file does not exist, create a new file named .htaccess.
Add the Following Lines to .htaccess
Options +ExecCGIAddHandler cgi-script .cgi .pl .py
What These Directives Do:
Options +ExecCGI enables CGI execution, provided the server allows .htaccess overrides.
AddHandler cgi-script Instructs the web server to treat .cgi, .pl, and .py files as CGI scripts.
3. Upload or Create a CGI Test Script
Create a file named: test.cgi
Location: public_html/cgi-bin/
Paste the following content into the file:#!/bin/sh echo "Content-Type: text/plain" echo "" echo "ExecCGI is ENABLED and working."
4. Set the Correct Permissions (Critical Step)
CGI scripts must be executable; otherwise, they will not run.
1. Right-click on test.cgi file
2. Select Change Permissions and Set permissions to:755
3. Recommended permissions:
test.cgi: 755
cgi-bin directory: 755
5. Run the Test in Your Browser
Open the following URL in your browser: https://yourdomain.com/cgi-bin/test.cgi
If ExecCGI is enabled and working correctly, you should see:
Expected Result: ExecCGI is ENABLED and working
Conclusion:
If the test script runs successfully, ExecCGI is properly enabled on your hosting account. If you encounter permission errors or 403 errors, it usually means CGI execution is restricted at the server level.
