PHP web application with Firebase backend integration, featuring user authentication, JWT tokens, and Firestore database.
- User Authentication: Secure login system with JWT tokens
- Firebase Integration: Uses Firebase Auth and Firestore for data storage
- RESTful API: Clean API endpoints for user management
- Responsive Frontend: Bootstrap-based UI for dashboard and user management
- Session Management: PHP sessions with token-based authentication
- Admin User Creation: Script to bootstrap admin user
- PHP 8.0 or higher
- Apache web server with mod_rewrite enabled
- Composer (for dependency management, if needed)
- Firebase project with Firestore enabled
- Service account key from Firebase
-
Clone the repository:
git clone https://github.com/CSGLMZBA/Firebase-PHP.git cd Firebase-PHP -
Set up Apache:
- Point your document root to
/path/to/Firebase-PHP - Ensure
mod_rewriteis enabled - Configure virtual host if needed
- Note: Apache must serve from the Firebase-PHP folder. If
index.phpis set as the default landing page indir.conf, accessing the root URL will automatically redirect to the login page in the publicindex.phpfile - Port Configuration: The project is configured for port 8888. Either run Apache on port 8888 or update the API base URL in
Frontend/public/api.php
- Point your document root to
-
Firebase Setup:
- Create a Firebase project at Firebase Console
- Enable Firestore Database
- Create a service account and download the JSON key
-
Configuration:
- Copy your Firebase service account JSON data to
backend/app/config/firebase_credentials.php - The file should return an array with
project_id,client_email, andprivate_key
- Copy your Firebase service account JSON data to
-
Create Admin User:
php backend/scripts/create_admin.php
This creates an admin user with username
Adminand passwordPassword.
- Login Page:
http://your-domain/Frontend/public/index.php - Dashboard:
http://your-domain/Frontend/public/dashboard.php(requires login) - User Management:
http://your-domain/Frontend/public/users.php(requires login)
All API endpoints are prefixed with /backend/public/index.php/api/
POST /api/auth/login- User login{ "usuario": "username", "password": "password" }
GET /api/users- List all active usersPOST /api/users- Create new userPATCH /api/users/{id}- Update userPATCH /api/users/{id}/toggle-active- Toggle user active statusDELETE /api/users/{id}- Delete user (soft delete)
Firebase-PHP/
├── backend/
│ ├── app/
│ │ ├── config/
│ │ │ ├── app.php
│ │ │ ├── firebase.php
│ │ │ └── firebase_credentials.php (ignored)
│ │ ├── controllers/
│ │ ├── helpers/
│ │ ├── middlewares/
│ │ ├── repositories/
│ │ ├── routes/
│ │ ├── schemas/
│ │ └── services/
│ ├── public/
│ │ ├── index.php
│ │ └── .htaccess
│ └── scripts/
├── Frontend/
│ └── public/
│ ├── index.php
│ ├── dashboard.php
│ ├── users.php
│ ├── logout.php
│ ├── api.php
│ └── assets/
└── login/
└── login.php
This file contains sensitive Firebase credentials and is gitignored. Create it with:
<?php
return [
'project_id' => 'your-project-id',
'client_email' => 'firebase-adminsdk-xxxxx@your-project.iam.gserviceaccount.com',
'private_key' => "-----BEGIN PRIVATE KEY-----\nYOUR_PRIVATE_KEY\n-----END PRIVATE KEY-----\n",
];Contains application configuration like JWT settings and timezone.
- Firebase credentials are stored in a separate file that's gitignored
- JWT tokens are used for API authentication
- Passwords are hashed using PHP's
password_hash() - CORS is enabled for cross-origin requests
- Update API routes in
backend/app/routes/api.php - Create controllers in
backend/app/controllers/ - Add business logic in services
- Update frontend as needed
Users collection in Firestore:
id: Unique identifierusuario: Usernamenombre: First nameapellidoPaterno: Father's last nameapellidoMaterno: Mother's last namepassword: Hashed passworddireccion: Addresstelefono: Phoneciudad: Cityestado: Stateactivo: Active status (boolean)deleted: Soft delete flag (boolean)
- Ensure Apache document root is set to the project directory
- Check
.htaccessconfiguration - Verify
mod_rewriteis enabled
- Verify
firebase_credentials.phpcontains correct credentials - Check Firebase project settings
- Ensure Firestore is enabled
- Run the admin creation script
- Check PHP error logs
- Verify JWT configuration in
app.php
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.