curl_init() function not working

最后都变了- 提交于 2019-11-26 04:29:11
RusAlex

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.

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

;extension=php_curl.dll

Restart apache server.

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)

I got it working in ubuntu 16.04 by following steps.My php version was 7.0

sudo apt-get install php7.0-curl

sudo service apache2 restart

i got it from this link check here for more details

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
Hiruna De Alwis

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"
Rajat26

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

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"

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.

Amit Garg

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

(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.

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)

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

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.

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.

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

Had this problem but found the answer here: https://askubuntu.com/questions/1116448/cannot-enable-php-curl-on-ubuntu-18-04-php-7-2

Had to:

sudo a2dismod php7.0

And:

sudo a2enmod php7.2

Then:

sudo service apache2 restart

This was after a system upgrade to next version of Ubuntu. All the other answers I found were stale, due to a bad cert apparently on the PPA most of them pointed out, but would probably not have worked anyway. The real issue was disabling the old versions of php, apparently.

Found the solution here:

https://askubuntu.com/questions/1116448/cannot-enable-php-curl-on-ubuntu-18-04-php-7-2

NickUnuchek

Just install the last version of wamp server.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!