Configuring Apache to support the operation of CGI processes

Source: Internet
Author: User

Configure Apache to run CGI programs can be divided into two cases, one is the Scriptalias directory of CGI, and the second is scriptalias outside the directory of CGI.

CGI for the Scriptalias directory

The SCRIPTALIAS directive allows Apache to execute CGI programs in a specific directory. When a client requests a resource in this particular directory, Apache assumes that the file is a CGI program and tries to run it.
Scriptalias directive shape such as:

    1. scriptalias/cgi-bin//usr/local/apache/cgi-bin/
CGI outside the Scriptalias directory

For security reasons, CGI programs are typically limited to directories specified by Scriptalias, so administrators can strictly control who can use CGI programs. However, if appropriate security method measures are taken, there is no reason not to allow CGI programs in other directories to run. For example, you might want users to hold pages in the host directory specified by Userdir, and they have their own CGI programs, but have no access to the Cgi-bin directory, which creates the need to run CGI programs in other directories.
1, using the options to explicitly allow the execution of CGI
You can use the options directive to explicitly allow the execution of CGI in a particular directory in the primary server configuration file:

  1. <Directory/usr/local/apache/htdocs/somedir>
  2. Options +execcgi
  3. </Directory>

The above instructions enable Apache to allow CGI file execution. Also, you must tell the server which files are CGI files. The following AddHandler instruction tells the server that all files with CGI or PL suffixes are CGI programs:

    1. addhandler cgi-script CGI PL


. htaccess files are a way to configure a directory. When Apache provides a resource, it looks for the. htaccess file in the directory where the resource resides, and if so, makes the instruction in it effective. The allowoverride directive determines whether the. htaccess file is valid, specifies which directives can appear in it, or is not allowed at all. To do this, you need to configure this in the primary server configuration:

    1. AllowOverride Options

In the. htaccess file, this configuration is required:

    1. Options +execcgi

To enable Apache to allow the execution of CGI programs in this directory.
Finally, you can write a CGI program test, such as:

  1. #!/usr/bin/perl
  2. print "content-type:text/html\n\n";
  3. Print "Hello, world.";

Configuring Apache to support the operation of CGI processes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.