- Knowledgebase Home
- » Browse by Service
- » (dv) Dedicated-Virtual Server
- » (dv) 3.0
- » Server Settings and Optimization
Running scripts outside of the cgi-bin
This article describes how to execute scripts outside of your cgi-bin using an .htaccess file.
Results
You will be able to execute CGI scripts outside of your cgi-bin. Enabling this in a web-accessible directory is slightly more insecure than limiting script execution to the cgi-bin, because if a malicious script is ever uploaded to your server, it will be more easily able to be executed.
Instructions
Add the following lines to your .htaccess file:
Filename: .htaccess
AddHandler cgi-script .cgi .pl
Options +ExecCGI
Then, upload the .htaccess file to the directory in which you want to enable CGI script execution, via FTP. For more information on creating and uploading .htaccess files, please click on the link.
NOTE:
You can add any file extension to the "AddHandler" line in your .htaccess file. The example is for CGI and Perl scripts.
If you are using this directive in your existing cgi-bin directory, the above line alone will also work.
Enable server-wide execution
You can enable server-wide processing of cgi scripts. Note that this will make your server more vulnerable if you get hacked. To do this, uncomment the cgi-script AddHandler directive in the main Apache configuration file, /etc/httpd/conf/httpd.conf.
- Log into your server as root or a sudo user via SSH.
-
Open the httpd.conf file for editing:
vi /etc/httpd/conf/httpd.confvi tip: Press "i" to enter "insert mode" so you can type and copy/paste. Use the arrow keys to navigate. Press "Esc" to exit "insert mode" when you are done modifying the file. Type ":wq" to save and quit.
-
Locate this line:
httpd.conf
#AddHandler cgi-script .cgi
Remove the # so that it looks like this:
httpd.confAddHandler cgi-script .cgi
-
Restart Apache with the following command:
/etc/rc.d/init.d/httpd restart
That's it. You should now be able to execute cgi scripts anywhere on the server.
vhost.conf
You can also modify your vhost.conf file to allow execution of cgi scripts on a per-domain basis. This allows execution of cgi scripts in the httpdocs directory for a particular domain.
- Log into your server as root or a sudo user via SSH.
-
Create or edit your vhost.conf file:
vi /var/www/example.com/conf/vhost.conf/vi tip: Press "i" to enter "insert mode" so you can type and copy/paste. Use the arrow keys to navigate. Press "Esc" to exit "insert mode" when you are done modifying the file. Type ":wq" to save and quit.
-
Add the following lines to the file and save your changes:
vhost.conf
<Directory /var/www/vhosts/example.com/httpdocs> <Files ~ (\.cgi$)> SetHandler cgi-script Options ExecCGI allow from all </Files> </Directory>
- Run the following command to reload your Apache configuration files: /usr/local/psa/admin/sbin/websrvmng -av
For more information about your vhost.conf file in general, and this specific issue, see: