]> granicus.if.org Git - apache/blob - docs/manual/platform/win_service.xml
new XML
[apache] / docs / manual / platform / win_service.xml
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "../style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4
5 <manualpage>
6   <relativepath href=".." />
7
8   <title>Running Apache for Windows as a Service</title>
9
10   <summary>
11
12     <p>Apache can be run as a service on Windows NT/2000. (There is
13     also some HIGHLY EXPERIMENTAL support for similar behavior on
14     <a href="#win95svc">Windows 95/98</a>, introduced with Apache
15     1.3.13).</p>
16
17     <p>Installing Apache as a service should only be done once you
18     can successfully run it in a console window. See <a
19     href="windows.html">Using Apache with Microsoft Windows</a>
20     before you attempt to install or run Apache as a service.
21     Changes to the <code>httpd.conf</code> file should always be
22     followed by starting Apache as a console window. If this
23     succeeds, the service should succeed.</p>
24
25     <note><strong>Prior to version 1.3.13, the configuration was
26     <em>not tested</em> prior to performing the
27     installation</strong>, and a lack of service dependencies often
28     caused the console window to succeed, but the service would
29     still fail. See <a href="#service">below</a> if you are having
30     problems running a version of Apache prior to 1.3.13 to resolve
31     the issue. If you have this problem with version 1.3.13 or
32     greater, first try uninstalling (<code>-u</code>) and re-installing
33     (<code>-i</code>) the Apache service.</note>
34
35     <p>To start Apache as a service, you first need to install it
36     as a service. Multiple Apache services can be installed, each
37     with a different name and configuration. To install the default
38     Apache service named "Apache", run the "Install Apache as
39     Service (NT only)" option from the Start menu. Once this is
40     done you can start the "Apache" service by opening the Services
41     window (in the Control Panel), selecting Apache, then clicking
42     on Start. Apache will now be running, hidden in the background.
43     You can later stop Apache by clicking on Stop. As an
44     alternative to using the Services window, you can start and
45     stop the "Apache" service from the command line with</p>
46
47     <example>
48       NET START APACHE<br />
49       NET STOP APACHE
50     </example>
51
52     <p>See <a href="#signal">Controlling Apache as a Service</a>
53     for more information on installing and controlling Apache
54     services.</p>
55
56     <note><title>Note</title>
57     Apache, unlike many other Windows NT/2000 services,
58     logs any errors to its own error.log file in the logs folder
59     within the Apache server root folder. You will <em>not</em>
60     find Apache error details in the Windows NT Event
61     Log.</note>
62
63     <p>After starting Apache as a service (or if you have trouble
64     starting it) you can test it using the same <a
65     href="windows.html#cmdline">procedure</a> as for running in a
66     console window. Remember to use the command:</p>
67
68     <example>
69       apache -n "service name"
70     </example>
71
72     <p>to assure you are using the service's configuration.</p>
73
74   </summary>
75
76   <section id="service">
77
78     <title>Running Apache for Windows as a Service</title>
79
80     <note><strong>The <code>-n</code> option to specify a service
81     name is only available with Apache 1.3.7 and later.</strong>
82     Earlier versions of Apache only support the default service name
83     "Apache".</note>
84
85     <p>You can install Apache as a Windows NT service as
86     follows:</p>
87
88     <example>
89       apache -i -n "service name"
90     </example>
91
92     <p>To install a service to use a particular configuration,
93     specify the configuration file when the service is
94     installed:</p>
95
96     <example>
97       apache -i -n "service name" -f "\my server\conf\my.conf"
98     </example>
99
100     <p>To remove an Apache service, use:</p>
101
102     <example>
103       apache -u -n "service name"
104     </example>
105
106     <p>The default "service name", if one is not specified, is
107     "Apache".</p>
108
109     <p>Once a service is installed, you can use the <code>-n</code>
110     option, in conjunction with other options, to refer to a
111     service's configuration file. For example:</p>
112
113     <p>To test a service's configuration file:</p>
114
115     <example>
116       apache -n "service name" -t
117     </example>
118
119     <p>To start a console Apache using a service's configuration
120     file:</p>
121
122     <example>
123       apache -n "service name"
124     </example>
125
126   </section>
127
128   <section id="depends">
129
130     <title>Important Note on service dependencies:</title>
131
132     <p>Prior to Apache release 1.3.13, the dependencies required to
133     successfully start an installed service were not configured.
134     After installing a service using earlier versions of Apache,
135     you must follow these steps:</p>
136
137     <example>
138       Run regedt32 <br />
139       Select Window - "HKEY_LOCAL_MACHINE on Local Machine" from the menu <br />
140       Double-click to open the SYSTEM, then the CurrentControlSet keys <br />
141       Scroll down and click on the Apache servicename <br />
142       Select Edit - Add Value... from the menu <br />
143       Fill in the Add Value dialog with <br />
144       &#160;&#160;&#160;&#160;Value Name: DependOnGroup <br />
145       &#160;&#160;&#160;&#160;Data Type: REG_MULTI_SZ <br />
146       &#160;&#160;&#160;&#160;and click OK <br />
147       Leave the Multi-String Editor dialog empty and click OK <br />
148       Select Edit - Add Value... from the menu <br />
149       Fill in the Add Value dialog with <br />
150       &#160;&#160;&#160;&#160;Value Name: DependOnService <br />
151       &#160;&#160;&#160;&#160;Data Type: REG_MULTI_SZ <br />
152       &#160;&#160;&#160;&#160;and click OK <br />
153       Type the following list (one per line) in the Multi-String Editor dialog <br />
154       &#160;&#160;&#160;&#160;Tcpip <br />
155       &#160;&#160;&#160;&#160;Afd <br />
156       &#160;&#160;&#160;&#160;and click OK <br />
157     </example>
158
159     <p>If you are using COM or DCOM components from a third party
160     module, ISAPI, or other add-in scripting technologies such as
161     ActiveState Perl, you may also need to add the entry Rpcss to
162     the DependOnService list. To avoid exposing the TCP port 135
163     when it is unnecessary, Apache does not create that entry upon
164     installation. Follow the directions above to find or create the
165     DependOnService value, double click that value if it already
166     exists, and add the Rpcss entry to the list.</p>
167
168   </section>
169
170   <section id="account">
171
172     <title>User Account for Apache Service to Run As (NT/2000)</title>
173
174     <p>When Apache is first installed as a service (e.g. with the
175     <code>-i</code> option) it will run as user "System" (the LocalSystem
176     account). There should be few issues if all resources for the
177     web server reside on the local system, but it has broad
178     security privileges to affect the local machine!</p>
179
180     <note>LocalSystem is a very privileged account locally, so you
181     shouldn't run any shareware applications there. However, it
182     has no network privileges and cannot leave the machine via
183     any NT-secured mechanism, including file system, named pipes,
184     DCOM, or secure RPC.</note>
185
186     <p><strong>NEVER grant network privileges to the SYSTEM
187     account!</strong> Create a new user account instead, grant the
188     appropriate privileges to that user, and use the the "Log On
189     As:" option. Select the Start Menu -&gt; Settings -&gt; Control
190     Panel -&gt; Services -&gt; apache service ... and click the
191     "Startup" button to access this setting.</p>
192
193     <note>A service that runs in the context of the LocalSystem account
194     inherits the security context of the SCM. It is not
195     associated with any logged-on user account and does not have
196     credentials (domain name, user name, and password) to be used
197     for verification.</note>
198
199     <p>The SYSTEM account has no privileges to the network, so
200     shared pages or a shared installation of Apache is invisible to
201     the service. If you intend to use <em>any</em> network
202     resources, the following steps should help:</p>
203
204     <ul>
205       <li>Select Apache from the Control Panel's Service dialog and
206       click Startup.</li>
207
208       <li>Verify that the service account is correct. You may wish
209       to create an account for your Apache services.</li>
210
211       <li>Retype the password and password confirmation.</li>
212
213       <li>Go to User Manager for Domains.</li>
214
215       <li>Click on Policies from the title bar menu, and select
216       User Rights.</li>
217
218       <li>Select the option for Advanced User Rights.</li>
219
220       <li>
221         In the drop-down list, verify that the following rights
222         have been granted to the selected account:
223
224         <ul>
225           <li>Act as part of the operating system</li>
226
227           <li>Back up files and directories</li>
228
229           <li>Log on as a service</li>
230
231           <li>Restore files and directories</li>
232         </ul>
233       </li>
234
235       <li>Confirm that the selected account is a member of the
236       Users group.</li>
237
238       <li>Confirm the selected account has access to all
239       <code>document</code> and <code>script</code>
240       directories (minimally read and browse access).</li>
241
242       <li>Confirm the selected account has read/write/delete access
243       to the Apache <code>logs</code> directory!</li>
244     </ul>
245
246     <p>If you allow the account to log in as a user, then you can
247     log in yourself and test that the account has the privileges to
248     execute the scripts, read the web pages, and that you can start
249     Apache in a console window. If this works, and you have
250     followed the steps above, Apache should execute as a service
251     with no problems.</p>
252
253     <note><strong>Error code 2186</strong> is a good indication
254     that you need to review the "Log On As" configuration, since
255     the server can't access a required network resource.</note>
256
257   </section>
258
259   <section id="trouble">
260
261     <title>Troubleshooting Apache for Windows as a Service</title>
262
263     <p>When starting Apache as a service you may encounter an error
264     message from Windows service manager. For example if you try to
265     start Apache using the Services applet in Windows Control Panel
266     you may get the following message:</p>
267
268     <example>
269       Could not start the apache service on \\COMPUTER <br />
270       Error 1067; The process terminated unexpectedly.
271     </example>
272
273     <p>You will get this error if there is any problem starting
274     Apache. In order to see what is causing the problem you should
275     follow the instructions for <a
276     href="windows.html#cmdline">Running Apache for Windows from the
277     Command Line</a>.</p>
278
279     <p>Also, Apache 1.3.13 now records startup errors in the
280     Application Event Log under Windows NT/2000, if Apache is run
281     as a service. Run the Event Viewer and select Log ...
282     Application to see these events.</p>
283
284     <note><strong>Check the Application Event Log with the Event
285     Viewer in case of any problems, even if no error message pops
286     up to warn you that an error occured.</strong></note>
287
288   </section>
289
290   <section id="cmdline">
291
292     <title>Running Apache for Windows from the Command Line</title>
293
294     <p>For details on controlling Apache service from the command
295     line, please refer to <a href="windows.html#cmdline">console
296     command line</a> section.</p>
297
298   </section>
299
300   <section id="signal">
301
302     <title>Controlling Apache as a Service</title>
303
304     <p>Multiple instances of Apache can be installed and run as
305     services. Signal an installed Apache service to start, restart,
306     or shutdown/stop as follows:</p>
307
308     <example>
309       apache -n "service name" -k start <br />
310       apache -n "service name" -k restart <br />
311       apache -n "service name" -k shutdown <br />
312       apache -n "service name" -k stop
313     </example>
314
315     <p>For the default "Apache" service, the <code>-n</code> Apache
316     option is still required, since the <code>-k</code> commands without
317     the <code>-n</code> option are directed at Apache running in a console
318     window. The quotes are only required if the service name contains spaces.</p>
319
320     <note><strong>Note the <code>-k stop</code> alias for the
321     <code>-k shutdown</code> command was introduced in Apache version
322     1.3.13.</strong> Earlier versions of Apache will only recognize the
323     <code>-k shutdown</code> option. Prior to 1.3.3, Apache did not
324     recognize <em>any</em> <code>-k</code> options at all!</note>
325
326     <p>In addition, you can use the native NT <code>NET</code> command
327     to start and stop Apache services as follows:</p>
328
329     <example>
330       NET START "service name" <br />
331       NET STOP "service name"
332     </example>
333
334     <p>Again, quotes are only required if the service name contains
335     spaces.</p>
336
337   </section>
338
339   <section id="win95svc">
340
341     <title>HIGHLY EXPERIMENTAL Windows 95/98 Service</title>
342
343     <note><strong>The service options for Windows 95 and 98 are
344     only available with Apache 1.3.13 and later.</strong> Earlier
345     versions of Apache only supported Apache in a console window
346     for Windows 95/98.</note>
347
348     <p>There is some support for Apache on Windows 95/98 to behave
349     in a similar manner as a service on Windows NT/2000. It is
350     <em>highly experimental</em>, if it works (at all) the Apache
351     Sofware Foundation will not attest to its reliability or
352     future support. Proceed at your own risk!</p>
353
354     <p>Once you have confirmed that Apache runs correctly at the <a
355     href="windows.html#cmdline">Command Prompt</a> you can install,
356     control and uninstall it with the same commands as the Windows
357     NT/2000 version.</p>
358
359     <p>There are, however, significant differences that you should
360     note:</p>
361
362     <p>Apache will attempt to start and if successful it will run
363     in the background. If you run the command</p>
364
365     <example>
366       Apache -n "service name" -k start
367     </example>
368
369     <p>via a shortcut on your desktop, for example, then if the
370     service starts successfully a console window will flash up but
371     immediately disappears. If Apache detects any errors on startup
372     such as a incorrect entries in the <code>httpd.conf</code> file,
373     then the console window will remain visible. This will display
374     an error message which will be useful in tracking down the cause
375     of the problem.</p>
376
377     <p>Windows 95/98 does not support <code>NET START</code> or
378     <code>NET STOP</code> commands so you must use Apache's Service
379     Control options at a command prompt. You may wish to set up a
380     shortcut for each of these commands so that you can just choose
381     it from the start menu or desktop to perform the required action.</p>
382
383     <p>Apache and Windows 95/98 offer no support for running the
384     Apache service as a specific user with network privileges. In
385     fact, Windows 95/98 offers no security on the local machine,
386     either. This is the simple reason that the Apache Software
387     Foundation never endorses the use of Windows 95/98 as a public
388     httpd server. These facilities exist only to assist the user in
389     developing web content and learning the Apache server, and
390     perhaps as a intranet server on a secured, private network.</p>
391
392   </section>
393
394 </manualpage>
395