Backend Knowledge Sharing #22

Deploy web applications in Heroku, Configuring fresh ubuntu server, Jotr — Jot down your ideas

Sandip Shrestha
YoungInnovations' Blog

--

Deploy web applications in Heroku

Heroku is a platform as a service based on a managed container system, with integrated data services and a powerful ecosystem, for deploying and running modern apps.

Last week Kushal Raj Shrestha shared his experience on working with Heroku. He believes, whether you’re building a simple prototype or a business-critical product, Heroku’s fully-managed platform gives you the simplest path to delivering apps quickly.

Below are some gotchas associated with Heroku

Dynos

Heroku runs your apps inside dynos — smart containers on a reliable, fully managed runtime environment.

Free Tier

New accounts receive 550 free dyno hours monthly and you can verify your identity with a credit card for an additional 450 hours. Heroku “free tier” dynos will go to sleep state if your app doesn’t receive any traffic in 30 minutes. It will turn active when the next request is received. This is a great way to conserve our dyno hours during inactivity.

App support

Heroku platform supports popular languages like Node.js, Ruby, Python, Java, PHP, Go, Scala and Clojure. There are detailed ‘Getting started’ documentation in their website. In “free tier” account you create and run 5 apps.

Heroku CLI

Heroku Command Line Interface (CLI) makes it easy to create and manage your Heroku apps directly from the terminal. It’s an essential part of using Heroku. It requires Git, the popular version control system.

Add-ons

Heroku add-ons are components, services, or pieces of infrastructure that are fully maintained for you, either by a third-party provider or by Heroku.

Deployment

After following simple steps to setup your app for deployment in heroku, the final step is a simple command.

git push heroku master

Here’s a link to a blog to get you started in deploying your Laravel app in Heroku.

Configuring Ubuntu server instance

Last week Ashish Shakya shared with us how to setup a ubuntu server on our local machine for development purposes using LXC and configuring NGINX.

LXC is a well-known set of tools, templates, library and language bindings. It’s pretty low level, very flexible and covers just about every containment feature supported by the upstream kernel.

Its main focus is system containers. That is containers that offer an environment as close as possible as the one you’d get from a VM but without the overhead that comes with running a separate kernel and simulating all the hardware.

All the getting started steps are mentioned properly in its official documentation.

We will first create a local linux container and run it using the below command:

lxc launch ubuntu:18.04 my-local-container

Now that your container is running, you can get a shell inside it with:

lxc exec my-local-container - /bin/bash

Installing Nginx:

Step 1 — Installing Nginx

sudo apt update
sudo apt install nginx

Step 2 — Checking your Web Server

sudo systemctl status nginx

Step 3 — Checking into the browser address bar

When you have your server’s IP address, enter it into your browser’s address bar:

http://your_server_ip

You should see the default Nginx landing page:

Step 4 — Setting Up Server Blocks

Create a new server block by copying the existing default server block

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com

Open the server block and replace with following code:

server {
listen 80;
listen [::]:80;
root <directory_of_project> (eg: /var/www/example.com/html);
index index.php index.html index.htm;
server_name <ip_address>; location / {
try_files $uri $uri/ =404;
}
}

In the above server block:

listen 80 tells Nginx server to listen to port 80 from where the request and responses are served.

root defines the directory of our project.

The set of files name (index, index.php, index.html, etc) defines which file to load initially from our project directory.

server_nameis where we mention our IP address or domain name (if exists).

location tells: first attempt to serve request as a file, then as directory, then fall back to displaying a 404.’

So in brief, where an IP is entered in our browser, the request is sent to the server. The Nginx then responses with the content located at the root directory mentioned in root of server block.

Notice that we’ve updated the root configuration to our new directory, and the server_name to our domain name.

Next, let’s enable the file by creating a link from it to the sites-enabled directory, which Nginx reads from during startup:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled

In doing so, the content of our projects must be loaded in the browser.

Jotr — Jot down your ideas, thoughts and notes in the terminal.

How many times in our developer life have we thought of an idea or written notes in sublime text for future reference and never touched that file again or did not find the file when we wanted to?

☝️ This happens to me very often. I even started writing notes and code snippets on my own chatbox in slack simply because it faked single source of information but it is a hassle to track.

When I moved from Windows to Ubuntu there are two things I have come to love very much: Keyboard and The Almighty Terminal.

So, I found this little tool bundled up as a npm package that can jot down your ideas, thoughts and notes in the comfortable space of terminal some weeks back. It’s called Jotr and is developed by Morten Olsrud.

Installation

npm i jotr -g

Adding notes

// one liner note
jotr [tags] -c <your jot>
example:
jotr javascript -c 'let' is scoped to a block
// multi line note
jotr [tags]
This clears the terminal window and opens up a editor with an empty space to write your heart out.

Note: that you can have multiple tags. The jot is stored with all tags.

Listing and searching notes

// list all notes
jotr -l
// filter notes by tags
jotr -l [tags]
example:
jotr -l c++ pointers
//filter notes by specific terms
jotr -g term
example
jotr -l term

Editing and deleting notes

// open the entire YAML-file for editing
jotr --edit
// completely empty the data file (delete all jots)
jotr --purge

Exporting notes

jotr --export some_filename.json // export as json file
jotr --export some_filename.yml // export as YAML file

Learn more about the tool here.

--

--

I am a Software Engineer under construction and a hobbyist writer who writes about Software Development and the constant rambling thoughts inside my head.