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 Install CloudPanel on Ubuntu? CloudPanel can be self-hosted on Ubuntu and is a very effective software for the administration of web hosting platforms. CloudPanel is a type of open-source control panel that primarily facilitates the tasks of an administrator and developers and that is used by hosting providers as well. This guid
3 min read
How to Install Apache Web Server in Linux: Ubuntu, Fedora, RHEL? If you're looking to install Apache on Linux, this guide will walk you through the steps required for different distributions, including Ubuntu, Fedora, and RHEL. The Apache web server is a popular choice for hosting websites and applications, known for its reliability and flexibility. Whether you'r
5 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 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