After spending countless hours or even days trying out all the posted solutions on stackoverflow and elsewhere, the only thing that worked for me in 2022 was the following solution, (taken from this comment to the php cURL manual)
Try add to these strings to apache config (httpd.conf):
# manually load SSL libraries for cURL
LoadFile "(path\to\php)\libssh2.dll"
LoadFile "(path\to\php)\libcrypto-1_1-x64.dll"
LoadFile "(path\to\php)\libssl-1_1-x64.dll"
and restart apache (dont forget to use your php folder name);
Don't know if this matters, but I am on Windows 7, using Apache 2.4 and PHP 7.4. I don't have any WAMP/XAMP server installed on my system. Instead I downloaded the ZIPped versions and start them manually from my local non-system drive whenever I need to use localhost.
Also, after it finally worked, I deleted libeay32.dll, ssleay32.dll from C:/Windows/System32 and from Apache/bin.