PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<Unix 系统下的安装Caudium 服务器>
Last updated: Mon, 16 Jul 2012

Unix 系统下的 Apache 2.0

本节包括在 Unix 平台的 Apache 2.0 下安装 PHP 的说明和提示。

警告

不推荐将线程 MPM 用于实际运作的 Apache 2 环境中去。用 prefork MPM 替代,或者用 Apache 1。其原因见 使用线程 MPM 的 Apache2。

推荐您阅读 Apache 文档,了解一下 Apache 2.0 服务器。

PHP and Apache 2.0.x compatibility notes: The following versions of PHP are known to work with the most recent version of Apache 2.0.x:

These versions of PHP are compatible to Apache 2.0.40 and later.

Apache 2.0 SAPI-support started with PHP 4.2.0. PHP 4.2.3 works with Apache 2.0.39, don't use any other version of Apache with PHP 4.2.3. However, the recommended setup is to use PHP 4.3.0 or later with the most recent version of Apache2.

All mentioned versions of PHP will work still with Apache 1.3.x.

下载最新版本的 Apache 2.0,并且根据上文选择合适版本的 PHP 下载。本向导仅包含最基础的内容,只能让 Apache 2.0 和 PHP 能够正常工作。更多信息请阅读 Apache 文档。这里省略所有的版本号,以保证本文的正确性。您需要将本文的“NN”替换为相应的版本号。

例子 4-4. 安装说明(Apache 2 共享模块版本)

1.  gzip -d httpd-2_0_NN.tar.gz
2.  tar xvf httpd-2_0_NN.tar
3.  gunzip php-NN.tar.gz
4.  tar -xvf php-NN.tar
5.  cd httpd-2_0_NN
6.  ./configure --enable-so
7.  make
8.  make install

    现在您已经将 Apache 2.0.NN 安装在 /usr/local/apache。本安装支持可装载模块
    和标准的 MPM prefork。之后,可以使用如下命令启动 Apache 服务器:
    /usr/local/apache2/bin/apachectl start
    如果成功,您可以停止 Apache 服务器并继续安装 PHP:
    /usr/local/apache2/bin/apachectl stop.

9.  cd ../php4-NN

10. 现在我们需要配置 PHP。在这里您可以用各种各样的参数来自定义PHP,例如启动哪
    些扩展功能包的支持等。用 ./configure --help 命令可以列出当前可用的所有参
    数。在我们的例子中,我们将给出一个在有 MySQL 支持的 Apache 2 上进行配置的
    范例。您本地的 apxs 的路径可能会不同,事实上,在您的系统中,它可能被命名为
    apxs2。

    ./configure --with-apxs2=/usr/local/apache2/bin/apxs

11. make
12. make install

    如果您决定在安装后改变配置选项,您只需重复最后的三步,然后需要重新启动
    Apache 使新模块生效。无需重新编译。

    请注意,除非明确有提示,否则 'make install' 命令将安装 PEAR、各种 PHP 工具
    诸如 phpize,安装 PHP CLI 等等。

13. 配置 php.ini

    cp php.ini-dist /usr/local/lib/php.ini

    您可以编辑 php.ini 文件以修改 PHP 的选项。如果您想要把此文件放到另外的位置,
    您需要在步骤 10 添加 --with-config-file-path=/path 选项。

    如果您选择 php.ini -recommended,请务必阅读其中的变更的列表,它们将影响
    PHP 的执行。

14. 编辑 httpd.conf 文件以调用 PHP 模块。LoadMolude 表达式右边的路径必须指向您
    系统中的 PHP。以上的 make install 命令可能已经帮您完成了这些,但务必要检查。

    对于 PHP 4:
       LoadModule php4_module modules/libphp4.so

    对于 PHP 5:
       LoadModule php5_module modules/libphp5.so

15. 告知 Apache 将特定的扩展名解析成 PHP,例如,我们让 Apache 将扩展名 .php
    解析成 PHP。您可以将任何扩展名指定为 PHP,只需添加它们,每一个用空格分隔。
    例如,我们要添加 .phtml:

    AddType application/x-httpd-php .php .phtml

    通常,我们还将 .phps 扩展名设置成显示高亮的 PHP 源文件,可以这样来完成:

    AddType application/x-httpd-php-source .phps

16. 启动您的 Apache 服务器:
   /usr/local/apache2/bin/apachectl start

按照上面的步骤您便可以使 Apache 2.0 将 PHP 作为 SAPI 模块了。当然 Apache 和 PHP 都还有很多配置选项,您可以在相应的源代码目录中使用 ./configure --help 获得更多信息。假如您要编译一个多线程版本的 Apache 2.0,您必须覆盖标准的 MPM-Module prefork,或者 worker 或者 perchild。要这样,您需要在上面的第 6 步使用 --with-mpm=worker 或者 --with-mpm=perchild 选项。之前您需要了解您正在做什么。更多信息请参考 Apache 文档中关于 MPM-Modules 的部分。

注: 如果您要使用内容协商(content negotiation)机制,请阅读 Apache MultiViews 常见问题。

注: 要编译多线程版本的 Apache,您的系统必须支持多线程。这也意味着需要将 PHP 编译为正处在试验阶段的 Zend Thread Safety (ZTS)。因此并不是所有的扩展都可以使用了。推荐编译 Apache 使用标准的 prefork MPM-Module。




<Unix 系统下的安装Caudium 服务器>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST