Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » SQL Anywhere 服务器 - 编程 » SQL Anywhere 数据访问 API » SQL Anywhere PHP API » 在 UNIX 和 Mac OS X 上构建 SQL Anywhere PHP 模块 » 编译 Apache 和 PHP

 

将 PHP 作为 Apache 模块进行编译

以下说明中的前两步将会配置 Apache 以使它能识别共享模块。如果您的系统上已经安装了 Apache 的已编译版本,则直接进入第 3 步。请注意,Mac OS X 附带有预安装的 Apache Web 服务器。

♦  将 PHP 作为 Apache 模块进行编译
  1. 配置 Apache 以识别共享模块。

    从提取 Apache 文件的目录中执行以下命令(在一行中输入所有内容):

    $ cd Apache-source-directory
    $ ./configure --enabled-shared=max --enable-module=most --
    prefix=/Apache-installation-directory

    以下示例适用于 Apache 版本 2.2.9。必须将 apache_2.2.9 设置为正在使用的 Apache 版本。

    $ cd ~/apache_2.2.9
    $ ./configure --enabled-shared=max --enable-module=most --
    prefix=/usr/local/web/apache
  2. 重新编译和安装相关组件:

    $ make
    $ make install

    现在,可以编译 PHP 来将其作为 Apache 模块运行。

  3. 确保设置了适用于 SQL Anywhere 的环境。

    根据您使用的 shell,从 SQL Anywhere 的安装目录(缺省情况下,为 /opt/sqlanywhere11)输入相应的命令。在 Mac OS X 上,缺省目录为 /Applications/SQLAnywhere11/System

    如果正在使用此 shell... ...使用此命令
    sh、ksh、bash
     . ./bin32/sa_config.sh
    csh、tcsh
    source ./bin32/sa_config.csh
  4. 将 PHP 作为 Apache 模块进行配置以包括 SQL Anywhere PHP 模块。

    执行以下命令:

    $ cd PHP-source-directory
    $ ./configure --with-sqlanywhere --with- apxs=/Apache-installation-directory/bin/apxs
    

    以下示例适用于 PHP 版本 5.2.6。必须将 php-5.2.6 设置为正在使用的 PHP 版本。

    $ cd ~/php-5.2.6
    $ ./configure --with-sqlanywhere --with- apxs=/usr/local/web/apache/bin/apxs

    configure 脚本将尝试确定 SQL Anywhere 安装的版本及位置。在此命令的输出中,应看到与以下内容类似的几行:

    checking for SQL Anywhere support... yes
    checking     SQL Anywhere install dir... /opt/sqlanywhere11
    checking     SQL Anywhere version... 11
    
  5. 重新编译相关组件:

    $ make
  6. 检查是否已正确链接到库。

    • Linux 用户(以下示例假定您正在使用 PHP 版本 5):

      ldd ./.libs/libphp5.so
    • Mac OS X 用户:

      请参考 httpd.conf 配置文件以确定计算机上的 libphp5.so 位置。使用以下命令执行检查:

      otool -L $LIBPHP5_DIR/libphp5.so

      $LIBPHP5_DIRlibphp5.so 所在的目录(根据您的服务器配置)。

      此命令输出由 libphp5.so 使用的库的列表。验证 libdblib11.so 在该列表中。

  7. 在 Apache 的 lib 目录中安装 PHP 二进制文件:

    $ make install
  8. 执行验证。PHP 会自动执行此操作。只需确保 httpd.conf 配置文件经过验证以使 Apache 承认 .php 文件作为 PHP 脚本。

    httpd.conf 存储在 Apache 目录的 conf 子目录中:

    $ cd Apache-installation-directory/conf

    例如:

    $ cd /usr/local/web/apache/conf

    在编辑文件前制作 httpd.conf 的一个备份副本(可使用所选的文本编辑器替换 pico):

    $ cp httpd.conf httpd.conf.backup
    $ pico httpd.conf

    httpd.conf 中添加以下几行或取消这几行的注释(这些行在文件中不在一起):

    LoadModule php5_module   libexec/libphp5.so
    AddModule mod_php5.c
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    注意

    在 Mac OS X 上,httpd_macosxserver.conf 中的最后两行应添加或取消注释。

    开头两行会将 Apache 指向用于解释 PHP 代码的文件,而另外两行声明扩展名为 .php.phps 的文件的文件类型,以便 Apache 能够识别并正确地处理它们。

有关测试和使用您的设置的信息,请参见在 Web 页中运行 PHP 测试脚本