php - Fatal error: Uncaught Error: Class 'KreaitFirebaseServiceAccount' not found in


I have to learn just now write mobile app web service via fire base. I followed this link:

In my core website i create web service folder and then create my fire.php file.This file code here,


require __DIR__.'/vendor/autoload.php';

use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;

$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$apiKey = 'AIzaSyC_vb5G9qs3NJsywbR34el1RaPj2HDhwNg';

$firebase = (new Factory)
    ->withServiceAccountAndApiKey($serviceAccount, $apiKey)

$database = $firebase->getDatabase();

$newPost = $database
        'title' => 'Post title',
        'body' => 'This should probably be longer.'

$newPost->getKey(); // => -KVr5eu8gcTv7_AHb-3-
$newPost->getUri(); // =>

$newPost->getChild('title')->set('Changed post title');
$newPost->getValue(); // Fetches the data from the realtime database

I have to call my support file here:

But still I got a:

Fatal error: Uncaught Error: Class 'Kreait\Firebase\ServiceAccount' not found in /opt/lampp/htdocs/workarea/webservice/firebase/fire.php:13 Stack trace: #0 {main} thrown in /opt/lampp/htdocs/workarea/webservice/firebase/fire.php on line 13

issue have to fix this issue. Kindly check and help me.

Mycomposer.json file

    "name": "kreait/firebase-php",
    "description": "Firebase Admin SDK",
    "keywords": ["firebase", "google", "sdk", "api", "database"],
    "homepage": "",
    "license": "MIT",
    "authors": [
        { "name": "Jérôme Gamez", "homepage": "" }
    "require": {
        "php": "^7.0",
        "ext-mbstring": "*",
        "ext-openssl": "*",
        "fig/http-message-util": "^1.1",
        "google/auth": "^0.11.0|^1.0",
        "guzzlehttp/guzzle": "^6.2.1",
        "kreait/firebase-tokens": "^1.1.1",
        "lcobucci/jwt": "^3.2",
        "mtdowling/jmespath.php": "^2.3"
    "require-dev": {
        "friendsofphp/php-cs-fixer": "^2.0",
        "phpstan/phpstan-phpunit": "^0.9.2",
        "phpunit/phpunit": "^6.0"
    "autoload": {
        "psr-4": {
            "Kreait\\": "src"
    "autoload-dev": {
        "psr-4": {
            "Kreait\\Tests\\": "tests"
    "config": {
        "platform": {
            "php": "7.0"
        "sort-packages": true
    "extra": {
        "branch-alias": {
            "dev-master": "3.x-dev"



I am sure you already got your problem solved, but for upcoming developers it might be helpful, Its issue with your composer install kreait/firebase-php using composer in cmd inside project directory and your issue will be resolved.




I actually had the same issue and I address it by install php-psr exteion:

pecl install psr

Created /etc/php/7.x/mods-available/psr.ini with the following lines:

; configuration for psr module
; priority=20

and enable the extension by excuting:

sudo phpenmod psr

and reload/restart apache, php-fpm.....

service apache2 restart
service php7.4-fpm restart



I recommend starting from Firebase Installation. Process is described there, but the main point is this:

Install your firebase-php package in command-line with Composer:

php composer.phar require kreait/firebase-php

That should fix problem with missing class.

People are also looking for solutions to the problem: php - How to properly update password in Laravel?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.