Enable Cgi-bin for any Folder

November 27, 2006 / General Discussion

CGI (Common Gateway Interface) scripts allow you to run programs or scripts (such as .cgi, .pl, or .py) on your web server to generate dynamic content. By default, many servers only allow CGI scripts in the cgi-bin directory, but you may want to enable CGI for a specific folder within your hosting account.

This guide will show you how to enable CGI in any folder using a .htaccess file.

What is CGI-Bin?

  • cgi-bin is a directory where servers typically store executable CGI scripts.

  • These scripts can perform tasks like form processing, database connections, and generating dynamic web pages.

  • Enabling CGI for other folders gives developers more flexibility in organizing their web applications.

Steps to Enable CGI-Bin for Any Folder

1. Create a .htaccess File

In the folder where you want to enable CGI, create a new file named: “.htaccess

2. Add Execution Permission

Insert the following directive in the .htaccess file:

Options +ExecCGI”

3. Define CGI Handlers

Add the handlers for CGI scripts so that the server knows how to process them:

“AddHandler cgi-script .cgi .pl”

4. (Optional) Update Apache Config

If your setup requires additional configuration, you can update the Apache config file:

Include /etc/httpd/conf/site#/enable-cgi
Options +ExecCGI

5. Restart Apache

For changes to take effect, restart the Apache service:

systemctl restart httpd

By creating a .htaccess file and adding the right directives, you can enable CGI-bin functionality for any folder on your server. This allows more flexibility in running scripts and building dynamic web applications. Always remember to set correct file permissions and follow security best practices while working with CGI.