Unix 系统下的安装
在线手册:中文 英文
PHP手册

Debian GNU/Linux 安装说明

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

Warning

Unofficial builds from third-parties are not supported here. Any bugs should be reported to the Debian team unless they can be reproduced using the latest builds from our » download area.

While the instructions for building PHP on Unix apply to Debian as well, this manual page contains specific information for other options, such as using either the apt-getor aptitudecommands. This manual page uses these two commands interchangeably.

使用 APT

First, note that other related packages may be desired like libapache2-mod-php5 to integrate with Apache 2, and php-pear for PEAR.

Second, before installing a package, it's wise to ensure the package list is up to date. Typically, this is done by running the command apt-get update.

Example #1 Debian 中在 Apache 2 下安装的例子

# apt-get install php5-common libapache2-mod-php5 php5-cli

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

Example #2 安装完 PHP 后停止并启动 Apache

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

更好地控制配置

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

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

Example #3 取得 PHP 附加软件包的列表

# dpkg -l 'php4-*'

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

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

Example #4 安装 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等)中去。

Example #5 在 PHP 中激活 MySQL,cURL 和 GD 的配置行

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

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

常见问题


Unix 系统下的安装
在线手册:中文 英文
PHP手册
PHP手册 - N: Debian GNU/Linux 安装说明

用户评论:

juraj at jurajsplayground dot com (09-May-2009 01:59)

On Ubuntu (since 7.04), rather do:
sudo tasksel install lamp-server

Details:
https://help.ubuntu.com/community/ApacheMySQLPHP

tranzbit at yahoo dot com (02-May-2009 09:59)

On Ubuntu:

sudo apt-get install apache2 php5 mysql-client-5.0 mysql-server-5.0 phpmyadmin libapache2-mod-php5 libapache2-mod-auth-mysql php5-mysql

then restart the computer/start mysql manually
From:
http://ubuntuforums.org/showthread.php?t=186492

John Fisher (09-Feb-2007 12:53)

With Apache2 and Php4 under Debian Sarge there is an extra configuration file :  /etc/apache2/sites-available/default
This file is not clearly documented, at least not for noobs, in Apache docs.

It overrides the conf file in the way you expect the /etc/apache2/conf.d/apache2-doc  to do according to the README.

Add ExecCGI to it to get rid of "Options ExecCGI is off in this directory"  errors.

Ben A. (18-Dec-2005 06: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 06: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 ......