Debian GNU/Linux 安装说明

本节包含了在 Debian GNU/Linux 下安装 PHP 的说明和提示。

使用 APT

当然可以下载 PHP 源代码并自己编译,不过使用 Debian 的软件包系统是安装 PHP 的最简单和最干净利落的方法。如果不熟悉在 Linux 下编译软件,那最好用此方法。

首先要决定是安装 Apache 1.3.x 还是 Apache 2.x。相对应的 PHP 软件包名字为 libapache-mod-php* 和 libapache2-mod-php*。以下步骤以 Apache 1.3.x 为例。注意迄今为止,还没有 PHP 5 的正式的 Debian 软件包。以下步骤将安装 PHP 4。

PHP 在 Debian 下也有 CGI 和 CLI 两种风格,分别命名为 php4-cgi 和 php4-cli。如果需要的话,只要用正确的软件包名称重复以下步骤。另外需要安装的一个特殊软件包是 php4-pear。它包含了最小的 PEAR 安装以及 pear 命令行工具。

如果需要比 Debian 的稳定版本更新的 PHP 包或者一些不在 Debian 官方库中的 PHP 模块,那应该看看 http://www.apt-get.org/。其中可以找到一个 Dotdeb。此非官方库是由 Guillaume Plessis 负责维护,其中包含了最新版 PHP 4 和 PHP 5 的 Debian 软件包。要使用,只需将以下两行添加到 /etc/apt/sources.lists 并运行 apt-get update

例子 4-10. Dotdeb 有关的两行

deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all

最后要考虑的是自己的软件包列表是否是最新版。如果最近没有更新过,那需要在做任何事之前先 apt-get update。这样就可以使用最近稳定版的 Apache 和 PHP 软件包了。

所有准备做好之后,就可以按照下面的例子来安装 Apache 和 PHP:

例子 4-11. Debian 中在 Apache 1.3 下安装的例子

# apt-get install libapache-mod-php4

APT 将自动安装 Apache 1.3 的 PHP 4 模块以及所有依赖的库并激活之。如果在安装过程中没有被要求重启动 Apache,那必须手工进行:

例子 4-12. 安装完 PHP 4 后停止并启动 Apache

# /etc/init.d/apache stop
# /etc/init.d/apache start

更好地控制配置

上一节中 PHP 仅安装了核心模块。但可能不够用,用户很快就会发现需要更多的激活模块,例如 MySQL,cURL,GD 等。

当自己从源代码编译 PHP 时,需要通过 configure 命令来激活模块。用 APT 则只需安装附加的软件包。这些包都命名为“php4-*”(或“php5-*”,如果安装了第三方的 PHP 5 的话)。

例子 4-13. 取得 PHP 附加软件包的列表

# dpkg -l 'php4-*'

从上面的输出中可以看到,还有很多 PHP 模块可安装(除了 php4-cgi,php4-cli 或 php4-pear 这些特殊软件包)。仔细察看并安装自己所需要的。如果选择了一个模块而没有相应的库,APT 会自动安装所有依赖的库。

如果选择将 MySQL,cURL 和 GD 支持添加到 PHP 中,则其命令类似于:

例子 4-14. 安装 PHP 的 MySQL,cURL 和 GD 支持

# apt-get install php4-mysql php4-curl php4-gd

APT 会自动把适当的行添加到不同的 php.ini/etc/php4/apache/php.ini/etc/php4/cgi/php.ini 等)中去。

例子 4-15. 在 PHP 中激活 MySQL,cURL 和 GD 的配置行

extension=mysql.so
extension=curl.so
extension=gd.so

只需像之前那样重新启动 Apache 来激活这些模块。

常见问题

  • 如果看到了 PHP 源代码而不是脚本应该产生的结果,则 APT 可能没有 /etc/apache/conf.d/php4 包括到 Apache 1.3 配置中去。请确保下面一行出现在 /etc/apache/httpd.conf 文件中并重启动 Apache:

    例子 4-16. 下面这行在 Apache 中激活了 PHP 4

    # Include /etc/apache/conf.d/
  • 如果安装了更多模块但其函数不能在脚本中使用,请确保相应的配置行出现在 php.ini 中,如上面所说。APT 可能会由于混乱的 debconf 配置而在安装附加模块时失败。


add a note add a note User Contributed Notes
A random Debian Developer
05-Oct-2006 10:00
PHP5 is available in Debian 4.0 (codename 'etch') or later. Until Debian 4.0 is released you may want to look at www.backports.org which also has the packages.

www.backports.org only allows official Debian Developers to upload packages so it is likely that they are somewhat more trustable than some generic collection of "debs" available for download.
Ben A.
18-Dec-2005 02:53
Although there are no PHP 5 packages for Debian 3.1 (aka "stable" or "sarge"), there are currently PHP 5 packages for "testing"/"etch" and "unstable"/"sid".  Installation works the same way.

Also, the same process can be used for Ubuntu, but note that some of the packages may be in the "universe" section instead of "main".
jimmychan at example dot com
24-Oct-2005 01:01
If you are using Debian 3.1

It is total, the php.ini is under
/etc/php4/apache2

Since Debian 3.1 default apache is 2.0.x version, this one just said how to change the php.ini under apache 1.3.x

If you need enable the ext. need manaul edit php.ini, and comment out # of what the ext. that you want to enable

Of course, you much first install the ext. first by like that

apt-get install php4-gd php4-mysql ......