1
0
mirror of https://github.com/php/doc-zh.git synced 2026-04-27 01:58:14 +02:00
Files
mowangjuanzi eab9684955 Update install
2024-10-16 00:17:55 +08:00

147 lines
4.5 KiB
XML
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 2871f7103c7cfcfd95db64eb0930085965fd9330 Maintainer: Luffy Status: ready -->
<!-- CREDITS: mowangjuanzi -->
<sect1 xml:id="install.windows.apache2" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>在Windows系统上安装 Apache 2.x</title>
<para>
本节包括在 Microsoft Windows 系统中针对 Apache 2.x 安装 PHP 的指导与说明。
</para>
<note>
<para>
请先阅读<link linkend="install.windows.manual">手工安装步骤</link>
</para>
</note>
<para>
强烈建议阅读 <link xlink:href="&url.apache2.docs;">Apache 文档</link> 来加深对
Apache 2.x 服务器的基本理解。此外在继续下去之前考虑先阅读一下 Apache 2.x 的
<link xlink:href="&url.apache2.windows;">Windows 下使用说明</link>
</para>
<para>
下载最新版本的 <link xlink:href="&url.apachelounge.download;">Apache 2.x</link>
以及适合的 PHP 版本。先完成<link linkend="install.windows.manual">手工安装步骤</link>后再回来继续将
PHP 集成入 Apache。
</para>
<para>
Windows 下有三种方法使 PHP 工作于 Apache 2.x 之中。可以以 handler、CGI、或者 FastCGI 方式运行 PHP。
</para>
&note.apache.slashes;
<sect2 xml:id="install.windows.apache2.module">
<title>以 Apache handler 方式安装</title>
<note>
<simpara>
在使用 apache2handler SAPI 时,必须使用线程安全 (TS) 版本的 PHP。
</simpara>
</note>
<para>
需要将以下几行加入到 Apache 的 &httpd.conf; 配置文件中以加载 Apache 2.x 的 PHP 模块:
<example>
<title>PHP 在 Apache 2.x 中作为 handler</title>
<programlisting role="apache-conf">
<![CDATA[
# 在 PHP 8.0.0 之前,模块的名称是 php7_module
LoadModule php_module "c:/php/php8apache2_4.dll"
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
# 配置 php.ini 的路径
PHPIniDir "C:/php"
]]>
</programlisting>
</example>
</para>
<note>
<simpara>
必须使用实际的 PHP 路径替换掉上例中的 <filename>c:/php/</filename>
确保在 <literal>LoadModule</literal> 指令中引用的文件位于所指定的位置。
PHP 7 使用 <filename>php7apache2_4.dll</filename>
PHP 8 使用 <filename>php8apache2_4.dll</filename>
</simpara>
</note>
</sect2>
<sect2 xml:id="install.windows.apache2.cgi">
<title>以 CGI 方式运行 PHP</title>
<para>
要更好地理解在 Apache 下运行 CGI,请参阅
<link xlink:href="&url.apache.cgi;">Apache CGI 文档</link>
</para>
<para>
要将 PHP 以 CGI 方式运行,需要将 php-cgi 文件放入到用
ScriptAlias 指令所指定的 CGI 目录中。
</para>
<para>
然后需要给 PHP 文件中添加 <literal>#!</literal> 的一行来指明 PHP 可执行文件的位置:
<example>
<title>Apache 2.x 下 CGI 方式的 PHP</title>
<programlisting>
<![CDATA[
#!C:/php/php.exe
<?php
phpinfo();
?>
]]>
</programlisting>
</example>
</para>
&warn.install.cgi;
</sect2>
<sect2 xml:id="install.windows.apache2.fastcgi">
<title>以 FastCGI 方式运行 PHP</title>
<para>
以 FastCGI 方式运行 PHP 比起 CGI 方式有很多优点。设定的方式很直接:
</para>
<para>
<link xlink:href="&url.apachelounge.download;">&url.apachelounge;</link>
取得 <literal>mod_fcgid</literal>,该站点有 Win32 可执行文件的下载。按照下载文件中的指示安装此模块。
</para>
<para>
按以下方法配置 web 服务器,注意用自己系统上的路径替换其中相应的内容:
<example>
<title>配置 Apache 以 FastCGI 方式运行 PHP</title>
<programlisting>
<![CDATA[
LoadModule fcgid_module modules/mod_fcgid.so
# php.ini 文件的位置
FcgidInitialEnv PHPRC "c:/php"
<FilesMatch \.php$>
SetHandler fcgid-script
</FilesMatch>
FcgidWrapper "c:/php/php-cgi.exe" .php
]]>
</programlisting>
</example>
此时具有 <literal>.php</literal> 后缀的文件将被 PHP FastCGI 所解析执行。
</para>
</sect2>
</sect1>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->