Reputation: 1381
I'm new to both PHP and Firebase. I tried to use firestore on a php site.
use Google\Cloud\Firestore\FirestoreClient;
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);
initialize();
function initialize()
{
// Create the Cloud Firestore client
$db = new FirestoreClient();
printf('Created Cloud Firestore client with default project ID.' . PHP_EOL);
}
but the there's a Fatal error: Class 'Google\Cloud\Firestore\FirestoreClient' not found in /var/www/html/test.php on line 37
I followed quick start tutorial - https://firebase.google.com/docs/firestore/quickstart
I'm using debian 9 VPS with PHP 5.6
Upvotes: 4
Views: 8698
Reputation: 1381
Problem got fixed. If anyone having same problem. I added require 'vendor/autoload.php';
to the top of page. And Make sure to add extension=grpc.so
to both php.ini files ( one inside apache 2 folder other inside cli folder) and restart apache. here is my new code
use Google\Cloud\Firestore\FirestoreClient;
require 'vendor/autoload.php';
ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);
initialize();
function initialize()
{
// Create the Cloud Firestore client
$db = new FirestoreClient();
printf('Created Cloud Firestore client with default project ID.' . PHP_EOL);}
Upvotes: 5
Reputation: 7979
Are you sure you followed all of the steps carefully?
Namely, please check you've added the library:
composer require google/cloud-firestore
and that you've added the following to the top of your file:
use Google\Cloud\Firestore\FirestoreClient;
Upvotes: 1
Reputation: 2581
The Class library is not accessible from your test.php
file.
Use a bootstrap to load Google\Cloud\Firestore\FirestoreClient
or include it manually in your script.
Upvotes: 0