Open Source

Get started with Apache

If your interested in working with Apache, check out this introduction. Find out how to download, compile, and run Apache.

Taking your first steps into Apache territory is a lot easier than you think. If you are a regular Unix user, you will be well prepared to set up Apache. And the Windows version has the same install procedure as any other Windows application.

The first step is to obtain a copy of Apache. Because it's free there's no reason not to give it a try. The download files are 2.7MB for the Windows version, and a little over 1MB for the Unix version. Yes, it is possible to write slim, high-end applications.

The next step is compiling and installing Apache. Our tips will give you some pointers to make the process smoother, and help you avoid some pitfalls.

Download Apache

Go to the Apache Project Web site and pick the nearest mirror site listed there. Then, click to the download section of that mirror site. For the Windows version, you can also go to Builder Downloads.

You'll see a number of files available for download. On the main Apache Project Web site, all the files are neatly labeled with a description of the contents. Unfortunately, not all of the mirror sites have the same labels. But the file names are usually fairly descriptive, containing the all-important version number. This article works with the standard Unix version (apache_1.3.1.tar.gz) and the new Windows version (apache_1_3_1.exe).

The Windows version is a self-installing binary application, so all you need to do is double-click the Apache file to run the install program. But if you want to take the extra step of compiling the program, you'll probably need to increase environment space to accommodate the Microsoft compiler. This is the first version of Apache to be ported to Windows, and the Apache Project warns that it is not quite as stable as the Unix version.

Installing the Unix version takes a bit of extra work. You'll first need to decompress the files using a command like this:

gzip -d apache_1.3.1.tar.gz

That leaves you with a file called apache_1.3.1.tar. To extract the Apache files from this file you need to use the following:

tar xvf apache_1.3.1.tar

Certain versions of Unix may require you to type tar -xvf, though most modern version of Unix should let you omit the minus sign and use just tar xvf.

This will create a subdirectory called apache_1.3.1. Go to that directory, and then compile Apache.

Compile Apache

There are precompiled versions of Apache available for many Unix platforms. For example, we used Red Hat Linux 5.1 as our Unix test platform and could have installed a prepackaged executable of Apache available from the Red Hat FTP site.

However, most Web builders download the source version of Apache and compile it themselves in order to gain control over the initial configuration. Once you've downloaded the source and extracted it to a directory on your local disk drive, you can change to that new directory and run the Configure program:


This creates a makefile using the default configuration file, src/Configuration.tmpl. If you want to make changes, such as including a module that's normally commented out of Apache, make that change in the Configuration.tmpl file before running Configure.

Now you need to issue two commands, one to build Apache, and the other to install it in the appropriate directories:

make install

This will create an Apache installation in the /usr/local/apache directory, unless you've overridden that default directory during the previous configuration step. For more on customizing Configure, check out the README.configure file that comes with Apache.

Once you've installed the Apache binaries, you're ready to learn how to run Apache.

Increase DOS environment space

Compiling Apache 1.3.1 for Windows requires the Visual C++ compiler from Microsoft. The easiest way to run the compilation scripts is from a command prompt, also known in Windows 95 as a DOS window. And the easiest way to run the Visual C++ command-line tools is by setting a number of environment variables. The Visual C++ set-up program normally puts all the environment settings in a special BAT file called vcvars32.bat. All you have to do is find and run that file (normally in the \Program Files\DevStudio\VC\bin directory) to set up your compilation environment.

On most Windows 95 and 98 installations, you don't usually have enough environment space to store all the compiler settings in vcvars32.bat. When you run the batch file, you'll get a bunch of "Out of environment space" warnings.

Digging back to the ancient days of DOS, the way you increase environment space is by adding something like the following line to your config.sys file:

shell=c:\ /e:1024 /p

You would replace the value 1024 with however many bytes of environment space you need. That's going to be a bit different from machine to machine, depending on what other software and settings you have, so you may want to play around with that value. Unfortunately, DOS requires you to reboot in order for any changes in config.sys to take place, so you're in for a couple reboots before you find the right amount of environment space.

Once you've got the program compiled, you're ready to try running your new Apache server.

Run Apache

Apache for Windows is run just like any other Windows application—click the appropriate shortcut in your Start menu. If you install Apache on Windows NT, you can configure it as an NT Service, which means it will start whenever NT is booted up. The Apache installation program installs a shortcut in your Start menu to let you configure this option.

On Unix, you have two basic options for running Apache. The first is as a standalone server, which is the normal mode of operation. The second is as an inetd server, which is useful if you're experimenting with various Apache configuration settings.

Apache comes preconfigured to run standalone. To double-check this for your copy of Apache, open the httpd.conf file (normally stored in the /usr/local/apache/etc directory). Look for this line:

ServerType standalone

The httpd.conf file is one of Apache's configuration files. The ServerType command is called a directive, an instruction that tells Apache how to execute. The httpd.conf file is one of three Apache configuration files; the others are src.conf and access.conf. For now you just want to make sure the ServerType directive is set to standalone mode.

To actually run Apache, you execute the apachectl script. Assuming you used the default directories when you built Apache, the full command line would be:

/usr/local/apache/sbin/apachectl start

You would use apachectl stop to stop the server, and apachectl restart to restart it. If you want Unix to automatically start Apache whenever the computer boots up, copy the apachectl file into the /etc/rc.d/init.d directory.

While standalone mode is the simplest way to run Apache, there are times when you want to run it as an inetd service.

Configure inetd

In a production Web server, you'd most likely run Apache as a standalone server. But there are times when you might prefer to run it as an inetd server—on a test server with limited resources, for example.

Inetd is the Unix Internet daemon, which listens to the TCP/IP connection on your computer. Whenever inetd sees a call to a specific socket, it launches the program that's configured to handle that socket, such as Telnet (port 23) and SMTP (port 25). When the program finishes, inetd shuts it down.

This has the advantage of reusing limited resources—you don't need to have dozens of different programs running simultaneously, inetd will run them only when needed. On a test server, where you're trying different configuration directives, using inetd means you don't have to manually restart the server each time you alter the configuration.

If you want to try inetd, the first step is to edit the httpd.conf file by changing the ServerType:

ServerType inetd

Now add the following line to the /etc/inetd.conf file, which tells inetd what kind of services it's running and where to find the appropriate executable files:

httpd stream tcp nowait root /usr/local/apache/sbin/httpd -f /usr/local/apache/etc/httpd.conf

This assumes you want to run Apache as the root user. That's not a good idea on a production server, but on a test server it's probably acceptable and definitely simpler.

The last configuration change you need to make is in the /etc/services file, which tells inetd which port to associate with the HTTPD service. We've assumed the default HTTP port, port 80:

httpd   80/tcp   httpd

Next, you need to restart inetd. To do that, you'll need to first figure out its process ID (PID):

ps auxw | grep inetd

This runs the Unix ps command, which generates a list of running processes. That list is then piped to grep, which looks for any string that includes inetd. You'll probably get back two process IDs—one for inetd and one for grep inetd.

Finally, use the kill command to restart the appropriate PID:

kill -HUP pid

Once you get Apache running, it's time to figure out how to configure it.

Editor's Picks