What does CGI mean?
Common Gateway Interface is abbreviated to CGI. This is a standard way for web servers to interface executable scripts with end users.
Those executable scripts or programs execute by this way and generate web pages dynamically.
CGI scripts are usually written in scripting language, but can be written in any programming language.
Most of the hosts does not allow to execute those scripts outside the CGI-BIN folder on the public folder.
Some hosts already allowed this feature via the main Apache configuration file. Here I’m explaining the steps to add some extra lines on the .htaccess file to overwrite the main configuration, if it’s disabled. This is really simple. You can simply do this from the cPanel.
Instructions
If you have shell access to your cPanel account, you can simply create a .htaccess file under the home directory or the public folder.
Step 1 : Log into cPanel.
Step 2 : Create a .htaccess file under the home directory. If you prefer shell, you can use vi command.
# vi .htaccess
Step 3 : Add the following code in that .htaccess file.
AddHandler cgi-script .cgi .pl
Options +ExecCGI
That’s it!! Please try to execute the code from your browser now. It’ll work!!
Important things!
> You can add any file extension to the AddHandler line in your .htaccess file. Here the .pl stands for the per scripts and .cgi for CGI scripts.
> To enable server-wide, please make sure that those extensions are appended with AddHandler directive on the main Apache configuration file.
> File permission for .htaccess is 644.
> File permission for scripts are 755.
Do you want to test this?
Here I’m attaching a sample perl CGI script.
Please try to add this code and execute this from the web browser.
#!/usr/bin/perl
# hello.pl -- my first perl script CryBit.com!
print "Content-type: text/html\n\n";
print "Hello, world!\n";
Please check this and let me know if you need any help!
1) Where does the .htaccess file live?
2) What are the permissions associated with the .htaccess file?
3) Do I need to specify the suffix for the executable file or can I run any executable file?
Hi Frank,
I updated the blog post with those details 🙂
.htaccess in home or document root directory.
Permission 644.
You need to specify the extension.
Hi Arunlal Ashok, many thanks, this simple explanation resolved my problem with same days ….
best regards
You’re most welcome, Black!
yes the above documentation is helpful, in Windows if we want to run perl programs in alias ie., outside cgi-gin, By editing .htaccess with the above two lines, it worked for me. amazing, Thank you
You are most welcome, Manjunath!
To the below path i.e
/home/chandana/LINUX_BASED_DIAG/modules/ce/src/hal/diag/cards/csc01/code/
i have to create a file from web page.
what is the shell script written for this ?
Hello,
“please make sure that those extensions are appended with AddHandler directive on the main Apache configuration file” ????
what does the above mean??
what do you mean … “AddHandler directive” into the “main Apache configuration file”??
do you mean like the below example
# ——————————
# main Apache configuration file
home/xxx/pubic_html
# AddHandler directive (is that the same code thats in the .htaccess file?)
AddHandler cgi-script .cgi .pl
Options +ExecCGI
# ——————————