How to Install Heroku and Deploy a Static Website on Ubuntu?
Last Updated :
21 Dec, 2022
Heroku is a cloud platform that provides a platform as a service(PAAS) to deploy either static or dynamic websites. Heroku is managed by Salesforce. Heroku allows CI/CD, code rollbacks, automatic deploys, Github integration, app metrics, and much more. Heroku allows building, running, and deploying applications on the web. It supports several programming languages and is hence widely popular.
In this article, we will install git and Heroku and then deploy a static site. A static site is a site that doesn’t have a backend. Our site will contain a simple index.js file only. We will require Node.js as Heroku requires but we wouldn’t process any data.
Installation of Heroku
Step 1: Install git in your system
sudo apt-get install git -y
The output is as follows:
Step 2: Register on Heroku
Register on Heroku. It is available for free as well as has pricing options. To register, proceed to https://www.heroku.com/.
On registration, proceed to the next step.
Step 3: Install Heroku CLI.
Install Heroku CLI in Ubuntu as follows:
sudo snap install --classic heroku
Output
Deploy website on Heroku
In this section, we are going to deploy our website.
Step 1: Create a folder and name it mywebsite.
Then open the terminal in the current directory and enter
npm init -y
After that create a file index.js, and enter the following code.
index.js
Javascript
var http = require( 'http' );
var fs = require( 'fs' );
const port = process.env.PORT || 5000;
http.createServer( function (req, res) {
res.writeHead(200, { 'Content-Type' : 'text/plain' });
res.end( "Welcome to GeeksforGeeks" );
}).listen(port);
|
In the package.json, we need to call the index.js file. So modify it as follows:
package.json
Javascript
{
"name" : "mywebsite" ,
"version" : "1.0.0" ,
"description" : "" ,
"main" : "index.js" ,
"scripts" : {
"start" : "node index.js" ,
"test" : "echo \"Error: no test specified\" && exit 1"
},
"keywords" : [],
"author" : "" ,
"license" : "ISC"
}
|
The project structure is as follows
Step 2: Log in to your Heroku account,
heroku login
It will open your browser where you will have to enter your email and password.
Step 3: Create a new application using the Heroku CLI.
“heroku create” creates a new application on your account so we can use it to deploy our application.
git init
heroku create -a mygeekswebsite
Output
Use the following command to confirm that Heroku is used.
git remote -v
Step 4: Deploy your website
Add the files to the git and commit them
git add
git commit -m "message"
Use the following command to deploy
git push heroku main
After a successful deployment, the message appears as follows:
Follow your website link as provided and the output in the browser is as follows:

Similar Reads
How to Deploy a Basic Static HTML Website to Heroku?
Heroku is a simple and one-stop solution to host any website or server. This article revolves around how you can host your own Static HTML webpage on Heroku. To demonstrate this we are going to build a simple webpage and host it. PrerequisitesGitHeroku AccountHeroku CLI Let's create a directory name
3 min read
How to install and set up Apache Virtual Hosts on Ubuntu?
Every website that is published on the Internet is housed on a web server (host), which is able to handle requests for web pages made by clients using browsers like Chrome, Firefox, or Internet Explorer and is connected to the network with a public IP address. Install a web server before hosting a w
4 min read
How to Host Static Website Using AWS S3?
AWS Simple Storage Service (S3) from the aforementioned list, S3, is the object storage service provided by AWS. It is probably the most commonly used, go-to storage service for AWS users given the features like extremely high availability, security, and simple connection to other AWS Services. An A
2 min read
How to Deploy Static Website using Caddy Webserver?
Deploying a static website with Caddy is a simple and efficient way to host a website. Caddy is a modern, fast, and easy-to-use web server that simplifies the process of deploying websites with automatic HTTPS. In this guide, we will show you how to use a Caddy webserver to host a static website. Wh
6 min read
How to Install WordPress on Ubuntu 22.04
WordPress is one of the most popular platforms for building websites, known for its flexibility and ease of use. If you're looking to set up your own website, installing WordPress on Ubuntu 22.04 is a great choice. This guide will walk you through the process step by step, ensuring you get your Word
5 min read
How to Install and Customize Apache on Ubuntu or Debian?
One of the most dominant forces in web server software is the Apache HTTP Server, often shortened to Apache. This free and open-source project, overseen by the Apache Software Foundation, has been a major player in shaping the Internet since its launch in 1995. Installing an Apache web server on Ubu
2 min read
How to Install Apache in Ubuntu using Ansible?
Apache HTTP Server, commonly referred to as Apache, is a robust and broadly used web server for open-source web server programming. It is exceptionally adaptable and extensible, and it is famous for hosting websites and web applications. Ansible, then again, is a strong automation device that improv
6 min read
How to Deploy React App on Netlify Using Github?
React App is a web or mobile application that is built using the React library of JavaScript. It helps users create interactive, single-page, and dynamic applications. These applications are built using HTML, CSS, and JavaScript. Deployment of a React app can be done via GitHub, Netlify, or any othe
6 min read
How to deploy React app to Heroku?
React is a very popular and widely used library for building User Interfaces. So if you are thinking about deploying your React app to the cloud platform, there are various choices for doing that such as AWS EC2 or Heroku. But for testing your React app, Heroku will be the best option as it is free
3 min read
How to Make Changes to The Application Deployed on Heroku ?
Many of the times we need to make changes to our deployed project for some reason. Either we want to have a new version of the project, add new features to the project, remove a bug, or for some other reasons. If your project is deployed on Heroku Cloud Platform, you can easily make your changes usi
2 min read