Home arrow Apache arrow Page 9 - Getting Started with Apache

Starting, Stopping, and Restarting the Server - Apache

Learn the basic steps necessary to download, install, and configure a basic Apache server. This article is from chapter two of Pro Apache by Peter Wainwright. (Apress, 2004, ISBN: 1590593006).

TABLE OF CONTENTS:
  1. Getting Started with Apache
  2. Installing Apache
  3. Installing Apache from Binary Distribution
  4. Installing Apache from Prebuilt Packages
  5. Installing Apache by Hand
  6. Upgrading Apache
  7. Basic Configuration
  8. Administratorís E-Mail Address
  9. Starting, Stopping, and Restarting the Server
  10. Generic Invocation Options
  11. Windows-Specific Invocation Options
  12. Testing the Server
  13. Testing the Server Configuration Without Starting It
  14. Using Graphical Configuration Tools
By: Apress Publishing
Rating: starstarstarstarstar / 19
December 13, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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 Unix

To start Apache, itís usually sufficient to invoke it without additional parameters, for example:

$ /usr/local/apache/bin/httpd

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:

$ /usr/local/apache/bin/httpd -f /home/www/alpha-complex/conf/httpd-test.conf

Alternatively, Apache comes with the very convenient apachectl script, which can be used to start the server with this:

$ /usr/local/apache/bin/apachectl start

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:

$ /usr/local/apache/bin/apachectl startssl

If the configuration of the server is valid, Apache should start up. You can verify itís running under Linux using ps:

$ ps -aux | grep httpd

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:

Server configured - resuming normal operations

To keep an eye on the error log while starting Apache under Unix, a background tail command can be very useful:

$ tail -f /usr/local/apache/logs/error_log & $ /usr/local/apache/bin/apachectl start

Starting Apache on Windows

Apache 2 for Windows can be run in two different ways:

  • From a console window

  • As a Windows service

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:

  • From a Start menu option

  • From the command line in a command prompt window

Using the Menu Option

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 Prompt

Apache can be run from the command window by typing the following command at the command prompt:

C:\Program Files\Apache Group\Apache2\bin\apache

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:

C:\Program Files\Apache Group\Apache2\bin\apache -f "Program Files\Apache Group\Apache2\conf\
myconfiguration.conf"

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 Options

As 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:

/usr/local/apache/bin/httpd
[-D name] [-d directory] [-f file]
[-C "directive"] [-c "directive"]
[-v] [-V] [-h] [-l] [-L] [-t] [-T]

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.

Option Description
-D name Define a name for use in directives
-d directory Specify an alternative initial ServerRoot
-f file Specify an alternative ServerConfigFile
-C "directive" Process directive before reading configuration files
-c "directive" Process directive after reading configuration files
-v Show version number
-V Show compile settings
-h List available command line options (this page)
-l List compiled in modules
-L List available configuration directives
-t -D DUMP_VHOSTS Show parsed settings (currently only vhost settings)
-t Run syntax check for configuration files (with docroot check)
-T Run syntax check for configuration files (without docroot check)

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).

Option

Description

-F

Foreground mode. Donít detach from the console.

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).

Option

Description

-e level

Specify an alternative startup log level, for example, debug

-E startuplogfile

Specify an alternative startup logfile for debugging startup problems

Table 2-4. Apache 2 Debugging Options

Both Apache versions also support two unlisted options (see Table 2-5).

Option

Description

-X

Single-process foreground debugging mode.

-R

Specify an alternative location for loadable modules (shared core Apache servers only)

Table 2-5. Additional Options

Option

Description

-I

Register Apache as a service

-k config

Modify existing service definition

-k install

Same as-I

-k uninstall

Deregister as a service

-k restart

Restart running Apache

-k start

Start Apache

-k stop

Stop Apache

-k shutdown

Same as-k stop

-n <servicename>

The name of the service to control with the-i,-u, and-kcommands

-u

Same as-k uninstall

-w

Leaves the initial shell window open for 30 seconds to view startup messages

-W <servicename>

The name of the service after which an Apache service should be started (with-k configor-i)

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.  

This chapter is from Pro Apache by Peter Wainwright. (Apress, 2004, ISBN: 1590593006). Check it out at your favorite bookstore today. Buy this book now.



 
 
>>> More Apache Articles          >>> More By Apress Publishing
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

APACHE ARTICLES

- Apache Unveils Cassandra 1.2
- Apache on ARM Chips? Dell and Calxeda Help M...
- The Down Side of Open Source Software
- VMware Unveils Serengeti for Apache Hadoop
- SAP Takes Steps to Improve Hadoop Integration
- Looking to Hone Apache Hadoop Skills?
- How to Install Joomla on WAMPP
- Working with XAMPP and Wordpress
- GUI Available for Apache Camel
- Reduce Server Load for Apache and PHP Websit...
- Creating a VAMP (Vista, Apache, MySQL, PHP) ...
- Putting Apache in Jail
- Containing Intrusions in Apache
- Server Limits for Apache Security
- Setting Permissions in Apache

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: