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 WordPress with Ubuntu 20.04 and a LAMP Stack?
Install WordPress on Ubuntu 20.04 with a LAMP stack, and start by setting up Apache, MySQL, and PHP. Download and configure WordPress, set appropriate file permissions, and complete the installation through the web interface. Ensure security configurations for a stable and secure WordPressSteps to I
3 min read
How to install Django with NGINX, Gunicorn, and PostgreSQL on Ubuntu?
This article describes how to install and configure Django with PostgreSQL, Gunicorn, and Nginx on your Ubuntu machine. First, let's look at an overview of all the tools we use. Django is a robust, free, open-source, Python-based web framework that follows the MVT (Model-Template-View) architectural
6 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 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 Elinks on Ubuntu?
If you are searching for any Text-Based Web Browser for any Linux Distribution like Ubuntu, then the Elinks on Ubuntu will be the best to use. The Elinks Web Browser on Ubuntu can even enhance the Command Line Experience. Not only on Ubuntu OS but the Installation of Elinks can be done on Windows OS
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 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
4 min read