Enabling the cURL library for PHP using XAMPP for Windows - php

I am running PHP code with the following code invovled:
$ch = curl_init();
When I get to this line, the following error is returned:
Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\myfiles\API\IPVIKING_API.php on line 79
Now I've found all the answers talking about enabling the curl extension in the php.ini file, and I've done that, following this question here: How to enable curl in xampp?.
My problem is I do not have these 3 files:
C:\Program Files\xampp\apache\bin\php.ini
C:\Program Files\xampp\php\php.ini
C:\Program Files\xampp\php\php4\php.ini
I instead have 2 files called
C:\Program Files\xampp\php\php.ini-development
C:\Program Files\xampp\php\php.ini-production
I've uncommented the
;extension=php_curl.dll
line in both of them, restarted both my browser and xampp, yet it still gives me the same error. Suggestions?

Make an
<?php phpinfo(); ?>
there you can see which php.ini is loaded. In this file you uncomment the the extension line.
When there is no php.ini in this path which is in the phpinfo this should be xampp/php/php.ini then rename one of the two files
C:\Program Files\xampp\php\php.ini-development
to
C:\Program Files\xampp\php\php.ini

You should move C:\Program Files\xampp\php\php.ini-production to C:\Program Files\xampp\php\php.ini.
rename "C:\Program Files\xampp\php\php.ini-production" "C:\Program Files\xampp\php\php.ini"
And then change:
;extension=php_curl.dll
to
extension=php_curl.dll
Then restart Apache.
Some systems require two files to be copied from where PHP is installed to your WINDOWS\System32 directory:
libeay32.dll
ssleay32.dll
Update:
copy "C:\Program Files\xampp\php\php.ini" "C:\xampp\php\php.ini"

search for 'php.ini' file in
xampp\php\ directory
open php.ini
find for 'curl'
you will get line
;extension=php_curl.dll
uncomment it by removing semicolon at front of the line
extension=php_curl.dll

There is a file named php (I think this is the real php.ini) with the type as configuration settings that is the one you need to uncomment extension = php_curl.dll. You should also uncomment the .ini-development and .ini-production. Restart and both browser and apache and it should work.

Related

PHP: mysqli extension doesn't load

I try to use MySQL with PHP and I have this error:
Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in 'file_name Stack trace: #0 {main} thrown in 'file_name'`
When doing print_r( get_defined_functions()), I see that the MySQLi extension isn't there, but it is "loaded" in the php.ini file (I mean this is not in a commentary).
I specify that the PHP directory is in the PATH (I'm under windows) and MySQL, PHP and Apache are on my C: disk.
I don't know where is the problem, this is probably a small thing but I can't see which one so.
My versions are:
Apache 2.4.47
PHP 7.1.7
MySQL 5.7
Windows 7
PS : php_mysqli.dll do only 97k. I don't know if it's normal.
HOW I SOLVED THIS : I have just added extension_dir="path_to_php\ext" under the lines who load extentions, in the php.ini file. This line is used to indicate where are the extentions in your hard disk. Don't forget to restart your server, it will reload the php.ini file.
First of all, run phpinfo() to make sure you are looking at the correct php.ini.
If your php.ini file has extension=php_mysqli.dll uncommented check your extension directory. You may need to set it explicitly, like:
extension_dir="C:\xampp\php\ext"
If the problem persists check the apache error log, you should find more info there.

Windows PHP 5.6 built in server SQLite3

I have PHP 5.6 installed on windows 7 and I used the built in server to run websites locally for testing. I want to connect to a Sqlite3 file and I've uncommented the appropriate lines in the php.ini file in my C:\Program Files\php folder. I still get this error when trying to view the page on my local server: Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\Users\USERX\Documents\pageloadbasic.php:13 Stack trace: #0 C:\Users\USERX\Documents\pageloadbasic.php(13): PDO->__construct('sqlite:db/lhblo...') #1 {main} thrown in C:\Users\USERX\Documents\pageloadbasic.php on line 13
Why do I get this error?
A couple of notes: my phpinfo file shows:
Configuration File (php.ini) Path C:\Windows(for some reason this always defaults to C:\Windows even if there is not php.ini file in there)
Loaded Configuration File C:\Program Files\php\php.ini
But there is no php.ini file in C:\Windows. Also, my php folder does not include a php_pdo.dll in the ext folder, but I added one that I extracted from the pecl-5.0.5-Win32 archive as instructed in some other sites.
I added extension=php_pdo.dll in my php.ini file.
I uncommented extension=php_pdo_sqlite.dll.
I uncommented extension=php_sqlite3.dll.
I have these two lines in my php.ini which related to sqlite:
[sqlite]
; http://php.net/sqlite.assoc-case
;sqlite.assoc_case = 0 (I did not change anything on these two lines because I'm not sure what it is for...)
[sqlite3]
sqlite3.extension_dir = "ext" (on this line I added the "ext" directory as suggested on another post)
I have this in my php code to connect to my db file using pdo:
$db = new PDO('sqlite:db/xxxxx.db');
What am I missing? What do I need to do to get PDO to work with Sqlite3?
Problem solved. Even though I had properly uncommented all my dlls, and uncommented the sqlite3.extension_dir = "ext", you need to specifically uncomment the windows ext location on the line following ; On windows:'
extension_dir = "ext"`
And then restart your server.

include_path related problems in php

I have a PHP application where the autoloader is situated in /var/www/html/example.com/src/vendors/autoloader.php
var/
www/
html/
example.com
app/
vendors/
vendor_a/
example.php
vendor_b/
vendor_c/
autoloader.php
public/
In autoloader.php I have a line that requires example.php from the vedor_a/ folder.
although this works in my local virtual box running centos, php-fpm, nginx it fails to work in my vps, which has the same version of every program I am running in my localhost.
I am using php5.5.14
and I get this error when I require the above file.
Warning: require(vendor_a/example.php): failed to open stream: No such file or directory in /var/www/html/example.com/vendors/autoloader.php on line 2
Fatal error: require(): Failed opening required 'vendor_a/example.php' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/example.com/vendors/autoloader.php on line 2
I haven't modified anything from my php.ini where the include_path defaults to
; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
I am looking more than a solution here. Because I can see the include_path looks for php/includes dir when constructs such as require, include, include_once... at-least according to the manual but I can't find a directory called php/includes so why is that setting even there?

Include_path in php.ini

I'm trying to send mail using PEAR framework (and WAMP).
I installed PEAR and package MAIL and it is in correct folder. Problem is with include_path in php.ini.
When I checked where is my php.ini (php --ini), I have result:
Configuration File (php.ini) Path: C:\Windows
Loaded Configuration File: C:\wamp\bin\php\php5.3.13\php.ini
Scan for additional .ini files in:
Additional .ini files parsed:
In C:\wamp\bin\php\php5.3.13\php.ini I set:
include_path = ".;C:\wamp\bin\php\php5.3.13\pear"
And I restarded WAMP.
After click button to send mail, I have following error:
Warning: include(Mail.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\send_mail.php on line 2
Warning: include() [function.include]: Failed opening 'Mail.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\send_mail.php on line 2
Fatal error: Class 'Mail' not found in C:\wamp\www\send_mail.php on line 45
No idea, why include_path is here '.;C:\php\pear'.
Mike B told me to look at your phpinfo() to know exactly what ini file(s) are being used. The file was differ between cli and apache calls (php --ini is misleading).

Why won't PEAR work on my PHP Windows installation?

I'm running Wampserver on Windows 7, and I can't seem to get PEAR to work. Well, that's
not entirely true-apparently it works on the command line (both cmd.exe and on Cygwin).
Here's the sample program I found on PHP.Net that shows you if PEAR is installed:
<?PHP
require_once 'System.php';
var_dump(class_exists('System', false));
?>
On the command line, it returns "bool(true)", and in the browser I get
Warning: require_once(System.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\foobar.php on line 3
Fatal error: require_once() [function.require]: Failed opening required 'System.php' (include_path='.;C:\php\pear') in C:\wamp\www\foobar.php on line 3
I'm honestly not sure what I'm doing wrong. It seems like both should work, but I'm stumped.
Thanks.
Looks like your apache (or other webserver) is picking up wrong php.ini.
Make a page with a call to phpinfo()
Load the page in browser
Check the PHP.ini path its using.
Copy your proper php.ini to that location.
Based on your comments, it looks like your include_path is wrong. Go change your PHP.ini and set your include path to:
include_path = ".;C:\wamp\bin\php\php5.3.10\pear"

Categories