Ошибка call to undefined function curl init

I try PHP Post Request inside a POST Request thinking it might be useful for me. My code is given below:

$sub_req_url = "http://localhost/index1.php";

$ch = curl_init($sub_req_url);
$encoded = '';

// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

foreach($_POST as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

// chop off last ampersand
$encoded = substr($encoded, 0, strlen($encoded)-1);

curl_setopt($ch, CURLOPT_POSTFIELDS,  $encoded);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec($ch);
curl_close($ch);

from the index.php file and index2.php is another file in the same directory and when I open the page I get the following error in my error.log file:

[Sat Dec 18 15:24:53 2010] [error] [client ::1] PHP Fatal error: Call to undefined function curl_init() in /var/www/testing1/index.php on line 5

What I want to do is to have a reservation form that send post request. Then I want to process post values and send again the post request to paypal.

Uwe Keim's user avatar

Uwe Keim

39.3k56 gold badges174 silver badges291 bronze badges

asked Dec 18, 2010 at 9:45

S L's user avatar

3

You need to install CURL support for php.

In Ubuntu you can install it via

sudo apt-get install php5-curl

If you’re using apt-get then you won’t need to edit any PHP configuration, but you will need to restart your Apache.

sudo /etc/init.d/apache2 restart

If you’re still getting issues, then try and use phpinfo() to make sure that CURL is listed as installed. (If it isn’t, then you may need to open another question, asking why your packages aren’t installing.)

There is an installation manual in the PHP CURL documentation.

Shane's user avatar

Shane

1,0052 gold badges12 silver badges31 bronze badges

answered Dec 18, 2010 at 9:48

RusAlex's user avatar

RusAlexRusAlex

8,1856 gold badges35 silver badges44 bronze badges

7

For Windows, if anybody is interested, uncomment the following line (by removing the ;) from php.ini

;extension=php_curl.dll

Restart apache server.

answered Jun 30, 2013 at 15:39

Kanda's user avatar

KandaKanda

2793 silver badges6 bronze badges

3

For Ubuntu:
add extension=php_curl.so to php.ini to enable, if necessary. Then sudo service apache2 restart

this is generally taken care of automatically, but there are situations — eg, in shared development environments — where it can become necessary to re-enable manually.

The thumbprint will match all three of these conditions:

  1. Fatal Error on curl_init() call
  2. in php_info, you will see the curl module author (indicating curl is installed and available)
  3. also in php_info, you will see no curl config block (indicating curl wasn’t loaded)

answered Mar 15, 2015 at 13:28

Kevin Ard's user avatar

Kevin ArdKevin Ard

5944 silver badges12 bronze badges

In my case, in Xubuntu, I had to install libcurl3 libcurl3-dev libraries. With this command everything worked:

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl

answered Jan 30, 2015 at 17:05

lightbyte's user avatar

lightbytelightbyte

5664 silver badges10 bronze badges

Just adding my answer for the case where there are multiple versions of PHP installed in your system, and you are sure that you have already installed the php-curl package, and yet Apache is still giving you the same error.

curl_init() undefined even if php-curl is enabled in Php 7.

answered Feb 18, 2017 at 5:33

ultrajohn's user avatar

ultrajohnultrajohn

2,4974 gold badges31 silver badges56 bronze badges

To fix this bug, I did:

  1. In php.ini file, uncomment this line: extension=php_curl.dll
  2. In php.ini file, uncomment this line: extension_dir = "ext"
  3. I restarted NETBEANS, as I was using Built-in server

JasonMArcher's user avatar

JasonMArcher

14k22 gold badges56 silver badges52 bronze badges

answered Oct 31, 2014 at 17:17

Rajat26's user avatar

1

I got this error using PHP7 / Apache 2.4 on a windows platform. curl_init worked from CLI but not with Apache 2.4. I resolved it by adding LoadFile directives for libeay32.dll and ssleay32.dll:

LoadFile "C:/path/to/Php7/libeay32.dll"
LoadFile "C:/path/to/Php7/ssleay32.dll"
LoadFile "C:/path/to/Php7/php7ts.dll"
LoadModule php7_module "C:/path/to/Php7/php7apache2_4.dll"

answered Feb 8, 2016 at 11:12

fishbone's user avatar

fishbonefishbone

3,1302 gold badges36 silver badges50 bronze badges

This answer is for https request:

Curl doesn’t have built-in root certificates (like most modern browser do). You need to explicitly point it to a cacert.pem file:

  curl_setopt($ch, CURLOPT_CAINFO, '/path/to/cert/file/cacert.pem');

Without this, curl cannot verify the certificate sent back via ssl. This same root certificate file can be used every time you use SSL in curl.

You can get the cacert.pem file here: http://curl.haxx.se/docs/caextract.html

Reference PHP cURL Not Working with HTTPS

Community's user avatar

answered Feb 17, 2017 at 8:58

Amit Garg's user avatar

Amit GargAmit Garg

3,8471 gold badge27 silver badges37 bronze badges

Step 1 :

C:/(path to php folder)/php.ini
enable extension=php_curl.dll

(remove the ; at the end of the line)

Step 2 :

Add this to Apache/conf/httpd.conf (libeay32.dll, ssleay32.dll, libssh2.dll find directly in php7 folder)

# load curl and open ssl libraries
 LoadFile "C:/(path to php folder)/libeay32.dll"
 LoadFile "C:/(path to php folder)/ssleay32.dll"
 LoadFile "C:/(path to php folder)/libssh2.dll"

il_raffa's user avatar

il_raffa

5,090125 gold badges31 silver badges34 bronze badges

answered Apr 10, 2018 at 7:24

Hiruna De Alwis's user avatar

1

On newer versions of PHP on Windows, like PHP 7.x, the corresponding configuration lines suggested on previous answers here, have changed. You need to uncomment (remove the ; at the beginning of the line) the following line:

extension_dir = "ext"
extension=curl

Uwe Keim's user avatar

Uwe Keim

39.3k56 gold badges174 silver badges291 bronze badges

answered Aug 18, 2020 at 2:02

Vitox's user avatar

VitoxVitox

3,71229 silver badges30 bronze badges

1

(Trying to get Curl working via PHP and Apache on Windows…)

I kept getting an error saying:
Call to undefined function ‘curl_init()’

I made sure I had enabled curl with this line in my php.ini file:
extension=php_curl.dll

I made sure the extension_dir variable was being set properly, like this:
extension_dir = «ext»

I was doing everything everyone else said on the forums and curl was not showing up in my call to phpinfo(), and I kept getting that same error from above.

Finally I found out that Apache by default looks for php.ini in the C:Windows folder. I had been changing php.ini in my PHP installation folder. Once I copied my php.ini into C:Windows, everything worked.

Took me forever to figure that out, so thought I’d post in case it helps someone else.

answered Jul 4, 2014 at 3:50

jessejuicer's user avatar

jessejuicerjessejuicer

1073 silver badges10 bronze badges

For PHP 7 and Windows x64

libeay32.dll, libssh2.dll and ssleay32.dll should not be in apache/bin and should only exist in php directory and add php directory in system environment variable. This work for me.

Obvisouly in php.ini you should have enable php_curl.dll as well.

answered Mar 17, 2018 at 19:14

Wasim A.'s user avatar

Wasim A.Wasim A.

9,62022 gold badges90 silver badges120 bronze badges

1

RusAlex answer is right in that for Apache you have to install and enable curl and restart your apache service:

sudo apt-get install php5-curl
sudo service apache2 restart

On my Ubuntu Server with nginx and php5-fpm I however ran into the following problem. I had to restart nginx and php5-fpm like so:

sudo service nginx restart
sudo service php5-fpm restart

But I had non-working php5-fpm processes hanging around, which apparently is a bug in ubuntu https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1242376
So I had to kill all idle php5-fpm processes to able to restart php5-fpm so that the curl module is actually loaded

sudo kill <Process Id of php5-fpm Process)

answered Jul 20, 2014 at 2:15

Pascal Klein's user avatar

Pascal KleinPascal Klein

23.4k24 gold badges82 silver badges119 bronze badges

function curl_int();
cause server error,install sudo apt-get install php5-curl
restart apache2 server .. it will work like charm

answered Mar 12, 2016 at 8:21

Rajesh Kumar's user avatar

For linux you can install it via

sudo apt-get install php5-curl

For Windows(removing the ;) from php.ini

;extension=php_curl.dll

Restart apache server.

answered May 13, 2019 at 8:31

Mohsen Zamani's user avatar

On Ubuntu 18.04 these two commands solve my this problem.

sudo apt-get install php5.6-curl //install curl for php 5.6
sudo service apache2 restart //restart apache

answered Jun 21, 2019 at 10:35

Atul Baldaniya's user avatar

Seems you haven’t installed the Curl on your server.
Check the PHP version of your server and run the following command to install the curl.

sudo apt-get install php7.2-curl

Then restart the apache service by using the following command.

sudo service apache2 restart

Replace 7.2 with your PHP version.

Giulio Caccin's user avatar

answered Sep 16, 2019 at 8:39

Varun P V's user avatar

Varun P VVarun P V

1,0811 gold badge12 silver badges30 bronze badges

I also faced this issue. My Operating system is Ubuntu 18.04 and my PHP version is PHP 7.2.

Here’s how I solved it:

Install CURL on Ubuntu Server:

sudo apt-get install curl

Add the PHP CURL repository below to your sources list:

sudo add-apt-repository ppa:ondrej/php

Refresh your package database

sudo apt update

Install PHP-curl 7.2

sudo apt install php7.2-fpm php7.2-gd php7.2-curl php7.2-mysql php7.2-dev php7.2-cli php7.2-common php7.2-mbstring php7.2-intl php7.2-zip php7.2-bcmath

Restart Apache Server

sudo systemctl restart apache2

That’s all.

I hope this helps

answered Jan 10, 2020 at 16:19

Promise Preston's user avatar

Promise PrestonPromise Preston

23k12 gold badges137 silver badges140 bronze badges

Yet another answer …
If you land here in Oct 2020 because PHP on the command line (CLI) has stopped working, guess what … some upgrades will move you to a different/newer version of PHP silently, without asking!

Run:
php --version and you might be surprised to see what version the CLI is running.

Then run:
ll /usr/bin/php and you might be surprised to see where this is linking to.

It’s best to reference the SPECIFIC version of PHP you want when calling the PHP binary directly and not a symbolic link.

Example:

/usr/bin/php7.3 will give you the exact version you want. You can’t trust /usr/bin/php or even just typing php because an upgrade might switch versions on you silently.

answered Oct 11, 2020 at 16:07

mcmacerson's user avatar

mcmacersonmcmacerson

8451 gold badge14 silver badges17 bronze badges

I have solved this issue in Ubuntu 20.04.1 LTS and PHP Version 7.4.3

Update the package index:

sudo apt-get update

Install php7.4-curl deb package:

sudo apt-get install php7.4-curl

answered Jan 29, 2021 at 13:17

Nanhe Kumar's user avatar

Nanhe KumarNanhe Kumar

15.3k5 gold badges78 silver badges70 bronze badges

This worked for me with raspian:

sudo apt update && sudo apt upgrade
sudo apt install php-curl

finally:

sudo systemctl restart apache2

or:

sudo systemctl restart nginx

answered Feb 18, 2021 at 3:05

rundekugel's user avatar

rundekugelrundekugel

1,0501 gold badge10 silver badges23 bronze badges

To install the last version of php-curl on Ubuntu, use this:

sudo apt-get install php-curl -y

answered Nov 9, 2021 at 14:43

George Chalhoub's user avatar

George ChalhoubGeorge Chalhoub

14.6k3 gold badges36 silver badges60 bronze badges

Call to undefined function: curl_init() или нерабочий cURL

cURL — это свободная, кроссплатформенная служебная программа командной строки для копирования файлов по различным протоколам с синтаксисом URL.

Если Ваш парсер или модуль который Вы установили не работает из за cURL
Выводится ошибка «Fatal error: Call to undefined function: curl_init()»
Это означает что у Вас не установлены библиотеки cURL

Решения

Файл php.ini
Раскоментирать строку
из

на

— Перезапускаем PHP

Для Debian

Устанавливаем библиотеку cURL

aptget install php5curl

— Нажимаем «Y» и ждем завершения установки.
— Перезапускаем Apache

/etc/init.d/apache2 restart

Для Ubuntu

sudo aptget install curl libcurl3 libcurl3dev php5curl

— Перезапускаем Apache

sudo /etc/init.d/apache2 restart

Похожая запись

Are you getting the dreaded error: “Call to undefined function curl_init()”? If so, don’t worry. This blog post is here to help! We’ll walk you through the steps to fix this error quickly and easily. So grab a cup of coffee and let’s get started!

What reasons causing the Call to undefined function curl_init() error?

The error “Call to undefined function curl_init()” occurs when the cURL library is not installed or enabled in your PHP setup. Some of the common reasons for this error are:

  • cURL library is not installed: If cURL is not installed on your system, you will not be able to use the curl_init function.
  • cURL is not enabled in PHP: If cURL is installed, but not enabled in your PHP setup, you will not be able to use the curl_init function.
  • Incorrect PHP configuration: If the PHP configuration file (php.ini) is not set up correctly, the cURL library may not be loaded.
  • Server misconfiguration: If the server is not configured properly, the cURL library may not be installed or enabled.
  • Incorrect version of PHP: If the version of PHP you are using is not compatible with the version of cURL installed on your system, the error “Call to undefined function curl_init()” may occur.

Call To Undefined Function Curl

The error “Call to undefined function curl_init()” usually means that the cURL library is not installed or enabled in your PHP setup. To resolve this issue, you can do the following:

Step 1: Check if cURL is installed

Let’s run the following command in your terminal/command prompt: php -m to see a list of installed PHP modules. If you don’t see curl in the list, it means cURL is not installed.

Step 2: Install cURL

If you don’t have cURL installed, you can install it on most systems by using a package manager.

For example, on Ubuntu, run the following command: sudo apt-get install php-curl.

On Windows, you can download the cURL dll from the official website and add it to your php/ext directory.

For Linux users, this can be done by running the command “sudo apt-get install php5-curl” in a terminal window.

Once cURL is installed and enabled, users can use it for transferring data to or from a remote server

Step 3: Enable cURL in PHP

If cURL is installed, but not enabled in your PHP setup, you can add the following line to your php.ini file:

  • In Window

extension=php_curl.dll (Windows)

  • In Unix or Linux

extension=curl.so

Step 4: Restart your web server

After making changes to your php.ini file, you will need to restart your web server to check if the error is gone.

Final words: Call to undefined function curl_init()

the Call to undefined function curl_init() error is an issue that can be easily fixed by checking if cURL is installed and enabled. If it is not installed, then it can be quickly and easily installed. Once cURL is installed, it can be enabled in the php.ini file by removing the leading semi-colon before the “extension=php_curl.dll” line. With these simple steps, you can quickly fix this error and get back to using your PHP code normally.

By the way, our website specializes in providing a wide array of bewitching, free WordPress Themes that are suitable for various types of websites.  If you want to change your website’s appearance, don’t miss our website.

Digital Team Enginetemplates

We’re a Digital Team from EngineTemplate with 5 content experts. Our team has 5 years exp in open source Joomla and WordPress, we make daily blogs and build useful resources for everyone who is having issues with open source while using it.

This error will occur if your server does not have PHP’s curl extension installed or enabled.

The error will read something like this.

Uncaught error: Call to undefined function curl_init()

Essentially, PHP can’t find the curl_init function because the extension that defines it has not been loaded. This results in a fatal error, which kills the PHP script.

To avoid this kind of error, you can check to see whether the cURL module has been loaded or not before you attempt to use it.

Check to see if curl is enabled.

To see if your PHP installation has cURL enabled, you can run the following piece of code.

<?php
//Call the phpinfo function.
phpinfo();

The phpinfo function above will output information about PHP’s configuration.

If a CTRL + F search for “curl” is unable to find anything, then it means that your web server has not loaded the curl extension.

If you do find it, then you should see the following line under the cURL heading:

cURL support: enabled

Note that you should NOT leave this phpinfo function on a live web server, as it outputs sensitive information about your PHP installation!

Enabling curl on Linux.

If your web server is running on Linux and you have SSH / terminal access, then you can install and enable cURL by running the following command.

sudo apt-get install php-curl

After running the command above, you will need to restart your web server so that the changes will take effect.

If you are using Apache, you can restart your web server like so.

sudo /etc/init.d/apache2 restart

If you are using Nginx, you can use the following command.

sudo /etc/init.d/nginx restart

After your web server has been restarted, curl should be available.

Enabling curl on Windows.

If you are using Windows, you will need to locate the php.ini file that is being used by your web server.

If you are unsure about which php.ini file you need to edit, then you can use the phpinfo script that we used above, as that will display the full path to the file that is being used by the web server.

Once you have located your php.ini file, you will need to “uncomment” the following line.

;extension=php_curl.dll

To uncomment the line above and enable the php_curl.dll extension, simply remove the semi-colon at the beginning.

After you have saved the changes that you made to your php.ini file,  you will need to restart your web server. Otherwise, the new configuration will not take effect.

Enabling curl on WampServer.

If you are using the popular WampServer program on Windows, then you can try the following steps:

  1. Click on the WampServer icon in your system tray.
  2. Hover over the “PHP” option.
  3. Once the PHP menu appears, hover over the “PHP extensions” option.
  4. At this stage, a list of PHP extensions should appear. If an extension has a tick beside it, then it is already enabled. If the php_curl option does not have a tick beside it, then it is not enabled. To enable curl, simply click on the php_curl option.
  5. WampServer should automatically restart Apache and the changes should take effect.
  6. If WampServer does not automatically restart Apache, then you can manually force it to do so by clicking on the “Restart All Services” option in the main menu.

Hopefully, this guide helped you to get rid of that nasty “undefined function curl_init” error!

Related: Sending a POST request without cURL.

Are you using PHP’s curl_exec() function and getting a “call to undefined function curl_init()” error? If so, then let’s fix the undefined curl_init() function error for you on Linux.

What is cURL?

cURL is a library (known as libcurl) that lets you communicate with other computers in PHP. In other words, PHP uses the libcurl extension to transfer data to or from a remote computer. libcurl currently supports HTTP/HTTPS, FTP, and many other protocols. You can also POST, GET and do other methods.

You will get a fatal PHP error about an undefined function called: “curl_init()” if the extension is not installed or enabled. Therefore, you need to install the libcurl package to use cURL functions.

To use the CURL command, you would need to use code similar to this:

$ch = curl_init();
curl_setopt_array($ch, $this->getCurlGetOptions($this->getUrl($params)));
$response = curl_exec($ch);

$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headerText = substr($response, 0, $headerSize);
$bodyText = substr($response, $headerSize);
$headers = $this->getHeadersFromCurl($headerText);

If the PHP CURL module is not found, you will see an error similar to this:

PHP Fatal error: Uncaught Error: Call to undefined function curl_init()

Let’s fix the undefined function curl_init() error

Again, the fix will depend on your web hosting setup:

If you have no access to the command line:

You must contact your web hosting provider to enable cURL if you do not have command-line access. The same is true if you do not have access to php.ini. Some web hosting providers disable this extension by default for security reasons, but they may enable it for you on request. Additionally, you may be able to enable cURL if you have access to CPanel.

If you have access to the command line:

You will first need to install libcurl and then restart your web server.

Install libcurl

First, install libcurl for PHP on Debian/Ubuntu:

sudo apt-get install php-curl

If your distro is RHEL/Centos, then run this command:

sudo yum install php-curl

If you use Fedora, then run this command:

sudo dnf install php-curl

Restart your web server

Then, restart your webserver if it is Apache on Debian/Ubuntu:

sudo service apache2 restart

Or restart your webserver if it is Nginx on Debian/Ubuntu/Fedora:

sudo service nginx restart

Alternatively, restart your webserver if it is Apache on RHEL/CentOS/Fedora:

sudo systemctl restart httpd

Or restart your webserver if it is Nginx on RHEL/CentOS/Fedora:

sudo systemctl restart nginx

Wrapping up undefined function curl_init error

You will no longer get a “call to undefined function curl_init()” error when using PHP’s cURL functions.

You may also be interested in

Source:

  • https://www.php.net/manual/en/curl.examples-basic.php
  • https://serverfault.com/questions/1015175/php-curl-and-php7-3-curl-installed-but-curl-init-is-undefined-function-debi


About the Authors

Anto’s editorial team loves the cloud as much as you! Each member of Anto’s editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic! Contact Anto Online if you want to contribute.

Support the Cause

Support Anto Online and buy us a coffee. Anything is possible with coffee and code.

Buy me a coffee


Возможно, вам также будет интересно:

  • Ошибка call to abs is ambiguous
  • Ошибка call to a member function on array
  • Ошибка call of duty modern warfare онлайн
  • Ошибка call of duty modern warfare fatal error
  • Ошибка c50 сузуки бургман 650

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии