Real time Messaging System using PHP and Firebase

Posted at January 13, 2019 12425 Views . 0 Saved .

Hi Friends, Here i am going to share source code of real time one on one messaging system for php application using Firebase Nosql Database. 

We all know php lacks in Real time communication and there are many application running in PHP based Server. So if you are interested to add real time messaging system in your app this is right example for you. We can also use Node.js to do this same kind of thing but for that we also need nodejs compatible server. 


1 - PHP Application with Login System

2 - Firebase Project

3 - Firebase Admin SDK for PHP. 

      Note : I already added Admin SDK in my package so it is not required now but if you are interested to download it you can composer to download this via 

    composer require kreait/firebase-php ^4.18

To Create a Firebase Project visit

1 - Click on Add Project

2 - Select Country and Language and so on. Once your project created click on the project app and then select web option out of 3 options

3 - then open your project and click on authentication

4 - Click on 'Sign in method' Tab and enable Email/Password Authentication

5 - In your firebase project app, on the left side there will be an icon of gear symble click on that and then click on project settings and click on Service Accouts and click on generate a new private key it will download a .json file and place it in your root directory

Now you are ready to download my package form github or you can clone it from this url

Steps to configure it

1 - Creat a Database in mysql(phpmyadmin) phpfirebase

CREATE DATABASE phpfirebase;

2- Create two tables users and chat_record

CREATE TABLE IF NOT EXISTS phpfirebase.users (


    uuid VARCHAR(36) NOT NULL,

    username VARCHAR(50) NOT NULL,

    password VARCHAR(100) NOT NULL,

    UNIQUE KEY (uuid, username)


CREATE TABLE `chat_record`(

    `chat_uuid` VARCHAR(36) NOT NULL,

    `user_1_uuid` VARCHAR(36) NOT NULL,

    `user_2_uuid` VARCHAR(36) NOT NULL,

    UNIQUE KEY (chat_uuid)


ALTER TABLE users ADD fullname VARCHAR(100) NOT NULL AFTER uuid;

Now once again back to firebase console click on project overview and then click on web and copy the config code and paste it in inside the project folder phpfirebase/js/config.js file and now you can execute it 

and also watch the video for more clarification

Thanks for coming

Coding is an art and I love art
Why When I Register,But The All Register Data Its Nothing In My Database??
Where Its The Config Code? Where Its The Config Code
Thanks a lot. I had faced the following errors while running your GitHub code. If anyone else has faced these errors then you can solve them by following ways: 1: Rizwan has posted a code to build MySQL DB, when you run his commands then you can't see an email column in the users table, you have to make it your self. 2: If anyone faces the following exception firestore: PERMISSION_DENIED: Missing or insufficient permissions then solve it by the following solution
one to one chat working fine. i am also find group chat can you share any idea.
Thank you so much sir.
hello sir, i just want to learn how this program works ? could you plz help me out ?
please can you send to me source code on my email please can you send to me, source code of this project.
Rizwan Khan
you can download it from here