'Google distance matrix API works on Windows not on webserver

Google distance matrix API is enabled and works on Windows but on webserver all I get is NULL for an answer. I checked on Google API Console and this API is enabled for ALL PLATFORMS. All can think off now is that the web server has something to do with it. Any suggestions Please. Here is my code:

    function getDistance($addressFrom, $addressTo, $unit = ''){
    $apiKey = *************************
    $adrF=str_replace(" ","+",$addressFrom);
    $adrT=str_replace(" ","+",$addressTo);
    $url ="https://maps.googleapis.com/maps/api/distancematrix/json?origins=$adrF&destinations=$adrT&key=$apiKey";
    $api = file_get_contents($url);
    $data = json_decode($api);      
    if(isset(($data->rows[0]->elements[0]->status[0]))){
        $status = ($data->rows[0]->elements[0]->status);
        if($status == "ZERO_RESULTS"){
            return $Distance = "0 Km";
            exit();
        }else{  
             return $Distance = ((int)$data->rows[0]->elements[0]->distance->value / 1000).' Km';
            }
        }
    }


Solution 1:[1]

The problem was on the web server's php.ini. The https_fopen_allow was set to 0 instead of 1. Everything works now properly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jvdv