Deploying with Firebase App Hosting
A complete guide to setting up, deploying, and managing fullstack web applications on Firebase App Hosting — from CLI setup to secrets management.
Read the Docs
What is Firebase App Hosting?
Production-Ready Platform
Firebase App Hosting reached General Availability (GA) in April 2025 and is fully supported for production deployments. It's easy to use, scalable, and reliable.
Built-in framework support for Next.js and Angular, plus broader support for various other popular web frameworks.
Deployment Methods
GitHub Integration
CI/CD pipelines with automatic builds on push
Firebase CLI
Local source deployment directly from your machine
Firebase Studio & Terraform
Studio onboarding or infrastructure-as-code with Terraform
App Hosting integrates seamlessly with Firebase Authentication, Cloud Firestore, and Firebase AI Logic — making it a natural fit for fullstack Firebase applications.
Prerequisites
Before you begin, make sure you have the following ready:
1
Firebase Project
2
Blaze Billing Enabled
Required for App Hosting. See pricing details.
3
GitHub Repo Ready
Your app code should be committed and pushed to a GitHub repository.
4
Node.js or Bun
Installed locally for running builds and the Firebase CLI.

Install the Firebase CLI globally with npm i -g firebase-tools, or use npx without installing: npx -y firebase-tools@latest --version
Authenticate & Verify Local Build
A clean local build is the foundation of a successful cloud deployment. If it doesn't build locally, it won't build in the cloud either.
Step 1: Authenticate Firebase CLI
npx -y firebase-tools@latest login

npx -y firebase-tools@latest projects:list
Run the login command and confirm your projects are visible in the output.
Step 2: Verify Your Local Build
npm install   # or: bun install
npm run build # or: bun run build
Fix any local build errors before proceeding. A passing local build is required before touching hosting configuration.
Initialize Firebase App Hosting
Run the following command from your project root to begin the interactive setup:
npx -y firebase-tools@latest init apphosting
01
Choose Firebase Project
Select the Firebase project you created in the prerequisites step.
02
Choose GitHub-Integrated Deployment
Select the GitHub integration option when prompted for deployment method.
03
Authorize GitHub
Authorize GitHub and install the Firebase GitHub app on your account or organization.
04
Select Repository & Branch
Choose your repository and set the production branch (usually main).
05
Set App Root Directory
Use / if your app is at the repo root, or specify a subdirectory.

The connection between Firebase and GitHub is handled securely through Google Cloud Developer Connect.
Configure Environment Variables
Environment variables can be set in two ways. Console values always take precedence over file-based config.
🖥 Firebase Console (Quickest)
In your Firebase dashboard, you can now navigate to App Hosting → view your backend → Settings → Environment and add your required variables here.
Example variables for a Next.js + Firebase app:
  • NEXT_PUBLIC_FIREBASE_API_KEY
  • NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN
  • NEXT_PUBLIC_FIREBASE_PROJECT_ID
  • NEXT_PUBLIC_FIREBASE_APP_ID
  • NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID
  • NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET
📄 apphosting.yaml (File-Based)
Define environment variables and secret references directly in your apphosting.yaml config file. This approach lets you version-control your configuration alongside your code.

Never commit sensitive values like API keys as plain environment variables. Use Cloud Secret Manager for secrets — covered in the next section.
Managing Secrets with Cloud Secret Manager
For sensitive values like API keys, use Google Cloud Secret Manager instead of plain environment variables.
Setting Secrets via CLI (Recommended)
1
Run the secrets:set command
firebase apphosting:secrets:set SECRET_NAME
Example: firebase apphosting:secrets:set firebase-api-key
2
Paste the secret value when prompted
The value is stored securely in Cloud Secret Manager — never in your codebase.
3
Grant service account access
When prompted, select Y to grant your App Hosting backend service account access to the secret.
4
Update apphosting.yaml
Select Y when the CLI offers to update your apphosting.yaml with the secret reference. The file stores only references, not values — safe to commit.
Pin a Specific Secret Version
env:
  - variable: NEXT_PUBLIC_FIREBASE_API_KEY
    secret: firebase-api-key@1
Useful CLI Commands
Commit Config & Trigger First Deploy
Generated Config Files
After initialization, you'll see these new files in your project:
.firebaserc
Links your local project to your Firebase project ID.
firebase.json
Top-level Firebase configuration for your project.
apphosting.yaml
App Hosting-specific config including environment and secret references.
Commit and push all three files to your repository.
Trigger First Deployment
Push to the live branch you configured (e.g. main). App Hosting will automatically build and deploy your app.
The first rollout typically takes 5–7 minutes.
Once complete, find your generated App Hosting URL under "domains" in the Firebase console.
URL format:
backend-id--project-id.<region>.hosted.app
Verify Deployment & Common Gotchas
Post-Deploy Checklist
Open the App Hosting URL
Test key routes and authentication flows in your deployed app.
Add Authorized Domain
If using Firebase Auth, add your deployed domain to Authorized Domains in the Firebase console.
Commit Your Lockfile
Commit package-lock.json or bun.lock to keep builds reproducible.
Pin Framework Versions
Pin critical framework versions if security or build adapter restrictions require it.
⚠️ Common Gotchas

"Must be run from a Firebase project directory" — Run firebase init apphosting first before running firebase use project-id in that folder.

Build passes locally but fails in App Hosting? Check App Hosting build logs in the Firebase console. Common causes include framework or security version restrictions in the cloud build environment.

Missing environment variables? Add them in the App Hosting backend Environment settings in the Firebase console — not only in your local .env.local file. Console values override apphosting.yaml values.
Beyond GitHub: Other Ways to Deploy
While this guide covers GitHub-integrated deployment, App Hosting supports multiple deployment methods to fit your workflow.
Firebase CLI Local Deploys
Run firebase init apphosting then firebase deploy to push source directly from your machine — no GitHub required.
Firebase Studio
Deploy directly from Firebase Studio with built-in onboarding and monitoring. Great for rapid iteration.
Terraform
Manage App Hosting backends declaratively with infrastructure-as-code for enterprise-grade deployments.
Local Emulator Suite
App Hosting is part of the Firebase Local Emulator Suite. Use apphosting.emulator.yaml for local overrides — auto-created by the CLI, dynamically loads secrets from Cloud Secret Manager.

App Hosting vs Firebase Hosting: App Hosting is for fullstack, server-rendered apps. Firebase Hosting (since 2014) is better suited for static sites or apps without a backend.
Resources
Made with