phpphp-curl

Trying to fix error code 7 with AlmaLinux 9 PHP 8.1 cURL?


I recently installed AlmaLinux 9 with LAMP and everything works correctly except cURL. I have verified cURL is installed and enabled. When I run the following code I receive

$url = 'http://example.com/TellMeSomething';                      

$cURL = curl_init($url);
curl_setopt($cURL, CURLOPT_FAILONERROR, true);
curl_setopt($cURL, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($cURL, CURLOPT_TIMEOUT, 5);
curl_setopt($cURL, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);

$responseCode = curl_getinfo($cURL, CURLINFO_HTTP_CODE);
$data = curl_exec($cURL);
curl_close($cURL);

if (!$data) {
    die('Error: "' . curl_error($cURL) . '" - Code: "' . curl_errno($cURL) . '" - HTTP_CODE: "' . $responseCode . '"');
} else {
    echo 'Success!!!';
}

This script returns Success on PHP 7, but returns Error: "" - Code: "7" - HTTP_CODE: "0" using PHP 8.1

I have verified the PHP installation has cURL enabled

Any help will be greatly appreciated.


Solution

  • I finally found the answer. I ran the following command on the server.

    setsebool -P httpd_can_network_connect on