DevOps

Deploying a Web App on Heroku - Easy Hosting Tutorial


Introduction

Heroku is a cloud platform (PaaS - Platform as a Service) that allows developers to deploy, manage and scale web applications without worrying about server infrastructure. It supports multiple programming languages like Node.js, Python, Ruby, Java, PHP, Go, Scala and Clojure.

Key Features of Heroku

  1. Easy Deployment: Deploy apps directly using Git, GitHub or Docker.
  2. Scalability: Scale up or down based on traffic demands.
  3. Managed Services: Provides databases, caching, logging and monitoring.
  4. Buildpacks: Automates dependency installation for different languages.
  5. Heroku CLI & Dashboard: Manage applications using a command line interface (CLI) or web dashboard.
  6. Add-ons: Integrate third-party services like databases (PostgreSQL, Redis), logging (Papertrail) and authentication.

 

To host a web application on Heroku, follow these steps:

1. Install Required Tools

Install the Heroku CLI

curl https://cli-assets.heroku.com/install.sh | sh

 

Install Git (if not installed)

sudo apt install git # Ubuntu/Debianbrew install git # macOS

 

2. Create a Heroku Account

Sign up at Heroku.

Log in via CLI:

heroku login

 

3. Prepare Your Application

  • Add a Procfile (Required)

Heroku needs a Procfile to know how to start your application.

For a Node.js App

Create a file named Procfile (no extension) in the root directory:

web: npm start

 

For a Python (Flask/Django) App

web: gunicorn app:web: npm start

 

For PHP

web: heroku-php-apache2 .

 

  • Initialize Git Repository

If your project is not already in Git:

git initgit add .git commit -m "Initial commit"

 

4. Create a Heroku App

Run the following command to create an app:

heroku create your-app-name

If you don’t specify a name, Heroku assigns a random one.

 

5. Deploy the Application

  • Connect Git to Heroku

Add the Heroku remote repository:

git remote add heroku https://git.heroku.com/your-app-name.git
  • Deploy the Code
git push heroku main

or

git push heroku master

(depending on your Git branch)

 

6. Set Up Environment Variables (Optional)

If your app needs environment variables, set them using:

heroku config:set VAR_NAME=value

 

7. Scale and Open the App

heroku ps:scale web=1heroku open

 

8. View Logs and Debug

To check logs:

heroku logs --tail

 

To restart the app:

heroku restart

 

9. Add a Database (Optional)

If your app requires a database, use:

heroku addons:create heroku-postgresql:hobby-dev

 

That's it! Your web application is now live on Heroku.

 

Ready to transform your business with our technology solutions? Contact Us  today to Leverage Our DevOps Expertise. 

0

Devops

Related Center Of Excellence