Mac OS X Unleashed

Mac OS X Unleashed

By John Ray and William C. Ray

Apache

Apache is an open source project developed by a worldwide group of volunteers known as the Apache group (www.apache.org). It is available on dozens of operating systems including Microsoft Windows. Apache's appeal comes from its flexibility and extensibility. The base server package excels at serving HTML, but to truly exploit the power of Apache, you can install a number of extension modules, including MP3 streaming servers, SSL security, Java Server Pages, and much more. With a total expenditure of $0, you can set up a secure e-commerce server that processes credit cards in real-time and delivers SQL database access.

Apache Versus Personal Web Sharing

If you're looking for the features of the Mac OS 8/9 personal Web server, look elsewhere. The Apache server under Mac OS X does not offer the Finder mode, nor does it offer the SimpleText to HTML conversion of the previous operating system. To place information online, you'll need to create HTML documents. This isn't difficult, but there is no direct upgrade path if you have a collection of SimpleText documents you've been serving off the Internet.

Although Mac OS 8/9 allowed you to use the primary address of your computer as the address for your Web site, the Mac OS X Web sharing system forces a URL based on your username. For example, if your computer's address is http://192.168.0.1 and your username is joeuser, your Web site address would be http://192.168.0.1/~joeuser. This change is due to the multiuser capabilities of Mac OS X. Regardless of how many users are on the system, each can have his or her personal Web site online, simultaneously. To use this feature, users must place their Web pages with the Site folder of their home directory. If you want a single server without usernames, a master Web site can be created by placing documents in the /Library/Webserver/Documents folder.

Regardless of whether Apache is being used for an entire Web site or a few personal pages, users can take advantage of the server's advanced features. A personal page can execute CGI applications, use embedded programming languages, and so on.

Capabilities

This chapter addresses the base features of Apache, but it also includes some interesting add-ons that will make your system into a Web serving powerhouse. There are literally hundreds of Apache modules available for download (http://modules.apache.org/), so we'll try and focus on a select few:

If you're not interested in these features, take a look at the other Apache modules available. It's best to install only the modules you really use. Additional modules can add overhead and potentially weaken the overall security of the server.

Activating Web Sharing

To activate Web sharing (and the Apache Web server), open the System Preferences application (Path: /Applications/System Preferences) and click the Sharing icon. You've seen this screen, shown in Figure 27.1, before.

27fig01.jpg

Figure 27.1 Use the Sharing Preference panel to activate Apache.

Assuming the screen reads Web Sharing Off, click the Start button to start Apache. After a few seconds, the server status should change to Web Sharing On. Your Web pages are now online.

The Sharing button does two things. First, it configures the Mac OS X Server to start Apache when it boots. The /etc/hostconfig file is modified to read WEBSERVER=-YES-:

##
# /etc/hostconfig
##
# This file is maintained by the system control panels
##

# Network configuration
HOSTNAME=-AUTOMATIC-
ROUTER=-AUTOMATIC-

# Services
AFPSERVER=-YES-
APPLETALK=en1
AUTHSERVER=-NO-
AUTOCONFIG=-YES-
AUTODISKMOUNT=-REMOVABLE-
AUTOMOUNT=-YES-
CONFIGSERVER=-NO-
IPFORWARDING=-NO-
MAILSERVER=-NO-
MANAGEMENTSERVER=-NO-
NETBOOTSERVER=-NO-
NISDOMAIN=-NO-
TIMESYNC=-YES-
QTSSERVER=-NO-
SSHSERVER=-YES-
WEBSERVER=-YES-
APPLETALK_HOSTNAME="John Ray's Computer"

Second, it activates the Apache server with no need to reboot. You can start, stop, and restart Apache at any time using the /usr/sbin/apachectl utility. For example, to restart the server, type

$ /usr/sbin/apachectl restart

Table 27.1 documents all of the available apachectl options.

Table 27.1. The apachectl Administration Application Accepts These Commands

Options Functions
start Start the Apache server.
stop Stop the Apache server.
restart Restart Apache. This is equivalent to stopping then starting the server. Current connections are closed.
fullstatus Display a full status of the server. This requires lynx to be installed.
status Display a summary of the server status. The lynx text browser is required.
graceful Restart the server gracefully. Current connections are not dropped.
configtest Check the configuration files for errors. Can be used regardless of the current server state.

There is an interface problem that occurs with Apple's use of the Personal Web Sharing metaphor when it is applied to Apache. Each user has his or her own directory. When Web sharing is turned on for one user, it is activated for everyone.

If the computer is a multiuser system, you cannot be certain that Web sharing is on or off. The only ways to guarantee that your files aren't being displayed on the Web is to manually disable viewing files using Apache configuration directives, or to remove the files from your Site directory.

Share ThisShare This

Informit Network