]> granicus.if.org Git - apache/blob - docs/manual/platform/windows.xml
724074172ac630441fba859a8d4a04bdbff5e13d
[apache] / docs / manual / platform / windows.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 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <manualpage metafile="windows.xml.meta">
24   <parentdocument href="./">Platform Specific Notes</parentdocument>
25
26   <title>Using Apache HTTP Server on Microsoft Windows</title>
27
28   <summary>
29     <p>This document explains how to install, configure and run
30     Apache 2.&httpd.minor; under Microsoft Windows.  If you have questions after
31     reviewing the documentation (and any event and error logs), you
32     should consult the peer-supported
33     <a href="http://httpd.apache.org/userslist.html">users' mailing
34     list</a>.</p>
35
36     <p>This document assumes that you are installing a binary
37     distribution of Apache. If you want to compile Apache yourself
38     (possibly to help with development or tracking down bugs),
39     see <a href="win_compiling.html">Compiling Apache for Microsoft
40     Windows</a>.</p>
41   </summary>
42
43   <section id="req">
44     <title>Operating System Requirements</title>
45
46     <p>The primary Windows platform for running Apache 2.&httpd.minor; is Windows
47     2000 or later. Always obtain and
48     install the current service pack to avoid operating system bugs.</p>
49
50     <note>Apache HTTP Server versions later than 2.2 will not run on any
51     operating system earlier than Windows 2000.</note>
52   </section>
53
54   <section id="down">
55     <title>Downloading Apache for Windows</title>
56
57     <p>The Apache HTTP Server Project itself does not provide binary releases of 
58     software, only source code. If you cannot compile the Apache HTTP Server
59     yourself, you can obtain a binary package from numerous binary distributions
60     available on the Internet.</p>
61
62     <p>Popular options for deploying Apache httpd, and, optionally, PHP
63     and MySQL, on Microsoft Windows, include:</p>
64     <ul>
65     <li><a href="http://www.apachelounge.com/download/">Apache
66     Lounge</a></li>
67     <li><a href="http://www.apachefriends.org/en/xampp.html">XAMPP, from
68     ApacheFriends</a></li>
69     <li><a href="http://www.wampserver.com/">WampServer</a></li>
70     </ul>
71   </section>
72
73   
74   <section id="cust">
75     <title>Customizing Apache for Windows</title>
76
77     <p>Apache is configured by the files in the <code>conf</code>
78     subdirectory. These are the same files used to configure the Unix
79     version, but there are a few different directives for Apache on
80     Windows. See the <a href="../mod/directives.html">directive index</a>
81     for all the available directives.</p>
82
83     <p>The main differences in Apache for Windows are:</p>
84     <ul>
85       <li><p>Because Apache for Windows is multithreaded, it does not
86       use a separate process for each request, as Apache can on Unix.
87       Instead there are usually only two Apache processes running: a
88       parent process, and a child which handles the requests. Within
89       the child process each request is handled by a separate thread.
90       </p>
91
92       <p>The process management directives are also different:</p>
93
94       <p><directive module="mpm_common">MaxConnectionsPerChild</directive>:
95       Like the Unix directive, this controls how many connections a single
96       child process will serve before exiting.
97       However, unlike on Unix, a replacement process is not instantly
98       available.  Use the default <code>MaxConnectionsPerChild 0</code>,
99       unless instructed to change the behavior to overcome a memory leak
100       in third party modules or in-process applications.</p>
101
102       <note type="warning"><strong>Warning: The server configuration
103       file is reread when a new child process is started. If you have
104       modified <code>httpd.conf</code>, the new child may not start or
105       you may receive unexpected results.</strong></note>
106
107       <p><directive module="mpm_common">ThreadsPerChild</directive>:
108       This directive is new. It tells the server how many threads it
109       should use. This is the maximum number of connections the server
110       can handle at once, so be sure to set this number high enough for
111       your site if you get a lot of hits. The recommended default is
112       <code>ThreadsPerChild 150</code>, but this must be adjusted to
113       reflect the greatest anticipated number of simultaneous
114       connections to accept.</p></li>
115
116       <li><p>The directives that accept filenames as arguments must use
117       Windows filenames instead of Unix ones. However, because Apache
118       may interpret backslashes as an "escape character" sequence, you
119       should consistently use forward slashes in path names, not
120       backslashes.</p></li>
121
122       <li><p>While filenames are generally case-insensitive on
123       Windows, URLs are still treated internally as case-sensitive
124       before they are mapped to the filesystem.  For example, the
125       <directive module="core" type="section">Location</directive>,
126       <directive module="mod_alias">Alias</directive>, and <directive
127       module="mod_proxy">ProxyPass</directive> directives all use
128       case-sensitive arguments.  For this reason, it is particularly
129       important to use the <directive module="core"
130       type="section">Directory</directive> directive when attempting
131       to limit access to content in the filesystem, since this
132       directive applies to any content in a directory, regardless of
133       how it is accessed.  If you wish to assure that only lowercase
134       is used in URLs, you can use something like:</p>
135
136       <highlight language="config">
137 RewriteEngine On
138 RewriteMap lowercase int:tolower
139 RewriteCond %{REQUEST_URI} [A-Z]
140 RewriteRule (.*) ${lowercase:$1} [R,L]
141       </highlight></li>
142
143       <li><p>When running, Apache needs write access only to the logs
144       directory and any configured cache directory tree.  Due to the
145       issue of case insensitive and short 8.3 format names, Apache must
146       validate all path names given.  This means that each directory
147       which Apache evaluates, from the drive root up to the directory
148       leaf, must have read, list and traverse directory permissions.
149       If Apache2.&httpd.minor; is installed at C:\Program Files, then the root
150       directory, Program Files and Apache2.&httpd.minor; must all be visible
151       to Apache.</p></li>
152
153       <li><p>Apache for Windows contains the ability to load modules at
154       runtime, without recompiling the server. If Apache is compiled
155       normally, it will install a number of optional modules in the
156       <code>\Apache2.&httpd.minor;\modules</code> directory. To activate these or
157       other modules, the new <directive module="mod_so">LoadModule</directive>
158       directive must be used. For example, to activate the status
159       module, use the following (in addition to the status-activating
160       directives in <code>access.conf</code>):</p>
161
162       <highlight language="config">
163         LoadModule status_module modules/mod_status.so
164       </highlight>
165
166       <p>Information on <a href="../mod/mod_so.html#creating">creating
167       loadable modules</a> is also available.</p></li>
168
169       <li><p>Apache can also load ISAPI (Internet Server Application
170       Programming Interface) extensions such as those used by Microsoft
171       IIS and other Windows servers. <a href="../mod/mod_isapi.html">More
172       information is available</a>. Note that Apache <strong>cannot</strong>
173       load ISAPI Filters, and ISAPI Handlers with some Microsoft feature
174       extensions will not work.</p></li>
175
176       <li><p>When running CGI scripts, the method Apache uses to find
177       the interpreter for the script is configurable using the
178       <directive module="core">ScriptInterpreterSource</directive>
179       directive.</p></li>
180
181       <li><p>Since it is often difficult to manage files with names
182       like <code>.htaccess</code> in Windows, you may find it useful to
183       change the name of this per-directory configuration file using
184       the <directive module="core">AccessFilename</directive>
185       directive.</p></li>
186
187       <li><p>Any errors during Apache startup are logged into the
188       Windows event log when running on Windows NT. This mechanism
189       acts as a backup for those situations where Apache is not yet
190       prepared to use the <code>error.log</code> file. You can
191       review the Windows Application Event Log by using the Event Viewer,
192       e.g. Start - Settings - Control Panel - Administrative Tools
193       - Event Viewer.</p></li>
194     </ul>
195
196   </section>
197
198   <section id="winsvc">
199     <title>Running Apache as a Service</title>
200
201     <p>Apache comes with a utility called the Apache Service Monitor.
202     With it you can see and manage the state of all installed Apache
203     services on any machine on your network. To be able to manage an
204     Apache service with the monitor, you have to first install the
205     service (either automatically via the installation or manually).
206     </p>
207
208     <p>You can install Apache as a Windows NT service as follows from
209     the command prompt at the Apache <code>bin</code> subdirectory:</p>
210
211     <example>
212       httpd.exe -k install
213     </example>
214
215     <p>If you need to specify the name of the service you want to
216     install, use the following command. You have to do this if you
217     have several different service installations of Apache on your
218     computer. If you specify a name during the install, you have to
219     also specify it during any other -k operation.</p>
220
221     <example>
222       httpd.exe -k install -n "MyServiceName"
223     </example>
224
225     <p>If you need to have specifically named configuration files for
226     different services, you must use this:</p>
227
228     <example>
229       httpd.exe -k install -n "MyServiceName" -f "c:\files\my.conf"
230     </example>
231
232     <p>If you use the first command without any special parameters except
233     <code>-k install</code>, the service will be called <code>Apache2.&httpd.minor;</code>
234     and the configuration will be assumed to be <code>conf\httpd.conf</code>.
235     </p>
236
237     <p>Removing an Apache service is easy. Just use:</p>
238
239     <example>
240       httpd.exe -k uninstall
241     </example>
242
243     <p>The specific Apache service to be uninstalled can be specified by using:</p>
244
245     <example>
246       httpd.exe -k uninstall -n "MyServiceName"
247     </example>
248
249     <p>Normal starting, restarting and shutting down of an Apache
250     service is usually done via the Apache Service Monitor, by using
251     commands like <code>NET START Apache2.&httpd.minor;</code> and <code>NET STOP
252     Apache2.&httpd.minor;</code> or via normal Windows service management. Before
253     starting Apache as a service by any means, you should test the
254     service's configuration file by using:</p>
255
256     <example>
257       httpd.exe -n "MyServiceName" -t
258     </example>
259
260     <p>You can control an Apache service by its command line switches,
261     too. To start an installed Apache service you'll use this:</p>
262
263     <example>
264       httpd.exe -k start -n "MyServiceName"
265     </example>
266
267     <p>To stop an Apache service via the command line switches, use
268     this:</p>
269
270     <example>
271       httpd.exe -k stop -n "MyServiceName"
272     </example>
273
274     <p>or</p>
275
276     <example>
277       httpd.exe -k shutdown -n "MyServiceName"
278     </example>
279
280     <p>You can also restart a running service and force it to reread
281     its configuration file by using:</p>
282
283     <example>
284       httpd.exe -k restart -n "MyServiceName"
285     </example>
286
287     <p>By default, all Apache services are registered to run as the
288     system user (the <code>LocalSystem</code> account). The
289     <code>LocalSystem</code> account has no privileges to your network
290     via any Windows-secured mechanism, including the file system, named
291     pipes, DCOM, or secure RPC. It has, however, wide privileges locally.
292     </p>
293
294     <note type="warning"><strong>Never grant any network privileges to
295     the <code>LocalSystem</code> account! If you need Apache to be able
296     to access network resources, create a separate account for Apache as
297     noted below.</strong></note>
298
299     <p>It is recommended that users create a separate account for running
300     Apache service(s). If you have to access network resources via Apache,
301     this is required.</p>
302
303     <ol>
304       <li>Create a normal domain user account, and be sure to
305       memorize its password.</li>
306
307       <li>Grant the newly-created user a privilege of <code>Log on
308       as a service</code> and <code>Act as part of the operating
309       system</code>. On Windows NT 4.0 these privileges are granted via
310       User Manager for Domains, but on Windows 2000 and XP you probably
311       want to use Group Policy for propagating these settings. You can
312       also manually set these via the Local Security Policy MMC snap-in.
313       </li>
314
315       <li>Confirm that the created account is a member of the Users
316       group.</li>
317
318       <li>Grant the account read and execute (RX) rights to all document
319       and script folders (<code>htdocs</code> and <code>cgi-bin</code>
320       for example).</li>
321
322       <li>Grant the account change (RWXD) rights to the
323       Apache <code>logs</code> directory.</li>
324
325       <li>Grant the account read and execute (RX) rights to the
326       <code>httpd.exe</code> binary executable.</li>
327     </ol>
328
329     <note>It is usually a good practice to grant the user the Apache
330     service runs as read and execute (RX) access to the whole Apache2.&httpd.minor;
331     directory, except the <code>logs</code> subdirectory, where the
332     user has to have at least change (RWXD) rights.</note>
333
334     <p>If you allow the account to log in as a user and as a service,
335     then you can log on with that account and test that the account has
336     the privileges to execute the scripts, read the web pages, and that
337     you can start Apache in a console window. If this works, and you
338     have followed the steps above, Apache should execute as a service
339     with no problems.</p>
340
341     <note><strong>Error code 2186</strong> is a good indication that
342     you need to review the "Log On As" configuration for the service,
343     since Apache cannot access a required network resource. Also, pay
344     close attention to the privileges of the user Apache is
345     configured to run as.</note>
346
347     <p>When starting Apache as a service you may encounter an error
348     message from the Windows Service Control Manager. For example,
349     if you try to start Apache by using the Services applet in the
350     Windows Control Panel, you may get the following message:</p>
351
352     <example>
353       Could not start the Apache2.&httpd.minor; service on \\COMPUTER <br />
354       Error 1067; The process terminated unexpectedly.
355     </example>
356
357     <p>You will get this generic error if there is any problem with
358     starting the Apache service. In order to see what is really causing
359     the problem you should follow the instructions for Running Apache
360     for Windows from the Command Prompt.</p>
361
362     <p>If you are having problems with the service, it is suggested
363     you follow the instructions below to try starting httpd.exe from
364     a console window, and work out the errors before struggling to
365     start it as a service again.</p>
366   </section>
367
368   <section id="wincons">
369     <title>Running Apache as a Console Application</title>
370
371     <p>Running Apache as a service is usually the recommended way to
372     use it, but it is sometimes easier to work from the command line,
373     especially during initial configuration and testing.</p>
374
375     <p>To run Apache from the command line as a console application,
376     use the following command:</p>
377
378     <example>
379       httpd.exe
380     </example>
381
382     <p>Apache will execute, and will remain running until it is stopped
383     by pressing Control-C.</p>
384
385     <p>You can also run Apache via the shortcut Start Apache in Console
386     placed to <code>Start Menu --&gt; Programs --&gt; Apache HTTP Server
387     2.&httpd.minor;.xx --&gt; Control Apache Server</code> during the installation.
388     This will open a console window and start Apache inside it. If you
389     don't have Apache installed as a service, the window will remain
390     visible until you stop Apache by pressing Control-C in the console
391     window where Apache is running in. The server will exit in a few
392     seconds. However, if you do have Apache installed as a service, the
393     shortcut starts the service. If the Apache service is running
394     already, the shortcut doesn't do anything.</p>
395
396     <p>If Apache is running as a service, you can tell it to stop by opening another console
397     window and entering:</p>
398
399     <example>
400       httpd.exe -k shutdown
401     </example>
402
403     <p>Running as a service should be preferred over running in a
404     console window because this lets Apache end any current operations
405     and clean up gracefully.</p>
406
407     <p>But if the server is running in a console window, you can
408     only stop it by pressing Control-C in the same window.</p>
409
410     <p>You can also tell Apache to restart. This forces it to reread
411     the configuration file. Any operations in progress are allowed to
412     complete without interruption. To restart Apache, either press
413     Control-Break in the console window you used for starting Apache,
414     or enter</p>
415
416     <example>
417       httpd.exe -k restart
418     </example>
419
420     <p>if the server is running as a service.</p>
421
422     <note>Note for people familiar with the Unix version of Apache:
423     these commands provide a Windows equivalent to <code>kill -TERM
424     <em>pid</em></code> and <code>kill -USR1 <em>pid</em></code>. The
425     command line option used, <code>-k</code>, was chosen as a reminder
426     of the <code>kill</code> command used on Unix.</note>
427
428     <p>If the Apache console window closes immediately or unexpectedly
429     after startup, open the Command Prompt from the Start Menu --&gt;
430     Programs. Change to the folder to which you installed Apache, type
431     the command <code>httpd.exe</code>, and read the error message. Then
432     change to the logs folder, and review the <code>error.log</code>
433     file for configuration mistakes. Assuming httpd was installed into 
434     <code>C:\Program Files\Apache Software Foundation\Apache2.&httpd.minor;\</code>, 
435     you can do the following:</p>
436
437     <example>
438       c: <br />
439       cd "\Program Files\Apache Software Foundation\Apache2.&httpd.minor;\bin" <br />
440       httpd.exe
441     </example>
442
443     <p>Then wait for Apache to stop, or press Control-C. Then enter the
444     following:</p>
445
446     <example>
447       cd ..\logs <br />
448       more &lt; error.log
449     </example>
450
451     <p>When working with Apache it is important to know how it will
452     find the configuration file. You can specify a configuration file
453     on the command line in two ways:</p>
454
455     <ul>
456       <li><p><code>-f</code> specifies an absolute or relative path to
457       a particular configuration file:</p>
458
459       <example>
460         httpd.exe -f "c:\my server files\anotherconfig.conf"
461       </example>
462
463       <p>or</p>
464
465       <example>
466         httpd.exe -f files\anotherconfig.conf
467       </example></li>
468
469       <li><p><code>-n</code> specifies the installed Apache service
470       whose configuration file is to be used:</p>
471
472       <example>
473         httpd.exe -n "MyServiceName"
474       </example>
475       </li>
476     </ul>
477
478     <p>In both of these cases, the proper
479     <directive module="core">ServerRoot</directive> should be set in
480     the configuration file.</p>
481
482     <p>If you don't specify a configuration file with <code>-f</code>
483     or <code>-n</code>, Apache will use the file name compiled into the
484     server, such as <code>conf\httpd.conf</code>. This built-in path
485     is relative to the installation directory. You can verify the compiled
486     file name from a value labelled as <code>SERVER_CONFIG_FILE</code> when
487     invoking Apache with the <code>-V</code> switch, like this:</p>
488
489     <example>
490       httpd.exe -V
491     </example>
492
493     <p>Apache will then try to determine its <directive module="core"
494     >ServerRoot</directive> by trying the following, in this order:</p>
495
496     <ol>
497       <li>A <directive module="core">ServerRoot</directive> directive
498       via the <code>-C</code> command line switch.</li>
499
500       <li>The <code>-d</code> switch on the command line.</li>
501
502       <li>Current working directory.</li>
503
504       <li>A registry entry which was created if you did a binary
505       installation.</li>
506
507       <li>The server root compiled into the server. This is <code>
508       /apache</code> by default, you can verify it by using <code>
509       httpd.exe -V</code> and looking for a value labelled as
510       <code>HTTPD_ROOT</code>.</li>
511     </ol>
512
513     <p>If you did not do a binary install, Apache will in some
514     scenarios complain about the missing registry key. This warning can
515     be ignored if the server was otherwise able to find its
516     configuration file.</p>
517
518     <p>The value of this key is the
519     <directive module="core">ServerRoot</directive> directory which
520     contains the <code>conf</code> subdirectory. When Apache starts it
521     reads the <code>httpd.conf</code> file from that directory. If
522     this file contains a <directive module="core">ServerRoot</directive>
523     directive which contains a different directory from the one
524     obtained from the registry key above, Apache will forget the
525     registry key and use the directory from the configuration file. If
526     you copy the Apache directory or configuration files to a new
527     location it is vital that you update the
528     <directive module="core">ServerRoot</directive> directive in the
529     <code>httpd.conf</code> file to reflect the new location.</p>
530   </section>
531
532   <section id="test">
533     <title>Testing the Installation</title>
534
535     <p>After starting Apache (either in a console window or as a
536     service) it will be listening on port 80 (unless you changed the
537     <directive module="mpm_common">Listen</directive> directive in the
538     configuration files or installed Apache only for the current user).
539     To connect to the server and access the default page, launch a
540     browser and enter this URL:</p>
541
542     <example>
543       http://localhost/
544     </example>
545
546     <p>Apache should respond with a welcome page and you should see
547     "It Works!". If nothing happens or you get an error, look in the
548     <code>error.log</code> file in the <code>logs</code> subdirectory.
549     If your host is not connected to the net, or if you have serious
550     problems with your DNS (Domain Name Service) configuration, you
551     may have to use this URL:</p>
552
553     <example>
554       http://127.0.0.1/
555     </example>
556
557     <p>If you happen to be running Apache on an alternate port, you
558     need to explicitly put that in the URL:</p>
559
560     <example>
561       http://127.0.0.1:8080/
562     </example>
563
564     <p>Once your basic installation is working, you should configure it
565     properly by editing the files in the <code>conf</code> subdirectory.
566     Again, if you change the configuration of the Windows NT service
567     for Apache, first attempt to start it from the command line to
568     make sure that the service starts with no errors.</p>
569
570     <p>Because Apache <strong>cannot</strong> share the same port with
571     another TCP/IP application, you may need to stop, uninstall or reconfigure
572     certain other services before running Apache. These conflicting
573     services include other WWW servers, some firewall implementations,
574     and even some client applications (such as Skype) which will use port
575     80 to attempt to bypass firewall issues.</p>
576   </section>
577
578   <section id="windrivemap">
579     <title>Configuring Access to Network Resources</title>
580
581   <p>Access to files over the network can be specified using two
582   mechanisms provided by Windows:</p>
583
584   <dl>
585     <dt>Mapped drive letters</dt>
586     <dd>e.g., <code>Alias /images/ Z:/</code></dd>
587
588     <dt>UNC paths</dt>
589     <dd>e.g., <code>Alias /images/ //imagehost/www/images/</code></dd>
590   </dl>
591
592   <p>Mapped drive letters allow the administrator to maintain the
593   mapping to a specific machine and path outside of the Apache httpd
594   configuration.  However, these mappings are associated only with
595   interactive sessions and are not directly available to Apache httpd
596   when it is started as a service.  <strong>Use only UNC paths for
597   network resources in httpd.conf</strong> so that the resources can
598   be accessed consistently regardless of how Apache httpd is started.
599   (Arcane and error prone procedures may work around the restriction
600   on mapped drive letters, but this is not recommended.)</p>
601
602   <example><title>Example DocumentRoot with UNC path</title>
603   <highlight language="config">
604   DocumentRoot //dochost/www/html/
605   </highlight>
606   </example>
607
608   <example><title>Example DocumentRoot with IP address in UNC path</title>
609   <highlight language="config">
610   DocumentRoot //192.168.1.50/docs/
611   </highlight>
612   </example>
613
614   <example><title>Example Alias and corresponding Directory with UNC path</title>
615   <highlight language="config">
616 Alias /images/ //imagehost/www/images/
617
618 &lt;Directory //imagehost/www/images/&gt;
619 #...
620 &lt;Directory&gt;
621   </highlight>
622   </example>
623
624   <p>When running Apache httpd as a service, you must create a
625   separate account in order to access network resources, as described
626   above.</p>
627   </section>
628
629 </manualpage>