简体   繁体   English

如何为 XAMPP 安装 PECL HTTP 扩展?

[英]How to install PECL HTTP extension for XAMPP?

I want to install the PHP PECL HTTP extension in my XAMPP environment (OS is Windows).我想在我的 XAMPP 环境(操作系统是 Windows)中安装 PHP PECL HTTP 扩展。 I have attempted to add multiple variations of the php_http.dll extension into my ext directory, and added extension=php_http.dll to the php.ini file.我试图将 php_http.dll 扩展名的多个变体添加到我的 ext 目录中,并将 extension=php_http.dll 添加到 php.ini 文件中。 Yet when I go to start the Apache service, it throws some sort of error.然而,当我去启动 Apache 服务时,它会抛出某种错误。

It's pretty clear I'm doing something wrong, however I have no idea what.很明显我做错了什么,但我不知道是什么。 The last relevant question I could find was 5 years out of date.我能找到的最后一个相关问题已经过时了 5 年。 Does anybody have any idea how to install this?有人知道如何安装它吗?

You can try:你可以试试:

For pecl.
Look in xampp\php for the pecl.bat file
Open a command console window in this folder and issue the pecl.bat command and it will give a list of commands to use.

This post shows how to install XAMPP on Windows to run PHP applications that connect to a remote Oracle Database.这篇博文展示了如何在 Windows 上安装 XAMPP 以运行连接到远程 Oracle 数据库的 PHP 应用程序。

* *

XAMPP is an open source package that contains Apache, PHP and many PHP 'extensions'. XAMPP 是一个开源包,其中包含 Apache、PHP 和许多 PHP '扩展'。 One of these extension is PHP OCI8 which connects to Oracle Database.这些扩展之一是连接到 Oracle 数据库的 PHP OCI8。

* *

To install XAMPP: D: drive.安装 XAMPP:D: 驱动器。

Download " XAMPP for Windows " and follow the installer wizard.下载“ XAMPP for Windows ”并按照安装程序向导进行操作。 I installed into my D: drive.我安装到我的D: 驱动器中。

Start the Apache server via the XAMPP control panel.通过 XAMPP 控制面板启动 Apache 服务器。

XAMPP 控制面板的屏幕截图

Visit http://localhost/dashboard/phpinfo.php via your browser to see the architecture and thread safety mode of the installed PHP.通过浏览器访问http://localhost/dashboard/phpinfo.php可以查看已安装 PHP 的架构和线程安全模式。 Please note this is the architecture of the installed PHP and not the architecture of your machine.请注意,这是已安装 PHP 的架构,而不是您机器的架构。 It's possible to run a x86 PHP on an x64 machine.可以在 x64 机器上运行 x86 PHP。

在此处输入图片说明

Oracle OCI8 is pre-installed in XAMPP but if you need a newer version you can download an updated OCI8 PECL package from pecl.php.net . Oracle OCI8 预装在 XAMPP 中,但如果您需要更新版本,您可以从pecl.php.net下载更新的 OCI8 PECL 包。

Pick an OCI8 release and select the DLL according to the architecture and thread safety mode.选择一个 OCI8 版本并根据体系结构和线程安全模式选择 DLL。 For example, if PHP is x86 and thread safety enabled, download "7.2 Thread Safe (TS) x86".例如,如果 PHP 是 x86 并且启用了线程安全,请下载“7.2 线程安全 (TS) x86”。 Then replace "D:\\xampp\\php\\ext\\php_oci8_12c.dll" with the new "php_oci8_12c.dll" from the OCI8 PECL package.然后将“D:\\xampp\\php\\ext\\php_oci8_12c.dll”替换为来自 OCI8 PECL 包的新“php_oci8_12c.dll”。

PECL OCI8下载页面截图

Edit "D:\\xampp\\php\\php.ini" and uncomment the line "extension=oci8_12c".编辑“D:\\xampp\\php\\php.ini”并取消注释“extension=oci8_12c”行。 Make sure "extension_dir" is set to the directory containing the PHP extension DLLs.确保“extension_dir”设置为包含 PHP 扩展 DLL 的目录。 For example,例如,

extension=oci8_12c

extension_dir="D:\xampp\php\ext"



  • Download the Oracle Instant Client Basic package from OTN.OTN下载 Oracle Instant Client Basic 包

Select the correct architecture to align with PHP's.选择正确的架构以与 PHP 保持一致。 For Windows x86 download "instantclient-basic-nt-12.2.0.1.0.zip" from the Windows 32-bit page.对于 Windows x86,从 Windows 32 位页面下载“instantclient-basic-nt-12.2.0.1.0.zip”。

Oracle Instant Client 下载页面的屏幕截图

Extract the file in a directory such as "D:\\Oracle".将文件解压缩到“D:\\Oracle”等目录中。 A subdirectory "D:\\Oracle\\instantclient_12_2" will be created.将创建子目录“D:\\Oracle\\instantclient_12_2”。

Add this subdirectory to the PATH environment variable.将此子目录添加到 PATH 环境变量。 You can update PATH in Control Panel -> System -> Advanced System Settings -> Advanced -> Environment Variables -> System Variables -> PATH.您可以在控制面板 -> 系统 -> 高级系统设置 -> 高级 -> 环境变量 -> 系统变量 -> PATH 中更新 PATH。 In my example I set it to "D:\\Oracle\\instantclient_12_2".在我的示例中,我将其设置为“D:\\Oracle\\instantclient_12_2”。

Restart the Apache server and check the phpinfo.php page again.重新启动 Apache 服务器并再次检查 phpinfo.php 页面。 It shows the OCI8 extension is loaded successfully.它显示 OCI8 扩展已成功加载。

显示 OCI8 部分的 PHP 配置页面的屏幕截图

If you also run PHP from a terminal window, make sure to close and reopen the terminal to get the updated PATH value.如果您还从终端窗口运行 PHP,请确保关闭并重新打开终端以获取更新的 PATH 值。

To run your first OCI8 application, create a new file in the XAMPP document root "D:\\xampp\\htdocs\\test.php".要运行您的第一个 OCI8 应用程序,请在 XAMPP 文档根目录“D:\\xampp\\htdocs\\test.php”中创建一个新文件。 It should contain:它应该包含:

<?php
 
error_reporting(E_ALL);
ini_set('display_errors', 'On');
 
$username = "hr";                  // Use your username
$password = "welcome";             // and your password
$database = "localhost/orclpdb";   // and the connect string to connect to your database
 
$query = "select * from dual";
 
$c = oci_connect($username, $password, $database);
if (!$c) {
    $m = oci_error();
    trigger_error('Could not connect to database: '. $m['message'], E_USER_ERROR);
}
 
$s = oci_parse($c, $query);
if (!$s) {
    $m = oci_error($c);
    trigger_error('Could not parse statement: '. $m['message'], E_USER_ERROR);
}
$r = oci_execute($s);
if (!$r) {
    $m = oci_error($s);
    trigger_error('Could not execute statement: '. $m['message'], E_USER_ERROR);
}
 
echo "<table border='1'>\n";
$ncols = oci_num_fields($s);
echo "<tr>\n";
for ($i = 1; $i <= $ncols; ++$i) {
    $colname = oci_field_name($s, $i);
    echo "  <th><b>".htmlspecialchars($colname,ENT_QUOTES|ENT_SUBSTITUTE)."</b></th>\n";
}
echo "</tr>\n";
 
while (($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
    echo "<tr>\n";
    foreach ($row as $item) {
        echo "<td>";
        echo $item!==null?htmlspecialchars($item, ENT_QUOTES|ENT_SUBSTITUTE):"&nbsp;";
        echo "</td>\n";
    }
    echo "</tr>\n";
}
echo "</table>\n";
 
?>

You need to edit this file and set your database username, password and connect string.您需要编辑此文件并设置您的数据库用户名、密码和连接字符串。 If you are using Oracle Database XE, then the connect string should be "localhost/XE".如果您使用的是 Oracle 数据库 XE,则连接字符串应为“localhost/XE”。

The SQL query can also be changed. SQL 查询也可以更改。 Currently it queries the special DUAL table, which every user has.目前它查询每个用户都有的特殊 DUAL 表。

Load the test program in a browser using http://localhost/test.php .使用http://localhost/test.php在浏览器中加载测试程序。 The output will be the single value "X" in the column called "DUMMY".输出将是名为“DUMMY”的列中的单个值“X”。



---- NOTE - - 笔记


Maybe this can help, but this issue is very complex in XAMPP.也许这会有所帮助,但这个问题在 XAMPP 中非常复杂。 I have heard several reports about this problem in xampp, I advise testing VPS free for further study.我在 xampp 中听到了一些关于这个问题的报告,我建议免费测试 VPS 以进一步研究。
if you have any questions, post in the comments.如果您有任何问题,请在评论中发表。 If something is incompatible or wrong, be sure to comment!如果有不兼容或错误的地方,请务必发表评论! thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM