2

I am aware that there are other questions with a similar title, such as the following:

curl_init() function not working

However I am still not able to get curl working on my localhost and on my server.

For this case, I will focus on the server, which is a Windows Server 2019.

The version of Apache is 2.4.46.

The version of PHP is 7.4.12.

In the php.ini file, I have the following uncommented:

extension=curl

In the extension folder, I can see the following file:

php_curl.dll

On the phpinfo.php page, I don't see that curl has been enabled, which is strange. The only place I see curl is in the module.authors section, and it looks like this:

cURL           |          Sterling Hughes

I have already restarted the services, but I am still getting the following error:

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

What am I doing wrong and how can I fix this?

Edit

I just added this piece of code:

echo "<pre>", print_r(get_loaded_extensions()), "</pre>";

And I get the following:

Array
(
[0] => Core
[1] => bcmath
[2] => calendar
[3] => ctype
[4] => date
[5] => filter
[6] => hash
[7] => iconv
[8] => json
[9] => SPL
[10] => pcre
[11] => readline
[12] => Reflection
[13] => session
[14] => standard
[15] => mysqlnd
[16] => tokenizer
[17] => zip
[18] => zlib
[19] => libxml
[20] => dom
[21] => PDO
[22] => openssl
[23] => SimpleXML
[24] => xml
[25] => xmlreader
[26] => xmlwriter
[27] => apache2handler
[28] => mysqli
[29] => Phar
[30] => pdo_mysql
)
1

None of which are for curl.

halfer
  • 19,824
  • 17
  • 99
  • 186
John Beasley
  • 2,577
  • 9
  • 43
  • 89
  • cURL should already be enabled with PHP 7.x, not sure though, without any external dependency or INI hack. You can check by altering the PHP version to a different minor version. Also, off topic though, why would someone use Apache on a Windows Server while it comes with a built in web server IIS! – Broken Arrow Jul 12 '21 at 18:02
  • Do you have any other extensions loaded? On my Windows machines, the extensions folder listed in php.ini is always wrong and I need to manually uncomment that line so that it points to the correct location. – Chris Haas Jul 12 '21 at 19:03
  • @ChrisHaas - Other extensions are indeed loaded. For example, PDO. No issues with the PDO extension. – John Beasley Jul 12 '21 at 19:07
  • @BrokenArrow - Regarding the off topic question, I don't really have an answer. All I can say is that we are doing a migration of servers, and a number of sites were already using Apache. We have another server that we use the IIS services (if that makes sense). – John Beasley Jul 12 '21 at 19:09
  • Just for fun, can you try renaming the PDO extension that's in the same folder as the curl extension, restart the service, and see if that breaks things, or shows PDO as missing in phpinfo? Sometimes with Windows I've found it helps to have active confirmation of things. – Chris Haas Jul 12 '21 at 19:09
  • @ChrisHaas - I renamed the php_pdo_mysql.dll to php_pdo_mysql_test.dll, and I could no longer log into the sites. – John Beasley Jul 12 '21 at 19:13
  • 1
    @JohnBeasley Completely makes sense :) – Broken Arrow Jul 12 '21 at 19:15
  • In your case, I would give it a quick test with uWAMP just to check if cURL is really the missing child with PHP 7.x – Broken Arrow Jul 12 '21 at 19:16
  • If the cURL extension is not enabled, it's pretty obvious that you cannot use cURL. What have you tried to resolve that? Where are you stuck? Also, please do not use irrelevant tags, as this problem is not related to Apache after all – Nico Haase Jul 13 '21 at 12:08
  • @NicoHaase - I guess the question is: how is cURL not enabled when all of the above shows that it should be? – John Beasley Jul 13 '21 at 12:20
  • Well, that depends. Would it work if you used `extension=php_curl.dll`? Have you checked whether you are changing the correct `php.ini` (as there might be multiple copies)? – Nico Haase Jul 13 '21 at 12:25
  • I just tried changing the extension to php_curl.dll but no luck. I verified that I am editing the correct php.ini file. – John Beasley Jul 13 '21 at 12:31

2 Answers2

2

I was able to finally solve this issue by finding a file in my PHP root folder called libssh2.dll and copy/paste into the Apache bin folder. Once I did that, curl is now enabled, and I no longer get the error in question. I'm getting other errors, but that's for another question.

John Beasley
  • 2,577
  • 9
  • 43
  • 89
0

Had a similar problem. My PHP 8.2-curl was installed, but somewhere 8.3 was upgraded, and 8.3-curl didn't get installed.

It worked when I uninstalled 8.3 and 8.2 and reinstalled PHP from scratch.

Rafael Corrêa Gomes
  • 1,751
  • 1
  • 22
  • 31