php mysql环境 xp_Windows XP下PHP+MySQL环境搭建(5)

下一步是创建一个可用的 INI 文件,此文件会告诉 PHP 在被其他应用程序(例如 Apache)调用时如何反应。创建 INI 文件的最佳方式是从模板复制一个文件,然后将其重命名为 php.ini。 在 C:\PHP 中查找名为 php.ini-recommended 的文件。复制此文件并将其粘贴到相同的目录中;然后将其重命名为 php.ini。这就是需要对它进行的所有操作。以后您将回过头来重新查看这个文件,但是现在,这就是开始运行所需的全部操作。

此过程不会 设置 PHP 使用 Apache。因此,让我们回过头来看一些其他的文本文件和手动配置。

将 PHP 连接到 Apache

启动文本编辑器,并打开 Apache 的 httpd.conf 文件,就像您在之前部分中做的那样。搜索 ScriptAlias,应该看到类似如下的内容:

#

# ScriptAlias: This controls which directories contain server scripts.

# ScriptAliases are essentially the same as Aliases, except that

# documents in the realname directory are treated as applications and

# run by the server when requested rather than as documents sent to the client.

# The same rules about trailing "/" apply to ScriptAlias directives as to

# Alias.

#

ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache2/cgi-bin/"

对于 /cgi-bin/来说,此条目告诉 Apache 如何处理任何包含 cgi-bin 目录的 URL。例如,如果您请求了 http://www.newInstance.com/cgi-bin/mail-me,Apache 不会在 cgi-bin 目录中查找一个名为 mail-me 的文件。相反,ScriptAlias 命令会告诉 Apache 查看另一个目录 —— 在本例中,这个目录是 C:/Program Files/Apache Group/Apache2/cgi-bin/。这是至关重要的,因为您不会希望将脚本存储在可通过 Web 访问的目录中。因此,您需要为 PHP 脚本添加一个条目。如下所示:

#

# ScriptAlias: This controls which directories contain server scripts.

# ScriptAliases are essentially the same as Aliases, except that

# documents in the realname directory are treated as applications and

# run by the server when requested rather than as documents sent to the client.

# The same rules about trailing "/" apply to ScriptAlias directives as to

# Alias.

#

ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache2/cgi-bin/"

ScriptAlias /php/ "C:/PHP/"

您可能认为 C:/PHP 不是存储 Web 站点脚本的好地方。这绝对是正确的;然而,您将告诉 Apache 通过 PHP 解释器处理所有以 .php 结尾的文件,而无需考虑这些文件的位置;换句话说,无需担心这个问题。

接下来,您需要告诉 Apache 以 .php 结尾的文件必须作为应用程序处理;尤其是,您希望为 PHP 文件分配一个类型,然后您就能够指示 Apache 以特定方式处理它们。在 ScriptAlias 条目下,添加以下条目:

#

# ScriptAlias: This controls which directories contain server scripts.

# ScriptAliases are essentially the same as Aliases, except that

# documents in the realname directory are treated as applications and

# run by the server when requested rather than as documents sent to the client.

# The same rules about trailing "/" apply to ScriptAlias directives as to

# Alias.

#

ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache2/cgi-bin/"

ScriptAlias /php/ "C:/PHP/"

AddType application/x-httpd-php .php

现在您只需告诉 Apache 当它碰到这种新类型(链接到以 .php结尾的文件)时应该进行什么操作即可。基本上,这仅涉及告诉 Apache 运行什么程序,以及将 PHP 脚本交给什么程序;当然,这个神奇的程序就是您刚刚安装的 PHP 解释器。将此指令直接添加到刚才添加的两个指令下方:

#

# ScriptAlias: This controls which directories contain server scripts.

# ScriptAliases are essentially the same as Aliases, except that

# documents in the realname directory are treated as applications and

# run by the server when requested rather than as documents sent to the client.

# The same rules about trailing "/" apply to ScriptAlias directives as to

# Alias.

#

ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache2/cgi-bin/"

ScriptAlias /php/ "C:/PHP/"

AddType application/x-httpd-php .php

Action application/x-httpd-php "/php/php-cgi.exe"

请记住,Apache 已经知道将 /php/ 翻译为 C:/PHP/,因此这实际上将 PHP 应用程序类型分配给解释器 C:/PHP/php-cgi.exe。当然,您可以通过浏览文件系统中的目录的方式验证这些文件是否存在。

完成上述操作之后,重启 Apache,并确保您没有犯错误。如果当您尝试输入 http://localhost 进行简单的测试时一切正常,那么您就成功了。

测试 PHP 安装

要进行的关于 PHP 方面的工作已经不多了。首先,确保 PHP 脚本运行正常。再次打开文本编辑器,并输入以下代码:

PHP Installation Test

将此文件作为 index.php 保存在您的 Web 站点的根目录中:C:/Documents and Settings/Brett McLaughlin/My Documents/websites。当完成此操作后,应该看到如图 8 所示的内容。

图 8. 编辑一个示例 PHP 脚本(责任编辑:大宝库)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值