install apache as a service
Running Apache as a Service
Apache can be run as a service on Windows NT. There is some highly experimental support for similar behavior on Windows 9x.
You can install Apache as a service automatically during the installation. If you chose to install for all users, the installation will create an Apache service for you. If you specify to install for yourself only, you can manually register Apache as a service after the installation. You have to be a member of the Administrators group for the service installation to succeed.
Apache comes with a utility called the Apache Service Monitor. With it you can see and manage the state of all installed Apache services on any machine on your network. To be able to manage an Apache service with the monitor, you have to first install the service (either automatically via the installation or manually).
You can install Apache as a Windows NT service as follows from the command prompt at the Apache bin subdirectory:
httpd -k install If you need to specify the name of the service you want to install, use the following command. You have to do this if you have several different service installations of Apache on your computer.
httpd -k install -n "MyServiceName" If you need to have specifically named configuration files for different services, you must use this:
httpd -k install -n "MyServiceName" -f "c:\files\my.conf" If you use the first command without any special parameters except -k install, the service will be called Apache2 and the configuration will be assumed to be conf\httpd.conf.
Removing an Apache service is easy. Just use:
httpd -k uninstall The specific Apache service to be uninstalled can be specified by using:
httpd -k uninstall -n "MyServiceName" Normal starting, restarting and shutting down of an Apache service is usually done via the Apache Service Monitor, by using commands like NET START Apache2 and NET STOP Apache2 or via normal Windows service management. Before starting Apache as a service by any means, you should test the service’s configuration file by using:
httpd -n "MyServiceName" -t You can control an Apache service by its command line switches, too. To start an installed Apache service you’ll use this:
httpd -k start To stop an Apache service via the command line switches, use this:
httpd -k stop or
httpd -k shutdown You can also restart a running service and force it to reread its configuration file by using:
httpd -k restart By default, all Apache services are registered to run as the system user (the LocalSystem account). The LocalSystem account has no privileges to your network via any Windows-secured mechanism, including the file system, named pipes, DCOM, or secure RPC. It has, however, wide privileges locally.
LocalSystem account! If you need Apache to be able to access network resources, create a separate account for Apache as noted below.You may want to create a separate account for running Apache service(s). Especially, if you have to access network resources via Apache, this is strongly recommended.
- Create a normal domain user account, and be sure to memorize its password.
- Grant the newly-created user a privilege of
Log on as a serviceandAct as part of the operating system. On Windows NT 4.0 these privileges are granted via User Manager for Domains, but on Windows 2000 and XP you probably want to use Group Policy for propagating these settings. You can also manually set these via the Local Security Policy MMC snap-in. - Confirm that the created account is a member of the Users group.
- Grant the account read and execute (RX) rights to all document and script folders (
htdocsandcgi-binfor example). - Grant the account change (RWXD) rights to the Apache
logsdirectory. - Grant the account read and execute (RX) rights to the
Apache.exebinary executable.
logs subdirectory, where the user has to have at least change (RWXD) rights.If you allow the account to log in as a user and as a service, then you can log on with that account 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 the Windows Service Control Manager. For example, if you try to start Apache by using the Services applet in the Windows Control Panel, you may get the following message:
Could not start the Apache2 service on \\COMPUTER
Error 1067; The process terminated unexpectedly. You will get this generic error if there is any problem with starting the Apache service. In order to see what is really causing the problem you should follow the instructions for Running Apache for Windows from the Command Prompt.
There is some support for Apache on Windows 9x to behave in a similar manner as a service on Windows NT. It is highly experimental. It is not of production-class reliability, and its future is not guaranteed. It can be mostly regarded as a risky thing to play with - proceed with caution!
There are some differences between the two kinds of services you should be aware of:
- Apache will attempt to start and if successful it will run in the background. If you run the command
httpd -n "MyServiceName" -k startvia a shortcut on your desktop, for example, then if the service starts successfully, a console window will flash up but it immediately disappears. If Apache detects any errors on startup such as incorrect entries in the httpd.conf configuration file, 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 9x does not support
NET STARTorNET STOPcommands. You must control the Apache service on the command prompt via the-kswitches. - Apache and Windows 9x offer no support for running Apache as a specific user with network privileges. In fact, Windows 9x offers no security on the local machine, either. This is the simple reason because of which the Apache Software Foundation never endorses use of a Windows 9x -based system as a public Apache server. The primitive support for Windows 9x exists only to assist the user in developing web content and learning the Apache server, and perhaps as an intranet server on a secured, private network.
Once you have confirmed that Apache runs correctly as a console application you can install, control and uninstall the pseudo-service with the same commands as on Windows NT. You can also use the Apache Service Monitor to manage Windows 9x pseudo-services.
source: http://httpd.apache.org/docs/2.0/platform/windows.html



