PHP Accuses Curl Not Installed

Asked

Viewed 9,967 times

1

I downloaded the . exe from the official website, attached the system variable and tested. Everything working.

But when I go in my PHP program it always gives the same error:

Fatal error: Call to Undefined Function curl_init()

My code in the part where it gives the problem:

 <?php
    $url_recepient = "https://api.pagar.me/1/recipients";
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url_recepient);
    curl_setopt ($ch, CURLOPT_POST, 1);
 ?>

And now I don’t know if it’s my code error or I didn’t install it right.

  • Then, in the 7xx version I used, I searched for Curl in php.ini file, it appeared ;Extension=Curl , I just removed the dot and comma and restarted the local server

1 answer

3

This is because the Curl library is not installed and enabled.

To enable in windows:

Create a file called info.php with the content:

<?php
phpinfo();

Access the file URL cited above and locate the file the file path php.ini specified in Loaded Configuration File, then open the 'php.ini' file and remove the semicolon from the line:

;extension=php_curl.dll

Should stay like this:

extension=php_curl.dll

Save the file php.ini.

Copy the files php_curl.dll, ssleay32.dll and libeay32.dll to your folder Windows/system32

Restart the web server and run the tests.

To install and enable on linux (Debian/Ubuntu):

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

To install and enable on linux (Centos):

yum install php-curl
sudo service apache2 restart

In case everything went well:

If everything went well, you should find something similar to the image below in your phpinfo();, informing that the Curl library is installed and informing its settings

phpinfo(); exibindo seção cURL]

If running via Prompt

Use the "-c caminho_do_php.ini"

php -c C:\php\php.ini -S localhost:8080 
  • There is no php.ini file, there are two others with the following names: php.ini-PRODUCTION and php.ini-DEVELOPMENT

  • I did this and it didn’t help... Is it because I’m using the test server that comes along with the new versions of PHP and not Apache?

  • I’m using the native that comes together in PHP (type at the prompt: php -S localhost:8080 and testo there) and in phpinfo() appears all the php information as it was to appear

  • Something important, remember to copy the files php_curl.dll, ssleay32.dll and libeay32.dll to your folder Windows/system32

Browser other questions tagged

You are not signed in. Login or sign up in order to post.