Apache configuration to implement cgi

Source: Internet
Author: User

Apache configuration to implement cgi

After installing Apache, You need to modify the apache configuration file:
Nano/etc/httpd/conf/httpd. conf
The configuration file contains
The ScriptAlias/cgi-bin/"/var/www/cgi-bin/" command indicates the default cgi-bin path.
/Var/www/cgi-bin/, which can be seen in the configuration file.
You also need to configure
AddHandler cgi-script. cgi. pl
This configuration is commented out by default, and the cgi suffix is set.
Compile a cgi file with the following content:
#! /Bin/bash
Echo "Content-type: text/html"
Echo ""
Echo "Hello World"

Note that the file must be in UNIX format and can be written by tools such as editpro. Name the file first. cgi and put it in the/var/www/cgi-bin/directory.
Run http: // localhost: 9000/cgi-bin/first. cgi. You can find that there is an error.

Errors are not terrible. The default httpd error log can be viewed in/var/log/httpd/error_log, or you can access/etc/httpd/logs/error_log through the http soft connection.
Open the error_log file and you will see the following error:
[Thu Jan 22 09:06:54 2015] [error] [client 192.168.6.2] (13) Permission denied: exec of '/var/www/cgi-bin/first. cgi' failed
[Thu Jan 22 09:06:54 2015] [error] [client 192.168.6.2] Premature end of script headers: first. cgi
The permission is denied. Set the first. cgi permission to 755.
Chmod 755/var/www/cgi-bin/first. cgi
Run http: // localhost: 9000/cgi-bin/first. cgi again. It is displayed normally.
Similarly, you can edit a perl file or run it in cgi Mode.
#! /Usr/bin/perl
Print "Content-type: text/html \ n ";
Print "Hello, World .";

------------------------------------- I am a split line -------------------------------------

How to enable Apache Rewrite in Ubuntu

Key points after upgrading Apache 14.04 to 2.2 in Ubuntu 2.4

Install the LAMP \ Vsftpd \ Webmin \ phpMyAdmin service and settings in Ubuntu 13.04

Compile and install LAMP in CentOS 5.9 (Apache 2.2.44 + MySQL 5.6.10 + PHP 5.4.12)

Source code for Web server architecture in RedHat 5.4 build the LAMP environment and application PHPWind

Build a WEB Server Linux + Apache + MySQL + PHP in the LAMP source code Environment

This article permanently updates the link address:

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.