How to install PECL HTTP extension for XAMPP? - php

I want to install the PHP PECL HTTP extension in my XAMPP environment (OS is Windows). 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. Yet when I go to start the Apache service, it throws some sort of error.
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. 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.

You also have to load raphf and propro:
http://windows.php.net/downloads/pecl/releases/raphf/1.0.4/
http://windows.php.net/downloads/pecl/snaps/propro/1.0.0/
... and iconv, hash and spl.

This post shows how to install XAMPP on Windows to run PHP applications that connect to a remote Oracle Database.
*
XAMPP is an open source package that contains Apache, PHP and many PHP
'extensions'. One of these extension is PHP OCI8 which connects to
Oracle Database.
*
To install XAMPP: D: drive.
Download "XAMPP for Windows" and follow the installer wizard. I installed into my D: drive.
Start the Apache server via the XAMPP control panel.
Visit http://localhost/dashboard/phpinfo.php via your browser to see the architecture and thread safety mode of the installed PHP. Please note this is the architecture of the installed PHP and not the architecture of your machine. It’s possible to run a x86 PHP on an x64 machine.
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.
Pick an OCI8 release and select the DLL according to the architecture and thread safety mode. For example, if PHP is x86 and thread safety enabled, download "7.2 Thread Safe (TS) x86". Then replace "D:\xampp\php\ext\php_oci8_12c.dll" with the new "php_oci8_12c.dll" from the OCI8 PECL package.
Edit "D:\xampp\php\php.ini" and uncomment the line "extension=oci8_12c". Make sure "extension_dir" is set to the directory containing the PHP extension DLLs. For example,
extension=oci8_12c
extension_dir="D:\xampp\php\ext"
Download the Oracle Instant Client Basic package from OTN.
Select the correct architecture to align with PHP's. For Windows x86 download "instantclient-basic-nt-12.2.0.1.0.zip" from the Windows 32-bit page.
Extract the file in a directory such as "D:\Oracle". A subdirectory "D:\Oracle\instantclient_12_2" will be created.
Add this subdirectory to the PATH environment variable. You can update PATH in Control Panel -> System -> Advanced System Settings -> Advanced -> Environment Variables -> System Variables -> PATH. In my example I set it to "D:\Oracle\instantclient_12_2".
Restart the Apache server and check the phpinfo.php page again. It shows the OCI8 extension is loaded successfully.
If you also run PHP from a terminal window, make sure to close and reopen the terminal to get the updated PATH value.
To run your first OCI8 application, create a new file in the XAMPP document root "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):" ";
        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".
The SQL query can also be changed. Currently it queries the special DUAL table, which every user has.
Load the test program in a browser using http://localhost/test.php. The output will be the single value "X" in the column called "DUMMY".
---- NOTE
Maybe this can help, but this issue is very complex in XAMPP. I have heard several reports about this problem in xampp, I advise testing VPS free for further study.
if you have any questions, post in the comments.
If something is incompatible or wrong, be sure to comment! thanks

Related

mamp pro, php 7.3.8 and remote mssql server

i use mamp pro on mac (catalina) and try to connect to remote mssql server.
in order to work with mssql i installed on the relevant php mamp folder:
brew install msodbcsql17 mssql-tools
pecl install sqlsrv pdo_sqlsrv
than i updated the php.ini file
extension=sqlsrv.so
extension=pdo_sqlsrv.so
when i try to run (of course with the correct credentails and server name)
$db = new PDO("sqlsrv:Server=MY.SERVER;Database=MYDBNAME", "MYUSER", "MYPASS");
i get this error:
Fatal error: Uncaught PDOException: SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712
what am i missing?
The PHP-PDO driver wants to access MS-SQL-server via the ODBC driver of SQL-server.
You need to install the odbc driver by doing
brew install msodbcsql17 mssql-tools
Afterwards, you need to enable TCP connections on sql-server, add a login, add the login to the correct role, and then you need to open port 1433, so TCP connections to SQL-server can work (unless you have both PHP and the sql-server run on the same machine).
And you might have to install UnixODBC:
brew install unixodbc
Also, you might have to add php_odbc to extensions
extension=php_odbc.dll
and php-fpm uses another ini file than php-cli/php-cgi.
On ubuntu, the PHP-fpm ini file is in
/etc/php/7.2/fpm/php.ini
while the other is in
/etc/php/7.2/cli/php.ini
Another alternative, if you can't get ODBC to work, is to use PDO_DBLIB, which uses FreeTDS instead of ODBC. That might be better anyway.
sudo pecl install pdo_dblib
However, that restricts you to php > 5.03 < 6.0.0.
Maybe you can compile it from source.
Mine works on Linux, all I had to do was:
sudo apt-get install php-fpm php-dev php-pear
sudo pecl install sqlsrv pdo_sqlsrv
(msodbcsql17 and mssql-tools I already had installed)
add the lines
extension=sqlsrv.so
extension=pdo_sqlsrv.so
into both ini files, and done.
Then I executed the connection-test-sample
php ./test.php
(i have port 2017, on docker), and it worked:
<?php
$serverName = "localhost,2017";
$connectionOptions = array(
"database" => "MY_DB_NAME",
"uid" => "sa",
"pwd" => "TOP_SECRET"
);
// Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
if ($conn === false) {
die(formatErrors(sqlsrv_errors()));
}
// Select Query
$tsql = "SELECT ##Version AS SQL_VERSION";
// Executes the query
$stmt = sqlsrv_query($conn, $tsql);
// Error handling
if ($stmt === false) {
die(formatErrors(sqlsrv_errors()));
}
?>
<h1> Results : </h1>
<?php
while ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
echo $row['SQL_VERSION'] . PHP_EOL;
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
function formatErrors($errors)
{
// Display errors
echo "Error information: <br/>";
foreach ($errors as $error) {
echo "SQLSTATE: ". $error['SQLSTATE'] . "<br/>";
echo "Code: ". $error['code'] . "<br/>";
echo "Message: ". $error['message'] . "<br/>";
}
}
?>
<h1>Results: </h1>
Microsoft SQL Server 2017 (RTM-CU16) (KB4508218) - 14.0.3223.3 (X64)
Jul 22 2019 17:43:08 Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Linux (Ubuntu 16.04.6 LTS)
I get a funny warning, though:
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/lib64/php/modules/pdo_sqlsrv.so' -
/usr/lib64/php/modules/pdo_sqlsrv.so: undefined symbol:
php_pdo_register_driver in Unknown on line 0
If I remove
extension=pdo_sqlsrv.so
then it works, without warning.
Note:
Just fixed the crap.
If you run php --ini, it will list you all the ini-files php loads.
The correct location (on Linux) to put these two lines is
/etc/php/7.2/mods-available/pdo.ini
The above warning occurs if extension=pdo_sqlsrv.so is loaded before extension=pdo.so. Also, that way, you only need to set the extension ONCE, and it's done for both php-cli and php-fpm. The mods-available are then (already) symlinked into php-fpm and php-cli.
You might have the same problem on Mac.
To make sure there are no permission issues, create a test user that is sysadmin:
-- The available default languages:
-- SELECT * FROM sys.syslanguages AS sysl
CREATE LOGIN [WebServicesTest] WITH PASSWORD = 'TOP_SECRET'
,CHECK_EXPIRATION = off
,CHECK_POLICY = off
,DEFAULT_LANGUAGE = us_english;
EXEC master..sp_addsrvrolemember [WebServicesTest], N'sysadmin';
To test if the connection is actually working with the user, you can use AzureDataStudio.
Beware:
If your system uses OpenSSL 1.1 (e.g. Ubuntu 19.04), you need to download the insiders-build.
TDS-based providers (freeTDS/ODBC) need TCP open, even if you work on localhost.
if anyone needs the answer
turned out need to install one more thing:
brew install msodbcsql#13.1.9.2 mssql-tools#14.0.6.0

PHP can't connect to SQL Server

I have been thrown into the world of PHP, and I'm having a bit of an issue connecting to my SQL server. I'm using the following code to try to connect. When it hits the SQLsrv_connect command, it just seems to stop processing. No error, it just stops loading.
function testConnection()
{
$returnable = "TEST";
echo 'Current PHP version: ' . phpversion();
$connectionInfo = array("Database"=>"MyDatabase", "UID"=>"MyLogin", "PWD"=>"MyPassword");
$conn = sqlsrv_connect("MyServer",$connectionInfo);
if ($conn) {
echo "Connection Established.<br />";
} else {
echo "Something went wrong while connecting to MSSQL.<br />";
}
return $returnable;
}
Any idea on what I might be missing? I tried some very old syntax for version 5, and I got the same issue. I am trying to connect to sql server 2008.
Thanks
First, check if you have installed the sql_srv extension for PHP.
Probably this extension is not installed/loaded by you php.ini file.
For Windows
Download proper driver from SQL Driver for MSSQL extract and copy into you php installation directory. Then edit php.ini file and add in extensions path your extension. (For 99% you should copy NTS sql_srv version) also don't forget add sql_srv_pdo extension.
For Ubuntu/Linux
You can try install sql_srv and pdo_sql_srv by pecl (if is installed)
pecl install sqlsrv pdo_sqlsrv.

PHP & Mongo broken after Mac OSX Mavericks upgrade

Following an OSX 10.9.3 upgrade a number of things didn't work. Apache, Mongo and PHP are all working independently now, however the mongo extension for php is not. I am hoping the stackoverflow community can help. Here's the basic problem:
$ sudo pecl install mongo
pecl/mongo is already installed and is the same as the released version 1.5.3
install failed
$ php --re mongo
Exception: Extension mongo does not exist
Pecl and PHP are having a disagreement on whether the mongo extension is there. mongo.so does physically exist here: /opt/local/lib/php/extensions/no-debug-non-zts-20090626/mongo.so where it was installed and here: /usr/lib/php/extensions/no-debug-non-zts-20100525 where I copied it because that is where php.ini points. It is executable in both places. It seems odd that it is getting installed in the wrong spot, so maybe there is a pecl config that needs to be flipped? Also pecl is not finding php.ini at the end of the install, but I am updating manually.
The best summary of the directions for getting back up after the 10.9 upgrade appears to be here: http://fighterpilotstress.blogspot.com/2013/10/installing-mongodb-driver-with-php-on.html and I have followed it faithfully. I have also installed the commandline tools as referenced here: Unable to install mongodb php driver on mac os 10.9.
Relavent php.ini lines:
include_path = ".:/usr/lib/php/pear"
extension=mongo.so
any help appreciated. Thanks, Brian
I hanged up for a while in the same situation on ubuntu, then I just tried
1) In your phpinfo() screen, make sure the Configuration file Path and Loaded Configuration File match the PHP file you are editing. If not, then find the correct php.ini and add the mongo.so extension.
2) In your phpinfo() screen, look at the extension_dir value and confirm that mongo.so exists in that directory. If not, find the mongo.so file and copy it to this directory.
3) Restart your web server.
4) If it's still not working, take a look at the web server & php logs for clues as to why the extension might not be loading.
from Error enabling MongoDB module
All was ok on my side, but still I kept getting,
$ php --re mongo
Exception: Extension mongo does not exist
then I checked with this test script and was able to connect to mongoDB.
<?php
try {
// open connection to MongoDB server
$conn = new Mongo('localhost');
// access database
$db = $conn->test;
// access collection
$collection = $db->items;
// execute query
// retrieve all documents
$cursor = $collection->find();
// iterate through the result set
// print each document
echo $cursor->count() . ' document(s) found. <br/>';
foreach ($cursor as $obj) {
echo 'Name: ' . $obj['name'] . '<br/>';
echo 'Quantity: ' . $obj['quantity'] . '<br/>';
echo 'Price: ' . $obj['price'] . '<br/>';
echo '<br/>';
}
// disconnect from server
$conn->close();
} catch (MongoConnectionException $e) {
die('Error connecting to MongoDB server');
} catch (MongoException $e) {
die('Error: ' . $e->getMessage());
}
?>
Therefore try the script and if you are able to connect without errors, forget about the extension :).

command line oci OCIEnvNlsCreate() failed

I'm getting PHP Warning: oci_connect(): OCIEnvNlsCreate() failed. when i'm trying to execute php.exe "c:\xampp\htdocs\test.php" from command line....
But if i browse it by (localhost/test || ip/test) browser it works....
Same code and instandclint (INSTANTCLIENT_11_2) version on another same machine works... i'm sure i'm doing something wrong.
basically i want to run a php file from command prompt (schedule run) which will do something and upload the data to oracle server. manually it is working but not from scheduling...
Any help would be great thanks in advance. (right now i'm running that schedule from my demo PC, which working to upload data to LIVE pc where it is not) weird!!!
thanks
Farness
**oci8**
OCI8 Support enabled
Version 1.4.5
Revision $Revision: 305257 $
Active Persistent Connections 0
Active Connections 0
Oracle Instant Client Version 11.1
Temporary Lob support enabled
Collections support enabled
test file
<?php
$i=0;
// include('OraCon.php');
$c = oci_connect('user', 'pass','localhost/BDDBERP.LOCALHOST');
$s = oci_parse($c, "select DEST, DESTCODE from DESTCOUNTRY ORDER BY DEST");
oci_execute($s);
while (($row = oci_fetch_array($s, OCI_BOTH))) {
echo $row['DEST'] . ", ".$row['DESTCODE'].";";
$i++;
}
oci_free_statement($s);
oci_close($c);
?>

OCIEnvNlsCreate() failed. When i try to connect my oracle database in php

phpinfo
_ENV["ORACLE_HOME"] C:\oracle\instantclient_11_2\
_ENV["OS"] Windows_NT
_ENV["Path"] C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\oracle\instantclient_11_2;\;
oci8
OCI8 Support enabled
Version 1.2.5
Revision $Revision: 1.269.2.16.2.43 $
Active Persistent Connections 0
Active Connections 0
Temporary Lob support enabled
Collections support enabled
php code
<?php
$conn = OCILogon('mppd1','mppd1', "121.256.476.86:1521/mydatabase");
$query = 'select * from users';
$stid = OCIParse($conn, $query);
//OCIExecute($stid, OCI_DEFAULT);
while ($succ = OCIFetchInto($stid, $row)) {
foreach ($row as $item) {
echo $item." ";
}
echo "<br>\n";
}
OCILogoff($conn);
?>
i am getting this error
Severity: Warning
Message: ocilogon() [function.ocilogon]: OCIEnvNlsCreate() failed. There is something wrong with your system - please check that PATH includes the directory with Oracle Instant Client libraries
I solved it copying all the content of C:\instantclient_11_2 (please check what´s yours) inside system and system32 folders in Windows , then I delete the path of C:\instantclient_11_2 in the PATH enviroment variable.
I am using XAMPP and Windows 8 and it´s the first time I see this issue. I always configured properly oci 8 with xampp and windows in a few minutes. I hope this would help you.
You need to copy all content of the instant client to apache/bin
im using xampp and working for me.
copy all files of the instant client enter image description here to apache/bin
I was facing the same error on uwamp 3 in connecting to oracle 11gR2.
I deleted the oracle instantclient from path variable and copied all files from instantclient to uwamp\bin\apache\bin
and it worked.
My setup:
System: Windows 7
Instantclient: instantclient-basiclite-win32-11.1.0.7.0
Web Server: Uwamp3
https://forums.oracle.com/forums/message.jspa?messageID=1742926#1745145
There are several potential solutions on that page ranging from re-installing xampp to checking permissions to using native php oci_connect(). Have you tried any of these things?
Probably you should download InstantClient and replace contents of /instantclient folder of Oracle client with the .dll-s of InstantClient.

Categories