PHP cURL works locally, missing on Apache server - php

PHP Version 7.2.1
Apache Version: Apache/2.4.29 (Win64) OpenSSL/1.0.2n PHP/7.2.1
OS: Windows Server 2012 R2
I enabled cURL in my php.ini file.
When I try to load modules in console: php -m
I got:
There we can see that cURL is loaded and it is working when I use php [script path] command
But cURL is not loaded on my Apache Server
i have info.php page which contains:
<?php
if(in_array ('curl', get_loaded_extensions())) {
echo "CURL is available on your web server\n";
}
else{
echo "CURL is not available on your web server\n";
}
print_r(get_loaded_extensions());
phpinfo();
?>
Which tell if cURL is in loaded extensions, write them down, and show classic php info details.
This is output:
There is no cURL in loaded extension. But if you check php.ini file it is C:/PHP/php.ini <- one i changed (removed ";" to enable extension.)
And when I try to run cURL commands from server I get:
Fatal error: Uncaught Error: Call to undefined function curl_multi_init() in C:\web\databaseservers\generate-db-server-stats2.php:27 Stack trace: #0 {main} thrown in C:\web\databaseservers\generate-db-server-stats2.php on line 27
(This script works locally.)
Where can be problem?
Edit1:
Adding snippet from my php.ini
There you can see that file i am editing is correct one (Path above)
And that curl is enabled as extension (PHP7.2 and above doesn't require prepone "php_" and postpone ".dll")
EDIT2:
Fixed :
for PHP7 ... I added php dir path in system enviroment varible, deleted libeay32.dll and ssleay32.dll from apache/bin, keep these dll in php directory and its work. – Wasim A. Mar 17 at 19:10
Linked topic helped

Related

Php, "call to undefined function curl_init()" in browser BUT works fine on cmd

I have a simple test code:
<?php
var_dump(curl_init());
echo '.';
if I run it on command line (Windows 10) I get the expected result:
php.exe test.php
resource(4) of type (curl) .
very fine. But when Im running this file from browser (set to Apache rootdir).
Fatal error: Uncaught Error: Call to undefined function curl_init() in
Im speachless. For legacy reasons, this is php 7.04 (on 7.2, 7.4, 8.1 everything is fine).
The php.ini does work. Of course "extension=php_curl.dll" is enabled. When I change something, for example "max_execution_time = 300", the php_info(); also reinforcements me that these settings are taken into account.
However, the strange thing is what php_info() is saying:
cURL Sterling Hughes
nothing more for curl!
EDIT:
I tried the same with "extension=php_gd2.dll" and it does work if I remove/readd it, phpinfo shows that correctly!
This is because the php folder is not in your system PATH (not user), Apache doesn't know where to search dlls. The easiest way is adding php folder to PATH.
If you doesn't want to do that, you probably need set extension_dir to the full path of your extension folder in php.ini. for example:
extension_dir = "D:\Program Files\php-7.04-ts\ext"
cURL extension needs openssl to work. and you can also find these dlls in php folder, just copy them to Windows or system32 folder. According to RiggsFolly's comment you can copy these required dlls to Apache\bin folder.
libssl-1_1-x64.dll / libeay32.dll
libcrypto-1_1-x64.dll / ssleay32.dll
libssh2.dll

php pg_connect() works in terminal but not in the browser

<?php
echo "Inside php file!<br>";
$dbconn = pg_connect("host=localhost dbname=atharvacm user=atharvacm port=5432 password=Dominicmcs9") or die("Cannot connect to DB");
echo "after con<br>";
$query = "select * from person;";
$result = pg_query($dbconn, $query) or die("cannot exec query");
while ($answer = pg_fetch_row($result)) {
echo $answer[0];
echo $answer[1];
echo " huh<br>";
}
echo "<br>end";
?>
this is the code im trying to execute. It outputs the records in the table person in terminal but in the browser it only echoes "Inside php file" and nothing after it.
Here is the terminal output:
atharvacm#kali:/var/www/html$ php psqltest.php
Inside php file!<br>after con<br>1abc huh<br>2def huh<br>3pqr huh<br>4xyz huh<br><br>end
atharvacm#kali:/var/www/html$
Here is the output from the web browser
Inside php file!
Fatal error: Uncaught Error: Call to undefined function pg_connect() in /var/www/html/psqltest.php:4 Stack trace: #0 {main} thrown in /var/www/html/psqltest.php on line 4
I have kali linux and running apache2, psql, php7.
I installed the php-pgsql package and uncommented the extention in the php.ini file.
I cant seem to figure out what the problem is but my guess is that the pg_connect function is not finding the psql database or something form the browser.
thanks!
Please check the config.ini file of ur php configuration file "php.ini" within Apache Tomcat
In some case the software is not configured for psql
So go in the file and uncomment the line
Extension= pgsql
Also enable ur error log in Apache
U can refer
Please check the config.ini file of ur php configuration file "php.ini" within Apache Tomcat
In some case the software is not configured for psql
So go in the file and uncomment the line
Extension= pgsql
Also enable ur error log in Apache
U can refer
Please check the config.ini file of ur php configuration file "php.ini" within Apache Tomcat
In some case the software is not configured for psql
So go in the file and uncomment the line
Extension= pgsql
Also enable ur error log in Apache
U can refer
Please check the config.ini file of ur php configuration file "php.ini" within Apache Tomcat
In some case the software is not configured for psql
So go in the file and uncomment the line
Extension= pgsql
Also enable ur error log in Apache
U can refer
How do I get PHP errors to display?

PDO will not run since upgrading PHP to 5.4.22

I just recently upgraded my server's PHP version to 5.4.22, and now every script that uses PDO does not work.
An example of my PHP script which won't work:
<?php
$dsn = 'mysql:dbname=testDB;host=127.0.0.1';
$user = '[hidden]';
$password = '[hidden]';
try {
$pdo = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit;
}
?>
When i run the script i get: Fatal error: Class 'PDO' not found, i get this same error for every script that creates a connection.
I ran a check on puTTY to check PDO was even there and it found this:
root#cpanel [~]# php -m | grep -i pdo
PDO
pdo_mysql
pdo_sqlite
My php.ini has
extension=pdo.so
extension=pdo_sqlite.so
; sqlite was removed by EasyApache v3.22.24 on Sat Dec 14 23:24:10 2013 (PHP v5.4.x incompatibility)
; extension=sqlite.so
extension=pdo_mysql.so
phpinfo(); in PHP file claims im on PHP Version 5.3.10
How ever in my terminal # php -v says PHP 5.4.22
So this had really confused me why i'm getting two versions.
Your question shows that you are checking the PHP version via the command line. But PHP via a web browser is going to use a module loaded into Apache which is a completely different thing. So check the output of phpinfo(); in a PHP script loaded via the web browser. Is PDO installed or shows as installed via that?
Wherever your Apache config files are look for the directory mods-available and the file php5.load. Under Ubuntu 12.04 it would be in this path:
/etc/apache2/mods-available/php5.load
And the contents should be:
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
Does the path in that file match where the newly compiled libphp5.so is installed?
Also, that LoadModule php5_module line could be a part of your main Apache configuration. Look around to find where that is set. And then just set the path of the new module to me wherever it’s actually installed.

Install ingres extension for php on my WAMP server

I've a development computer, which runs under windows.
For a project, I've to make a php website which has to connect to an Ingres database server.
So I installed wamp, I installed ingres(server and client, on my local machine).
I added the library that I found on their site(php_ingres.dll) in the C:\wamp\bin\php\php5.3.5\ext folder, and I added a line "extension=php_ingres.dll" in the configuration file.
I shutdown wamp and restarted it, and I restarted the server, I see now a check mark in the wamp menu, indicating that php_ingres is now activated. But when I go to the welcome page of the server, I don't see this extension as loaded. If I go on the php info page, I don't see any Ingres entry in the Configure Command.
I just can't found any post/tutorial/... which indicating how to do this operation, so any help would be appreciated!
Thank you!
Edit: I made a small test to see if I can connect to an Ingres database:
<?php
$link = ingres_connect("localhost", "demodbtest", "demodbtest") or die("Connexion impossible");
echo "Connexion réussie";
$result = ingres_query($link,"select * from airline");
while ($row = ingres_fetch_array($result)) {
echo $row["al_iatacode"]; // utilisation du tableau associatif
echo $row["al_name"];
echo $row["al_ccode"]; // utilisation du tableau à indices numériques
echo "</br>";
}
ingres_close($link);
?>
And I get this error:
( ! ) Fatal error: Call to undefined function ingres_connect() in
C:\wamp\www\tests\index.php on line 2
Some information on my installation:
I've a windows 7 pro 32bits
Wampserver 2.1 ( http://sourceforge.net/projects/wampserver/files/WampServer%202/WampServer%202.1/WampServer2.1e-x32.exe/download )
Apache 2.2.17
PHP 5.3.5
Ingres 10.1.0 Community edition( downloaded here: http://esd.ingres.com/product/Community_Projects/Ingres_Database/Windows_32-Bit/Ingres_10.1_Build_121/ingres-10.1.0-121-gpl-win-x86-NoDoc.zip/http )
PHP drivers downloaded here: http://esd.ingres.com/product/drivers/PHP/Windows_32-Bit/PHP_Driver
To practically test if the extension was loaded you can as well call one of it's functions. If the extension was loaded, you should not get a fatal error for a missing function. That's perhaps one of the quickest checks.
Another check is to make use of extension_loaded *PHP Manual** which will give you a list of all loaded extensions. See the PHP Manual link above for more info.
The configure line
The configure line will not show the ingres extension because it has not been compiled in. That's perfectly alright because you load it as an extension (.dll) so it's not part of php.exe. This is why you don't see it in the configure line.
Locating ingres on the phpinfo() page.
On the phpinfo()-page use the search function inside your browser (often CTRL+F) and try to locate the word ingres. You should locate a section that displays the extensions default settings if it has been loaded.
The following is an example screenshot for the xdebug extension. This might look similar for ingres:
Image from: Launching xdebug in Eclipse stuck at 57% - How to trouble-shoot?
Double check your extension_dir setting as well as the actual php.ini file being used. Calling php.exe -i from the command line might not give the same output if executing phpinfo() in a script via Apache (or IIS). In fact http://www.wampserver.com/en/faq.php says there are 3 potential php.ini scripts.
The problem is that I wasn't having the ingres client installed locally, so it appears that this lib cannot works without it

PHP Extension (memcache|memcached) not showing in phpinfo() but showing in php -m and php -i?

I am getting both modules listed as installed / configured when I use:
php -m
or if I use:
php -i
but when I use:
$m = new Memcache;
// or
$m = new Memcache();
// or
$m = new Memcached();
//or
$m = new Memcached;
I get the following error:
Fatal error: Class 'Memcached' not found
I am running on a Mac - OS X (10.5.7) with default install of apache & php. Additionally, I have memcached running as a daemon on 127.0.0.1:11211 and libmemcache as required by the php-memcached library. I have restarted apache tons of times and even done a machine restart.
Does anyone know why the modules/extensions show up in the command line but not in my phpinfo()? I am literally stumped, after 3 hours of googling, I am just about ready to give up.
Also, please note, my phpinfo() outputs my ini files as follows AND they are both the exact same file:
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /private/etc/php.ini
UPDATE:
Apache is failing to load the extension.
[Fri May 14 04:22:26 2010] [warn]
Init: Session Cache is not configured
[hint: SSLSessionCache] PHP Warning:
PHP Startup: Unable to load dynamic
library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcached.so'
- (null) in Unknown on line 0 PHP Warning: PHP Startup: Unable to load
dynamic library
'/usr/lib/php/extensions/no-debug-non-zts-20060613/memcache.so'
- (null) in Unknown on line 0
Does anyone know why or how this would happen? Both of the files referenced above DEFINITELY ARE there. Should I move this question to server fault?
Your webserver is probably using mod_php, which is a seperate bit of code from the standalone (CLI) interpreter. If they are both using the same ini file, and the memcache extension is configured in the ini file, then it sounds like for some reason, the mod_php is failing to load the extension - check your webserver error_log for startup errors.
It may be that the mod_php was compiled without memcache support (most extensions need to have a stub file linked into the php code, even though the bulk of the code is not linked until run time). Or it may be a permissions problem on the shared object file. Or your webserver may be running chroot, and unable to find the extension (which would also mean that although the ini files appear to have the same path, this is relative to different roots).
HTH
C.
because both versions use different php.ini
place your php.ini into location noted in the phpinfo() outout
I would suspect that the issue revolves around permissions. When you run php from comand line, it runs as the user invoking it. When run as an apache module, it runs as "nobody".
I would assume that the memcached.so file, or the directory it's in does not have proper permissions.
I stumpled upon this post and was having the exact same problem with an extension in my php -i but not in phpinfo(). Mine was a permissions problem because of selinux on a CentOS machine. I had to change ownership and permissions and now it is working as expected.
Set php path in environment variables as given below.
Right-click on "My Computer"
Properties
Advanced Tab > Environment Variables
Under System variables, scroll down to find "Path", select and click on Edit.
Add path to your php install on the end (make sure to precede with semi-colon ";"). Example: ";C:\php7"
Click Ok.

Categories