Section 11.4. Web Services

11.4. Web Services

Mac OS X comes with Apache, an open source web server responsible for more than half of all the Internet's web sites. [*] At its most basic level, Apache runs as a daemon named httpd that supports the Hypertext Transfer Protocol (HTTP); it listens to web surfers' requests (on port 80, by default) and replies with response codes and web pages.

[*] Netcraft tracks the changing popularity levels of Apache and other web servers on its web site at http://www. netcraft .com/survey/.

11.4.1. Apache Configuration

Apache's configuration information lies in the /etc/httpd directory, mainly in the file /etc/httpd/httpd.conf . This file sets up options through lists of directives and values, often mapped to filesystem directories and other criteria. Many of its options are highly specific to Mac OS X, so that Apache works "out of the box"; turning on web services with a single click in the Sharing pane (see the earlier section "Running Services Through the Sharing Pane") launches a full-featured web server on a fresh Mac OS X installation. Here are some highlights (and variances from the defaults that are in a platform-independent Apache installation):

  • The DirectoryRoot directive defines the location of the server's default location for HTML files and other web-servable documentsin other words, what you'd see if you pointed your web browser to http://localhost/. Mac OS X sets this directive to /Library/WebServer/Documents/ .

  • Following the usual Unix tradition, Mac OS X Apache lets a host's individual users build personal web sites in their own home folders, accessible by pointing a web browser to http:// network_address /~ username . To find your network address, go to the Sharing preferences panel, as shown in Figure 11-1. Most Unix systems define users' personal document roots at ~ username /public_html ; Mac OS X Apache sets it to ~ username /Sites .

  • An Include directive at the bottom of the file reads in several additional Apache configuration files located in /etc/httpd/users/ . One username .conf file exists for every user created through the Accounts pane. Each one defines Apache options and directives for serving that user 's /Sites folder over the Web, thus allowing an administrator to set different options on different users' personal web sites.

  • Apache keeps two log files, access_log and error_log , in the /var/log/httpd/ directory. The access_log file keeps a record of the files served (graphics, web pages, etc.) and to whom the files were served by displaying the IP address of the machine that accessed the server. The error_log file reports any errors, such as from people who have attempted to access a file on the web server that doesn't exist. If anything is ever wrong with your web pages or web serving, this file is the first place to check for problems.

11.4.2. Apache Modules

Apache modules are code libraries that extend Apache's abilities beyond fundamental HTTP serving. Apache lets you install modules two ways: static modules are "baked in" to the httpd program at compile time, while dynamic modules are separate files that httpd can load and include into its functionality without any recompiling needed.

Mac OS X's Apache setup uses the latter of these strategies. To enable an existing but inactive module, simply locate the LoadModule and AddModule directives within /etc/httpd/httpd.conf and remove the # characters from the start of both lines, turning the lines from comments into actual directives. To disable an active module, just insert a # at the start of both lines, commenting them out; then restart the web server.

To install new modules, place their .so files (compiling them first, if necessary) into the /usr/libexec/httpd/ directory, and then add new LoadModule and AddModule lines to /etc/httpd/httpd.conf .



MAC OS X Tiger in a Nutshell
Mac OS X Tiger in a Nutshell: A Desktop Quick Reference (In a Nutshell (OReilly))
ISBN: 0596009437
EAN: 2147483647
Year: 2003
Pages: 130

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net