📄 windows.html.en
字号:
Programming Interface) extensions (i.e. internet server
applications), such as those used by Microsoft IIS and other
Windows servers. <a href="../mod/mod_isapi.html">More information
is available</a>. Note that Apache <strong>cannot</strong> load
ISAPI Filters.</p></li>
<li><p>When running CGI scripts, the method Apache uses to find
the interpreter for the script is configurable using the
<code class="directive"><a href="../mod/core.html#scriptinterpretersource">ScriptInterpreterSource</a></code>
directive.</p></li>
<li><p>Since it is often difficult to manage files with names
like <code>.htaccess</code> in Windows, you may find it useful to
change the name of this per-directory configuration file using
the <code class="directive"><a href="../mod/core.html#accessfilename">AccessFilename</a></code>
directive.</p></li>
<li><p>Any errors during Apache startup are logged into the
Windows event log when running on Windows NT. This mechanism
acts as a backup for those situations where Apache cannot even
access the normally used <code>error.log</code> file. You can
view the Windows event log by using the Event Viewer application
on Windows NT 4.0, and the Event Viewer MMC snap-in on newer
versions of Windows.</p>
<div class="note"><strong>Note that there is no startup error logging on
Windows 9x because no Windows event log exists on those operating
systems.</strong></div></li>
</ul>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="winsvc" id="winsvc">Running Apache as a Service</a></h2>
<p>Apache can be run as a service on Windows NT. There is some
highly experimental support for similar behavior on Windows 9x.</p>
<p>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.</p>
<p>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).
</p>
<p>You can install Apache as a Windows NT service as follows from
the command prompt at the Apache <code>bin</code> subdirectory:</p>
<div class="example"><p><code>
apache -k install
</code></p></div>
<p>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.</p>
<div class="example"><p><code>
apache -k install -n "MyServiceName"
</code></p></div>
<p>If you need to have specifically named configuration files for
different services, you must use this:</p>
<div class="example"><p><code>
apache -k install -n "MyServiceName" -f "c:\files\my.conf"
</code></p></div>
<p>If you use the first command without any special parameters except
<code>-k install</code>, the service will be called <code>Apache2</code>
and the configuration will be assumed to be <code>conf\httpd.conf</code>.
</p>
<p>Removing an Apache service is easy. Just use:</p>
<div class="example"><p><code>
apache -k uninstall
</code></p></div>
<p>The specific Apache service to be uninstalled can be specified by using:</p>
<div class="example"><p><code>
apache -k uninstall -n "MyServiceName"
</code></p></div>
<p>Normal starting, restarting and shutting down of an Apache
service is usually done via the Apache Service Monitor, by using
commands like <code>NET START Apache2</code> and <code>NET STOP
Apache2</code> 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:</p>
<div class="example"><p><code>
apache -n "MyServiceName" -t
</code></p></div>
<p>You can control an Apache service by its command line switches,
too. To start an installed Apache service you'll use this:</p>
<div class="example"><p><code>
apache -k start
</code></p></div>
<p>To stop an Apache service via the command line switches, use
this:</p>
<div class="example"><p><code>
apache -k stop
</code></p></div>
<p>or</p>
<div class="example"><p><code>
apache -k shutdown
</code></p></div>
<p>You can also restart a running service and force it to reread
its configuration file by using:</p>
<div class="example"><p><code>
apache -k restart
</code></p></div>
<p>By default, all Apache services are registered to run as the
system user (the <code>LocalSystem</code> account). The
<code>LocalSystem</code> 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.
</p>
<div class="warning"><strong>Never grant any network privileges to
the <code>LocalSystem</code> account! If you need Apache to be able
to access network resources, create a separate account for Apache as
noted below.</strong></div>
<p>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.</p>
<ol>
<li>Create a normal domain user account, and be sure to
memorize its password.</li>
<li>Grant the newly-created user a privilege of <code>Log on
as a service</code> and <code>Act as part of the operating
system</code>. 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.
</li>
<li>Confirm that the created account is a member of the Users
group.</li>
<li>Grant the account read and execute (RX) rights to all document
and script folders (<code>htdocs</code> and <code>cgi-bin</code>
for example).</li>
<li>Grant the account change (RWXD) rights to the
Apache <code>logs</code> directory.</li>
<li>Grant the account read and execute (RX) rights to the
<code>Apache.exe</code> binary executable.</li>
</ol>
<div class="note">It is usually a good practice to grant the user the Apache
service runs as read and execute (RX) access to the whole Apache2
directory, except the <code>logs</code> subdirectory, where the
user has to have at least change (RWXD) rights.</div>
<p>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.</p>
<div class="note"><strong>Error code 2186</strong> is a good indication that
you need to review the "Log On As" configuration for the service,
since Apache cannot access a required network resource. Also, pay
close attention to the privileges of the user Apache is
configured to run as.</div>
<p>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:</p>
<div class="example"><p><code>
Could not start the Apache2 service on \\COMPUTER <br />
Error 1067; The process terminated unexpectedly.
</code></p></div>
<p>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.</p>
<p>There is some support for Apache on Windows 9x to behave in a
similar manner as a service on Windows NT. It is <strong>highly
experimental</strong>. 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!</p>
<p>There are some differences between the two kinds of services
you should be aware of:</p>
<ul>
<li><p>Apache will attempt to start and if successful it will run
in the background. If you run the command</p>
<div class="example"><p><code>
apache -n "MyServiceName" -k start
</code></p></div>
<p>via 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.</p></li>
<li><p>Windows 9x does not support <code>NET START</code> or
<code>NET STOP</code> commands. You must control the Apache
service on the command prompt via the <code>-k</code> switches.
</p></li>
<li><p>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.</p></li>
</ul>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -