0
0
FirebaseHow-ToBeginner Ā· 3 min read

How to Deploy to Firebase Hosting: Step-by-Step Guide

To deploy to Firebase Hosting, first install the Firebase CLI, then run firebase init hosting to set up your project. Finally, use firebase deploy to upload your files and publish your site.
šŸ“

Syntax

The deployment process uses the Firebase CLI commands:

  • firebase init hosting: Sets up hosting configuration in your project folder.
  • firebase deploy: Uploads your site files to Firebase and makes them live.

You need to be logged in with firebase login before running these commands.

bash
firebase login
firebase init hosting
firebase deploy
šŸ’»

Example

This example shows how to deploy a simple static website folder named public to Firebase Hosting.

bash
firebase login
firebase init hosting
# When prompted, select your Firebase project and set 'public' as the public directory
firebase deploy
Output
āœ” Success: Project initialized āœ” Hosting URL: https://your-project-id.web.app āœ” Deploy complete!
āš ļø

Common Pitfalls

  • Not running firebase login before deploying causes authentication errors.
  • Choosing the wrong public directory during firebase init hosting means your site files won't upload.
  • Forgetting to build your app (if using frameworks) before deploying uploads outdated files.
bash
Wrong way:
firebase deploy

Right way:
firebase login
firebase deploy
šŸ“Š

Quick Reference

Remember these key steps for smooth Firebase Hosting deployment:

  • Always firebase login first.
  • Use firebase init hosting once per project folder.
  • Put your site files in the chosen public directory.
  • Run firebase deploy to publish updates.
āœ…

Key Takeaways

Install Firebase CLI and log in with your Google account before deploying.
Run 'firebase init hosting' once to configure your project for hosting.
Place your website files in the specified public directory.
Use 'firebase deploy' to upload and publish your site.
Always build your app before deploying if using a framework.