Now that you’ve configured Apache with the basic information it needs to start successfully, it’s time to find out how to actually start it. Starting Apache on UnixTo start Apache, it’s usually sufficient to invoke it without additional parameters, for example:
Apache immediately goes into the background on startup, so it’s not necessary to explicitly force the program to the background using the & option on a Unix system. Depending on what the server has been configured with, it may display several informative messages, or it may simply start without displaying a single message. If you don’t want to use the default configuration file, you need to specify the configuration file, which you can do with the -f command line option:
Alternatively, Apache comes with the very convenient apachectl script, which can be used to start the server with this:
apachectl allows you to do many things, depending on what arguments you pass, and it also provides help for a list of other options. The only other mode of interest right now is startssl, which defines the symbol SSL. If you have a configuration that’s set up to conditionally start using SSL, then this is a convenient way of enabling it. The default Apache 2 configuration is set up precisely this way, though it may not be convenient to maintain the ability to conditionally start Apache with SSL—it would be inconvenient to forget this on a production server, for instance. If you do want to use this, you can start Apache with SSL with this:
If the configuration of the server is valid, Apache should start up. You can verify it’s running under Linux using ps:
On System V Unix systems such as Solaris, use ps -elf instead for much the same result. If the server cannot start, Apache will log an error message to the screen advising you to run apachectl configtest to get more details about the problem. If the configuration is valid enough that Apache knows where the server’s error log is, you may also find additional information about the problem there. Even if the server does start, the error log may still highlight possible problems that aren’t serious enough to actually stop Apache running but imply a configuration error, for example, not specifying a ServerName directive. If Apache successfully starts, it will log a message into its error log:
To keep an eye on the error log while starting Apache under Unix, a background tail command can be very useful: Starting Apache on Windows Apache 2 for Windows can be run in two different ways:
If you don’t want to run Apache continuously, you can start it from a console window and shut it down whenever you want. This is the mode Apache is installed in if you use the installer to install it for the current user only. You can run Apache as a Windows service if you want to keep Apache running continuously. This is the mode Apache is installed in if you use the installer to install it for all users. You can start, stop, pause, or resume services on remote and local computers and configure startup and recovery options. You can also enable or disable services for a particular hardware profile. If Apache is installed as a service, it may be started automatically at the time of system boot. See the “Configuring Apache as a Windows Service” section later in the chapter. Running As a Console Application There are two different ways to run Apache as a console application:
If you choose to run Apache stand-alone rather than as a service, and have installed it from a Windows installer archive as described earlier, then you can start it from the Start menu, using the name you gave to the installer previously. Clicking the menu option opens a console window and starts Apache inside it. You can similarly stop the server at any time by clicking the Shutdown Apache Console App menu option. Using the Command PromptApache can be run from the command window by typing the following command at the command prompt:
This starts Apache as a console application. In this case, the console window remains open as long as Apache is running; press Ctrl+C to shut down Apache again. You may also specify options to modify how Apache starts. For example, you can specify a configuration file other than the default by using the -f option:
You should now be able to see Apache in the Task Manager, which can be brought up with Ctrl+Alt+Delete or by right-clicking the task bar and selecting Task Manager. Also, if Apache 2 is running, you can see the Apache Monitor icon in the system tray. Detecting Configuration Errors If there’s any error while running Apache, the console window will close unexpectedly. If this happens, you can determine the cause of the error by reading the error log; generally this file is located at C:\Program Files\Apache Group\Apache2\logs\error.log. Early in the startup process, errors may also be sent directly to the console. The -E and -e invocation options can help trap these, along with -w on Windows platforms. I’ll discuss these and other options next. Invocation OptionsAs you saw earlier in the chapter, the -f option can be used to point Apache at the location of a configuration file. The configuration file may in turn define the location of log and error files. However, Apache provides many other options, too. Invoking Apache with httpd -h will produce a list of available options and should look something like this:
I’ll describe each of these options in a moment, but Table 2-2 provides a quick summary of them for reference. The table shows the generally applicable options that are available on all platforms.
Table 2-2. HTTPD Invocation Command Line Options Apache 1.3 additionally provides an option to keep the parent Apache process in the foreground to help catch error status codes from a failed start (see Table 2-3).
Table 2-3. Apache 1.3 Foreground Option Apache 2 additionally provides two more options for assisting with debugging startup problems (see Table 2-4).
Table 2-4. Apache 2 Debugging Options Both Apache versions also support two unlisted options (see Table 2-5).
Table 2-5. Additional Options
Table 2-6. Windows-Specific Options Now that you have seen all the command line options that Apache supports, you can go through them in detail. Once you have done this, you’ll put a few of them into action in the “Starting, Stopping, and Restarting the Server” section.
blog comments powered by Disqus |
|
|
|
|
|
|
|