Ubuntu Apache Configuration and CGI configuration method _linux

Source: Internet
Author: User
Tags chmod apache log fully qualified domain name

In learning python CGI, you need to install Apache under Ubuntu, so today you learn about Apache installation and configuration on Ubuntu11.04.

A. Apache Installation

There are two ways to install information on the Internet: one is to download the tar file from the Apache Web site to your own computer, and the other is to install it directly over the network. I used the second way to be convenient.
Ubuntu offers a powerful apt-get install command, in Terminal input: sudo apt-get install apache2
This makes it easy and quick to install Apache. But here's the inconvenient part where you don't know where Apache is installed.

Two. Start and stop Apache service

The start and stop files for Apache are:/etc/init.d/apache2
Start command: sudo apache2ctl-k start
Stop command: sudo apache2ctl-k stop
Reboot command: sudo apache2ctl-k restart (sudo/etc/init.d/apache2 restart)
Reboot here's the problem: "Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for server when I reboot the service" Name ". I searched the internet and said it was httpd.conf. ServerName Ip:port and listen ip:port are inconsistent, that is, the port is inconsistent. So add "ServerName localhost:80" in the httpd.conf file.
Description under Httpd.conf is an Apache configuration file, in the/etc/apache2 directory, which is described later.
You also need to modify the permissions of the file before modifying the httpd.conf file, otherwise there is no permission to modify it, and the command is: sudo chmod 777/etc/apache2/httpd.conf
By the way, check out the Apache version, using the command: APACHE2CTL-V results will show:
Server version:apache/2.2.17 (Ubuntu)
Server Built:nov 3 2011 02:13:18

Three. Apache configuration file

The generic Apache Release configuration file is:/etc/apache2/httpd.conf, but found that the file is empty, in fact, this is the user's own to configure, later said.
Strictly speaking, the Ubuntu Apache configuration file is/etc/apache2/apache2.conf,apache automatically reads the configuration information of this file at startup, and some other configuration files such as httpd.conf, are included through the include instruction. These include lines can be found in apache2.conf:
Configuration of dynamic modules
Include Mods-enabled/*.load
Include mods-enabled/*.conf
User's own configuration
Include httpd.conf
Configuration of Port sniffing
Include ports.conf
Generic Configuration statement Fragment
Include conf.d/
Configuration directives for virtual hosts
Include sites-enabled/
We can totally put all the settings in apache2.conf or httpd.conf or any configuration file, which is a good habit.

1.Web Document root directory
The most important thing after you install Apache is to know where the root directory of your Web documents is. For Ubuntu, the default is/var/www. So how do we know? Apache2.conf is not described, httpd.conf is also empty, it must be in other configuration files. Later, the search was found in/etc/apache2/sites-enabled/000-default, which had this content:

 Documentroot/var/www
  <directory/>
 Options followsymlinks +execcgi allowoverride
 None
  </ directory>
  <Directory/var/www/>
 Options Indexes followsymlinks multiviews
 allowoverride None Order
 Allow,deny
 allow from
  </Directory>

In this documentroot, the root directory is set to/var/www

2.sites-enabled and Sites-available Directory
A sites-enabled directory was found in the apache2.conf and a sites-available directory under/etc/apache2. What are these two catalogues for? In fact, the sites-available inside is the real configuration file, and the sites-enabled directory is only a few points to the file to the symbolic connection, through the ls-l command to view/etc/apache2/ The 000-default in the sites-enabled is pointed at the/etc/apache2/sites-available/default. This is where the configuration instructions for the virtual host are stored.
Although sites-available is stored in valid content, it does not work, and it can only work if the LN command is linked to the enabled past.

3.mods-enabled and Mods-available Directory
The nature of the two directories and the above mentioned sites-enabled, sites-available consistent, here is the Apachegon function module of the configuration files and links.

4.ports.conf settings
This sets the port used by Apache. If you need to adjust the default port settings, it is recommended that you edit this file. There is also a way to modify the apache2.conf include prots.conf line, in the httpd.conf to set the port you want to use.

Four. CGI Configuration

1. First in the root directory to build a cgi-bin directory, that is,/var/www/cgi-bin/. CGI programs are placed in this Cgi-bin directory and cannot be placed in other directories.
2. Open the/etc/apache2/sites-enabled/000-default and find the following content:

  scriptalias/cgi-bin//usr/lib/cgi-bin/
  <directory "/usr/lib/cgi-bin/" >
  allowoverride None
  Options +execcgi-multiviews +symlinksifownermatch order
  Allow,deny
  allow from all
  </Directory>

Modified to:

  scriptalias/cgi-bin//var/www/cgi-bin/
  <directory "/var/www/cgi-bin" >
  allowoverride None
  Options +execcgi-multiviews +symlinksifownermatch order
  Allow,deny
  allow to all
  AddHandler Cgi-script CGI
  </Directory>

The/usr/lib/cgi-bin/is modified to/var/www/cgi-bin/and added to the AddHandler cgi-script CGI. If the options do not execcgi this item, remember to add it.

3. Restart Apache service: sudo/etc/init.d/apache2 restart

4. If you do not have access to the CGI script, then modify the/etc/apache2/mods-enabled/cigd.load file. Under the original LoadModule cgid_module/usr/lib/apache2/modules/mod_cgid.so, plus:

AddHandler cgi-script. cgi. pl. sh, and restart the Apache service.

5. Modify the permissions of the CGI program. CGI program properties must be set to run (755), while the directory of the HTML files associated with the CGI should be written to the CGI program, the permissions must be set to writable (666). Its command is: sudo chmod 755 ~/simple.cgi

At this point, you should have a smooth access to the CGI program by entering the appropriate URL through the browser, such as http://localhost/cgi-bin/simple.cgi. If not, it's the CGI program itself, and you can find the error by looking at the log. The Apache log is placed under/var/log/apache2.

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.