OpenSSL enabled but not working - php

I am running Apache 2.2.13 and PHP 5.2.12. Just installed PHP 5.2.12 manually (to have access to all extensions) and enabled OpenSSL. phpinfo() indicates OpenSSL is enabled and running OpenSSL 0.9.8k 25 Mar 2009.
I'm getting this error: PHP Fatal error: Call to undefined function ftp_ssl_connect().
I've seen where the PHP manual suggests 'ftp_ssl_connect() is only available if both the ftp module and the OpenSSL support is built statically into php' and further states that 'you must compile your own PHP binaries' to make it work with Windows.
I have the suspicion that phpinfo() only indicates OpenSSL as being 'enabled' because I have uncommented the line 'extension=php_openssl.dll' and have the correct dlls in the correct folders and the correct path in the environment variables. And perhaps a static build into PHP must be accomplished regardless of what phpinfo() indicates.
I believe the objective of distribution (as described above) is for dynamic extensions, but recompiling (for OpenSSL) is to encode a static extension.
ftp extension is working fine (built into PHP 5.2). I test this with the following code:
$conn_id = ftp_connect($url);
$login_result = ftp_login($conn_id, $username, $password);
ftp_close($conn_id);
Note that to check ssl, I only change ftp_connect to ftp_ssl_connect. When reaching this line, I get the PHP error above in my Apache error log file.

As the documentation states (quoting what you already quoted) :
Note: Why this function may not exist
ftp_ssl_connect() is only
available if both the ftp module and
the OpenSSL support is built
statically into php, this means that
on Windows this function will be
undefined in the official PHP builds.
To make this function available
on Windows you must compile your own
PHP binaries.
You say you installed PHP "manually" ; but this probably still means you used an "official" build from php.net -- which means you have not compiled your own PHP binaries... So, that function is not available.
There is no magic : it seems you'll have to re-compile PHP, using the right configuration options at compile-time, if you want to be able to use that function...
Here's some documentation about that : Build your own PHP on Windows -- but... good luck... i've never heard it was "simple" to compile PHP on windows, actually (it's not that hard on Linux, but Linux is maybe a bit more well suited when it comes to compilation)
A couple of other solutions :
switching to Linux for your developments (even if it's only using a Virtual Machine) -- but you might still have to recompile PHP to get that (might not be enabled by default)
just not using that function ; after all, do you know if your hosting service will provide you with it ? (If you can't use it on your production server, no need to use on your development/testing machine)

Related

PHP seems to ignore the default OpenSSL config

I need to change the OpenSSL config used by PHPs openssl* methods. phpinfo() reports the default openssl config as present in /etc/ssl/openssl.cnf. However, it does not seem to use it.
I changed the openssl.cnf to have some invalid values in it. Running openssl from the shell righfully fails and complains about an invalid config. The openssl* methods in my PHP script still continue to work?! They should fail with the same error message.
So, what OpenSSL config is PHP actually using?
PHP is running as Apache2 module in an Alpine Linux Docker Container (Package php81-apache2)
There seems to be some caching involved (have to investigate later). After letting the system sit for a few hours the PHP methods used the changed configuration.

PHP open_ssl, ftp_ssl_connect on Windows

I have a function in php that needs to connect to ftp using ftp_ssl_connect. Iam using windows seven and as per the answers from google I need to rebuild the php to include the ssl functions. Now my question if is there a way to enable ssl on Windows without rebuilding php? Or is there a donwloadable version where ssl already included for windows?
thanks
From PHP doc:
Note: Why this function may not exist
ftp_ssl_connect() is only available if both the ftp module and the
OpenSSL support is built statically into php, this means that on
Windows this function will be undefined in the official PHP builds. To
make this function available on Windows you must compile your own PHP
binaries.
Emphasis mine.
However, I've downloaded PHP binary for windows from official php.net and I noticed there's a specific DLL (ext/php_openssl.dll) for openssl. It means maybe it's not necessary rebuild PHP in order to get openssl working. Just remember add an entry for the dll in php.ini file.
It should be something like this:
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"
...
extension=php_openssl.dll
NOTE
I haven't tested the above case.
As of PHP 7.0, the core FTP extension on Windows is by default built with OpenSSL support. In the earlier PHP versions, while SSL support is possible, it is not provided with the standard builds for various reasons. The only solution for PHP 5 is to make a custom build of PHP, while the standard PHP 7.0 builds on windows.php.net provide the ftp_ssl_connect() function.
Thanks.

PHP 7.0 ODBC-Driver for Windows

I upgraded my PHP 5.6.30 (https://www.apachefriends.org/de/download.html) to PHP 7.0 (https://bitnami.com/stack/wamp/installer)
Everything worked fine so far and it reduces the loading time from my Page from 1,2 seconds to ~300 ms, when I use a MySQL-Database. But now I'm trying to connect to a MSSQL-Database with the following simple script, that worked fine with my old installation (PHP 5.6):
<?php
//Use the machine name and instance if multiple instances are used
$server = 'Server-Adress';
$user = '';
$pass = '';
//Define Port
$port='Port=1433';
$database = 'Databasename';
$connection_string = "DRIVER={SQL Server};SERVER=$server;$port;DATABASE=$database";
$conn = odbc_connect($connection_string,$user,$pass);
if ($conn) {
echo "Connection established.";
} else{
die("Connection could not be established.");
}
$sql = "SELECT * FROM st3_200 WHERE identifier = 1";
$result = odbc_exec($conn,$sql);
// Get Data From Result
while ($data[] = odbc_fetch_array($result));
// Free Result
odbc_free_result($result);
// Close Connection
odbc_close($conn);
// Show data
print_r($data);
?>
But now I got an error in my logs that says:
[Thu Dec 10 11:55:26.629956 2015] [:error] [pid 260:tid 968] [client
::1:63003] PHP Fatal error: Uncaught Error: Call to undefined
function odbc_connect() in
C:\Bitnami\wampstack-7.0.0-0\apache2\htdocs\test\query.php:11\nStack
trace:\n#0 {main}\n thrown in
C:\Bitnami\wampstack-7.0.0-0\apache2\htdocs\test\query.php on
line 11
First I thought, that my php.ini has a missing extension, so I enabled "extension=php_pdo_odbc.dll"
the difference from the php.ini in the 5.6 version is there is the extension:
"extension=php_mssql.dll" enabled. But I can't find them in the new PHP 7.0.ini
So my intension is there is no existing driver for odbc and PHP 7 yet?
I found some driver for Linux here:
https://aur.archlinux.org/packages/php7-odbc/
But I need something for my Windows environment.
Does anyone had the same issue and has already fixed it?
Thank und Greeting
Domi
Take a look in your php.ini, the string
extension=php_odbc.dll
seems to be missing in new installations, at least i had to add it manually in my new XAMPP installation (7.0.1)
and accidently just activated the pdo_odbc.dll
PHP7 has a few modules disabled by default that were previously enabled in PHP5.
It's an easy fix though since the extension should already exist in the \ext\ folder that came with PHP7. You just need to modify your php.ini file to include the line:
extension=php_odbc.dll
The line above is not already present and commented out; you actually need to add it!
PHP looks for the php.ini file in C:\Windows\ but it may also be located elsewhere on your machine. So check both C:\Windows\ and C:\php\ or where ever else you may have installed PHP.
After making the change you can check the results from the command line like this:
C:\php\php.exe -m
or (after restarting the web server / machine) from a .phtml file like this:
<? phpinfo(); ?>
That will output a list of enabled modules which should now include odbc; if not, then you may have modified the wrong php.ini file (keep looking) or forgot to restart the web server / machine.
Tips:
If you have a non-standard installation, you can use an absolute path like this:
extension=C:\php7x64\ext\php_odbc.dll
extension=php_mssql.dll (or extension=php_sqlsrv_56_nts.dll if you get it from Microsoft Drivers for PHP), is your problem: the Microsoft SQL driver for PHP 7 is not yet ready, the latest ETA is late January for the beta.
It looks like the cause of the delay is the intention to include SQL 2016 in that driver so you can migrate easier in the future.
UPDATE (2016/02/12):
As stated here (meet-bhagdev reply), there is an "early technical preview" of the PHP sqlsrv driver for Windows available on github.
Open your php.ini file and uncomment or add the following lines:
extension_dir = "C:\PHP\ext" ;<- your PHP path
extension=php_pdo_odbc.dll
extension=php_odbc.dll
Reset Internet Information Services:
On command prompt with admin rights type:
iisreset
This fixed the problem for me.
As an addition to Adrian B`s which mentions the official driver, you can also check https://github.com/thomsonreuters/msphpsql
This is an unofficial port. However there are limitations for the time being.
Supports only sqlsrv ODBC but not PDO
Doesn`t support ZTS, only NTS
Supports only x86
It supports a subset of ODBC functions , you can see the list on the page.
We need x86 driver from Microsoft.
http://www.microsoft.com/ja-jp/download/details.aspx?id=13255
*Sorry, 'ja-jp' is mine. Please select your country. There are 2 drivers, one is 32bit, but we need 64bit(x86) version.
Then we could set "ODBC data source (64bit)". It appears on the window.
Last, check your web. Maybe it works.
Mar. 29th. 2016 Naio
I guess you was right, you need download the SQL Server ODBC driver for your PHP client platform and OS.
Here is the link for the similar issue: Call to undefined function odbc_connect()
also you can try to install this connector for MySQL (if you use MySQL): Connector/ODBC
or if you use MSSQL: ODBC Driver 11 for SQL Server
I know this question is rather old. But I've come across the same issue recently ...
#Naio is right : there are indeed different versions of ODBC drivers, based on the architecture (32bits or 64bits). The driver that PHP uses depends on its own version.
In other words, if you are using a 32bits ODBC environement, make sure to use a 32bits version of PHP ...
My guess is that, by switching from PHP 5.6 to PHP 7.0 you also switched from a 32bits version to a 64bits version.

enable curl in xampp, windows

trying to enable curl in xampp 3.0.12 in windows environment.
Updated the php.ini in the php folder to enable curl, and there is no php.ini file in the apache/bin folder.
phpinfo() says:
loaded configuration file: C:\xampp\php\php.ini
curl support:enbaled
curl information: 7.24.0
and when i try to run a http_get() command php says:
Fatal error: Call to undefined function http_get()
Restarted both windows and xampp several times to update the changes.
Would be grateful for some advice, as I searched through similar topics on the web but can't get any further.
Note that the function http_get() belongs to the pecl http extension and not to the curl extension. Refer to the documentation of the curl extension to learn how you can use it to retrieve documents via http. You'll also find a lot of posts on stackoverflow
Also note, that the function file_get_contents() can be used to get documents over http in a very simple way. Although it is limited it will fit in much cases. To retrieve a page you can issue:
file_get_contents('http://www.server.com/page.html');

PHP SOAP cannot connect to an SSL WSDL source

Trying to make Soap connection to a https:// WSDL source via PHP/Win32, but keep getting the error:
Warning: SoapClient::SoapClient() [soapclient.soapclient]: I/O warning
: failed to load external entity "https://...
If I try to save the WSDL locally and access it then, the SoapFault->faultstring property has the message "SSL support is not available in this build".
After some Googling, seems like PHP SOAP cannot connect to a HTTPS source. HTTP is OK, though.
Is there a workaround for this? Or is there an alternative SOAP version/module I can install?
HTTPS support for SOAP in PHP5
If you’re seeing error messages about missing https wrappers when trying to use SOAP (”Unable to find the wrapper “https” – did you forget to enable it when you configured PHP?” or “[HTTP] SSL support is not available in this build”), you haven’t installed the SSL libraries to support secure transactions.
Uncomment
extension=php_soap.dll
in your php.ini
Uncomment
extension=php_openssl.dll
in your php.ini
Copy
ssleay32.dll
and
libeay32.dll
to your windows system32 directory
Reboot apache, et voila!
I originally found this answer at: http://webponce.com/rants/2008/04/https-support-for-soap-in-php5-under-windows/
I had the same problem. openSSL, cURL were enabled, initiated a SoapClient with option of location to stored certificated, etc, etc.. tried everything.
Turns out it does work in CLI mode. Thus php_sapi = CLI.
As we almost always run our webservices calls as a cronjob, scheduled task in Windows, this is not really a bad thing. I was really glad to get it working!
Update:
Okay, turns out when PHP is running as an Apache module, it uses the by opensll required libraries libeay32.dll and ssleay32.dll from the Apache install. When using PHP in CLI is uses the libraries from the PHP directory/install. Overwriting the 2 Apache dlls with the dlls from the PHP directory did the trick. It now also runs under Apache.
So your PHP version should match with the working dlls for the specific version. When it still doesn't work in the web interface. Please check that Apache isn't loading these dlls from a Windows System directory, specified earlier in your system defined path, which is picked up by Apache.
I've had success with SSL and SOAP using NuSOAP:
http://nusoap.sourceforge.net/

Categories