Search code examples
phpwindowsgoogle-cloud-firestoreiisgrpc

Google Firestore Database unable to connect in IIS (Laragon Apache is fine) "Empty address list:" Error :14


I am running (Windows) IIS with PHP 8.1, grpc + sodium. I have the credentials file from Google Firebase, and I'm just reading from a collection called "info".

On the same machine I am running IIS and Apache, the same code works fine in Apache (Laragon) but not IIS. IIS returns this error:

{ "error": "{\n "message": "empty address list: ",\n "code": 14,\n "status": "UNAVAILABLE",\n "details": []\n}" }

I have tried PHP8.1, 8.2 & 8.3 with the same error.

I have created a test function to help, this is the function I am running.

public function testFirestore()
    {
        $credentialsPath = base_path(env('FIREBASE_CREDENTIALS'));
        putenv('GOOGLE_APPLICATION_CREDENTIALS=' . $credentialsPath);
        putenv('GRPC_VERBOSITY=DEBUG');
        putenv('GRPC_TRACE=all');

        try {
            // Log the credentials path and environment variable
            Log::info('GOOGLE_APPLICATION_CREDENTIALS: ' . getenv('GOOGLE_APPLICATION_CREDENTIALS'));
            Log::info('Service account file exists: ' . (file_exists($credentialsPath) ? 'yes' : 'no'));

            Log::info('GRPC_VERBOSITY: ' . getenv('GRPC_VERBOSITY'));
            Log::info('GRPC_TRACE: ' . getenv('GRPC_TRACE'));

            $firestore = new FirestoreClient([
                'projectId' => '[projectid]',
            ]);

            $collection = $firestore->collection('info');
            $documents = $collection->documents();

            $result = [];
            foreach ($documents as $document) {
                $result[] = [
                    'id' => $document->id(),
                    'data' => $document->data()
                ];
            }

            return response()->json($result);
        } catch (\Exception $e) {
            Log::error('Firestore error: ' . $e->getMessage());
            return response()->json(['error' => $e->getMessage()], 500);
        }
    }

Happy to send my php.ini if that helps....


Solution

  • Turns out the pem certificate was not correct..

    Download the cert from here...

    https://github.com/grpc/grpc/blob/master/etc/roots.pem

    Add a env var with a key of "GRPC_DEFAULT_SSL_ROOTS_FILE_PATH" and the value of the path you stored the download. "C:\dev\certs\roots.pem". Then reboot.