Home / Documents / Tutorials / Apache
 
 
 
 
 
 
 
 
 
 
 
 
 DOCUMENTS 
 TUTORIALS 

Configuring Apache

Keith Parkansky
http://www.execpc.com/~keithp

Last revised: April 28, 2002

Basic setup

Apache can respond to browser requests from machines on your local network (i.e. an "Intranet" Web server) or from the Internet. The installation of the Solaris OS installed and set up most of the necessary Apache files. As a result, if you want to use your system as a Web server you only need to modify one file.

The file we need to edit is Apache's primary configuration file, httpd.conf which is stored in the /etc/apache directory. Actually, you have to create this file using an example file as a template.

  1. Use the text editor to Open the following file:
      /etc/apache/httpd.conf-example
    
      ServerAdmin you@your.address
    
  2. Substitute your e-mail address for the you@your.address
  3. A little farther down in the file you'll see the following line:
      #ServerName new.host.name
    
  4. Remove the # character from the beginning of the line
  5. Substitute new.host.name with your domain (www.yourdomain.com)
  6. Save the file as follows:
    • Click on File and select Save As
    • The /etc directory may still be the default save location so use the "Folders" list to navigate to the /etc/apache directory
    • Enter the file name httpd.conf (i.e. without the '-example') in the "file name" field
    • Click on OK
    • Exit the editor

With the existance of the httpd.conf file the Apache server will start automatically whenever you boot your system (it's the "httpd started" you'll see on screen while the system is booting). For now you can start it manually by opening a "This Host" window and entering the following command:

/usr/apache/bin/apachectl start

You should now be able to access the default Apache home page by using Netscape on the same machine by entering the following URL:

  http://localhost

You should also be able to access it from a different machine on the same local network using the machine's IP address. Example:

  http://192.168.10.20

Naturally, you'll need to have your ISP edit your "A" record on their DNS servers to point to your system's IP address in order for the system to act as a Web server for your domain (i.e. one that the public can access by entering your domain name for a URL). You'll also have to modify httpd.conf accordingly.

There are several key file locations (directories) you should be aware of:

  • "ServerRoot" - /var/apache
  • "DocumentRoot" (HTML files) - /var/apache/htdocs
  • CGI-BIN (script) files - /var/apache/cgi-bin
  • Log files - /var/apache/logs
  • Configuration files - /etc/apache
  • Executable file - /usr/apache/bin

Virtual Hosts

If you want to host several Web sites you don't need several separate servers. Apache allows you to configure "virtual hosts" that appear as multiple Web servers to those who visit the sites.

In addition to setting up multiple virtual Web servers, the virtual host configuration statements also allow you to customize the behavior of each individual virtual server. This includes specifying file locations for DocumentRoot and CGI-BIN files.

The virtual host configuration statements are also in the httpd.conf file. They basically duplicate the configuration statements found earlier in the file enclosed in a set of VirtualHost directives.

  <VirtualHost 172.18.254.38>
      ServerName www.my2nddomain.com
      ServerAdmin you@your-real-email-address.com
      ScriptAlias /cgi-bin/ /home/httpd/cgi-bin/my2nddomain/
      DocumentRoot /home/httpd/html/my2nddomain/
      <Directory /home/httpd/html/my2nddomain>
        AddHandler server-parsed .shtml
        AddType text/html .shtml
        Options +Includes
      </Directory>
      ErrorLog logs/my2nddomain-error_log
      CustomLog logs/my2nddomain-access_log common
  </VirtualHost>

Note that it's helpful to create a separate subdirectories in the DocumentRoot directory and the CGI-BIN directory for each additional site you will be hosting. This allows you to keep their pages and scripts separate. Giving the access and error logs site-specific names (or storing them in site-specific subdirectories) is also helpful.

The <Directory /home/httpd/html/> directive (and it's associated closing statement) are only necessary if you want to change any of the default values. The "default" values are those which are inherited from the main site's configuration values. In other words, if you were to use +Includes in the main site's options configuration it would not be necessary here.

If Includes is not enabled in the main site's configuration and you want to enable it you have to explicitly state so using the above commands for each virtual site. Enabling Includes allows you to use SSI directives (like include and exec ) on your Web pages.

Note that the above Directory directive references the DocumentRoot directory for the virtual site which, in this case, means that only the HTML document files stored in this directory are the ones that will be parsed to see if they contain SSI directives (provided the files have a .shtml extension).

It's important to remember that each Web site you host must have it's own static, public IP address. This is because the DNS record for the domain must point to a specific IP address. As a result, you'll have to assign multiple IP addresses to the system's single network interface.

Copyright © 2002 by Keith Parkansky. All rights reserved.


Thanks to Keith Parkansky for his contribution and maintenance of the article.
Original text: http://www.execpc.com/~keithp/bdlogsol.htm

Logo
Top
Last modified: 2003-03-15