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

Debian GNU/Linux 安装说明

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

Warning

这里不支持非官方的第三方发行包。任何错误应报告给 Debian 开发组,除非该错误在使用从官方» 下载的最新版时仍能重现。

尽管在 Unix 下编译 PHP 的指示也适用于 Debian,本节包含有一些特定信息,例如使用 apt-get 或者 aptitude 命令。本节中这两条命令可以互换。

使用 APT

首先,注意其它有关的包可能需要 libapache2-mod-php5 集成入 Apache 2,以及 PEAR 的 php-pear

其次,在安装一个包之前,最好先确定该包是最新版。通常可以运行命令 apt-get update

Example #1 Debian 下将 PHP 安装入 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 仅安装了核心模块。很可能还需要更多模块,例如 MySQLcURLGD 等。这些模块也可以通过 apt-get 命令安装。

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

# apt-cache search php5
# aptitude search php5
# aptitude search php5 |grep -i mysql

以上命令的输出中列出了很多的包,其中有几个针对 PHP 的模块例如 php5-cgi,php5-cli 以及 php5-dev。决定好要安装哪些之后可以用 apt-get 或者 aptitude 来安装。Debian 会进行倚赖性检查,会给出提示,例如安装 MySQL 和 cURL:

Example #4 安装 PHP 的 MySQL 和 cURL 支持

# apt-get install php5-mysql php5-curl

APT 会自动把适当的行添加到不同的 php.ini 相关文件中去,例如 /etc/php5/apache2/php.ini/etc/php5/conf.d/pdo.ini 等,并且根据扩展,还会添加类似 extension=foo.so 的内容。不过还是需要重新启动 web 服务器(例如 Apache)以使这些改动生效。

常见问题


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

用户评论:

thumbs at apache dot org (2013-06-27 17:50:35)

To refresh this document, perhaps it would be worth mentioning more modern methods to serve php content under apache httpd.
Specifically, the preferred method is now fastcgi, using either of those recipes:
(mod_fastcgi, httpd 2.2)
http://wiki.apache.org/httpd/php-fastcgi
(mod_fcgid, httpd 2.2)
http://wiki.apache.org/httpd/php-fcgid
(mod_proxy_fcgi, httpd 2.4)
http://wiki.apache.org/httpd/PHP-FPM
While the legacy mod_php approach is still applicable for some older installations, the fastcgi method is much faster, and require much less RAM to operate, based on similar traffic patterns.
Thank you!

juraj at jurajsplayground dot com (2009-05-08 17:59:37)

On Ubuntu (since 7.04), rather do:
sudo tasksel install lamp-server
Details:
https://help.ubuntu.com/community/ApacheMySQLPHP

tranzbit at yahoo dot com (2009-05-02 13:59:32)

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 (2007-02-08 16:53:55)

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. (2005-12-17 22:53:25)

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 (2005-10-23 22:01:44)

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 ......

易百教程