Apache HTTP Server Version 2.0
Apache can be run as a service on Windows NT/2000. (There is also some HIGHLY EXPERIMENTAL support for similar behavior on Windows 95/98, introduced with Apache 1.3.13).
Installing Apache as a service should only be done once you
can successfully run it in a console window. See Using Apache with Microsoft Windows
before you attempt to install or run Apache as a service.
Changes to the httpd.conf
file should always be
followed by starting Apache as a console window. If this
succeeds, the service should succeed.
-u
) and re-installing
(-i
) the Apache service.To start Apache as a service, you first need to install it as a service. Multiple Apache services can be installed, each with a different name and configuration. To install the default Apache service named "Apache", run the "Install Apache as Service (NT only)" option from the Start menu. Once this is done you can start the "Apache" service by opening the Services window (in the Control Panel), selecting Apache, then clicking on Start. Apache will now be running, hidden in the background. You can later stop Apache by clicking on Stop. As an alternative to using the Services window, you can start and stop the "Apache" service from the command line with
NET START APACHE
NET STOP APACHE
See Controlling Apache as a Service for more information on installing and controlling Apache services.
After starting Apache as a service (or if you have trouble starting it) you can test it using the same procedure as for running in a console window. Remember to use the command:
apache -n "service name"
to assure you are using the service's configuration.
-n
option to specify a service
name is only available with Apache 1.3.7 and later.
Earlier versions of Apache only support the default service name
"Apache".You can install Apache as a Windows NT service as follows:
apache -i -n "service name"
To install a service to use a particular configuration, specify the configuration file when the service is installed:
apache -i -n "service name" -f "\my server\conf\my.conf"
To remove an Apache service, use:
apache -u -n "service name"
The default "service name", if one is not specified, is "Apache".
Once a service is installed, you can use the -n
option, in conjunction with other options, to refer to a
service's configuration file. For example:
To test a service's configuration file:
apache -n "service name" -t
To start a console Apache using a service's configuration file:
apache -n "service name"
Prior to Apache release 1.3.13, the dependencies required to successfully start an installed service were not configured. After installing a service using earlier versions of Apache, you must follow these steps:
Run regedt32
Select Window - "HKEY_LOCAL_MACHINE on Local Machine" from the menu
Double-click to open the SYSTEM, then the CurrentControlSet keys
Scroll down and click on the Apache servicename
Select Edit - Add Value... from the menu
Fill in the Add Value dialog with
Value Name: DependOnGroup
Data Type: REG_MULTI_SZ
and click OK
Leave the Multi-String Editor dialog empty and click OK
Select Edit - Add Value... from the menu
Fill in the Add Value dialog with
Value Name: DependOnService
Data Type: REG_MULTI_SZ
and click OK
Type the following list (one per line) in the Multi-String Editor dialog
Tcpip
Afd
and click OK
If you are using COM or DCOM components from a third party module, ISAPI, or other add-in scripting technologies such as ActiveState Perl, you may also need to add the entry Rpcss to the DependOnService list. To avoid exposing the TCP port 135 when it is unnecessary, Apache does not create that entry upon installation. Follow the directions above to find or create the DependOnService value, double click that value if it already exists, and add the Rpcss entry to the list.
When Apache is first installed as a service (e.g. with the
-i
option) it will run as user "System" (the LocalSystem
account). There should be few issues if all resources for the
web server reside on the local system, but it has broad
security privileges to affect the local machine!
NEVER grant network privileges to the SYSTEM account! Create a new user account instead, grant the appropriate privileges to that user, and use the the "Log On As:" option. Select the Start Menu -> Settings -> Control Panel -> Services -> apache service ... and click the "Startup" button to access this setting.
The SYSTEM account has no privileges to the network, so shared pages or a shared installation of Apache is invisible to the service. If you intend to use any network resources, the following steps should help:
document
and script
directories (minimally read and browse access).logs
directory!If you allow the account to log in as a user, then you can log in yourself and test that the account has the privileges to execute the scripts, read the web pages, and that you can start Apache in a console window. If this works, and you have followed the steps above, Apache should execute as a service with no problems.
When starting Apache as a service you may encounter an error message from Windows service manager. For example if you try to start Apache using the Services applet in Windows Control Panel you may get the following message:
Could not start the apache service on \\COMPUTER
Error 1067; The process terminated unexpectedly.
You will get this error if there is any problem starting Apache. In order to see what is causing the problem you should follow the instructions for Running Apache for Windows from the Command Line.
Also, Apache 1.3.13 now records startup errors in the Application Event Log under Windows NT/2000, if Apache is run as a service. Run the Event Viewer and select Log ... Application to see these events.
For details on controlling Apache service from the command line, please refer to console command line section.
Multiple instances of Apache can be installed and run as services. Signal an installed Apache service to start, restart, or shutdown/stop as follows:
apache -n "service name" -k start
apache -n "service name" -k restart
apache -n "service name" -k shutdown
apache -n "service name" -k stop
For the default "Apache" service, the -n
Apache
option is still required, since the -k
commands without
the -n
option are directed at Apache running in a console
window. The quotes are only required if the service name contains spaces.
-k stop
alias for the
-k shutdown
command was introduced in Apache version
1.3.13. Earlier versions of Apache will only recognize the
-k shutdown
option. Prior to 1.3.3, Apache did not
recognize any -k
options at all!In addition, you can use the native NT NET
command
to start and stop Apache services as follows:
NET START "service name"
NET STOP "service name"
Again, quotes are only required if the service name contains spaces.
There is some support for Apache on Windows 95/98 to behave in a similar manner as a service on Windows NT/2000. It is highly experimental, if it works (at all) the Apache Sofware Foundation will not attest to its reliability or future support. Proceed at your own risk!
Once you have confirmed that Apache runs correctly at the Command Prompt you can install, control and uninstall it with the same commands as the Windows NT/2000 version.
There are, however, significant differences that you should note:
Apache will attempt to start and if successful it will run in the background. If you run the command
Apache -n "service name" -k start
via a shortcut on your desktop, for example, then if the
service starts successfully a console window will flash up but
immediately disappears. If Apache detects any errors on startup
such as a incorrect entries in the httpd.conf
file,
then the console window will remain visible. This will display
an error message which will be useful in tracking down the cause
of the problem.
Windows 95/98 does not support NET START
or
NET STOP
commands so you must use Apache's Service
Control options at a command prompt. You may wish to set up a
shortcut for each of these commands so that you can just choose
it from the start menu or desktop to perform the required action.
Apache and Windows 95/98 offer no support for running the Apache service as a specific user with network privileges. In fact, Windows 95/98 offers no security on the local machine, either. This is the simple reason that the Apache Software Foundation never endorses the use of Windows 95/98 as a public httpd server. These facilities exist only to assist the user in developing web content and learning the Apache server, and perhaps as a intranet server on a secured, private network.