“If you have two friends in your lifetime, you’re lucky. If you have one good friend, you’re more than lucky.”

― S.E. Hinton

If this is not one of the most robust, free, rich and informative era ever then I cannot think of any other time in history adorned with the wealth of technology as this one. If you would wish to accomplish anything, this era wields the most virile grounds to nourish, nurture and aid the sprouting, the growth and the maturity of your dreams. You can literaly learn to be what you would wish to be in this age.

That being said, this disquisition takes on a quest to get you into setting up something similar to Heroku on your own environment. We shall get to know what Heroku is then get off the dock and sail off towards our goal of having such an environment.

The proliferation of cloud technologies brought with it many opportunities in terms of service offerings. First and foremost, users had the ability to get as much infrastructure as they could afford. Users can spawn servers, storage and network resources ad libitum which is popularly known as Infrastructure as a service. Then comes the second layer that sits on the infrastructure. It could be anything, cloud identity service, cloud monitoring server et cetera. This layer provides ready made solutions to people who might need them. This is known as software as a service. I hope we are flowing together this far.

In addition to that there is another incredible layer that is the focus of this guide. It is a layer that targets developers majorly by making their lives easier on the cloud. In this layer , developers only concentrate on writing code and when they are ready to deploy, they only need to commit their ready project in a source control platform like GitHub/GitLab and the rest is done for them automatically. This layer provides a serverless layer to the developers since they do not have to touch the messy server side stuff. This layer as you might already have guessed is known as Platform as a Service (PaaS). Heroku is one of the solutions that sits on this layer.

In this guide, are going to setup a platform that is similar to Heroku on your own infrastructure. As you know, you cannot download and install Heroku on your server. It is an online cloud service that you subscribe to. We will use Caprover to setup our own private Platform as a service (PaaS).

CapRover is an extremely easy to use app/database deployment & web server manager for your NodeJS, Python, PHP, ASP.NET, Ruby, MySQL, MongoDB, Postgres, WordPress and even more applications.

Features of Caprover

  • CLI for automation and scripting
  • Web GUI for ease of access and convenience
  • No lock-in! Remove CapRover and your apps keep working!
  • Docker Swarm under the hood for containerization and clustering
  • Nginx (fully customizable template) under the hood for load-balancing
  • Let’s Encrypt under the hood for free SSL (HTTPS)
  • One-Click Apps: Deploying one-click apps is a matter of seconds! MongoDB, Parse, MySQL, WordPress, Postgres and many more.
  • Fully Customizable: Optionally fully customizable nginx config allowing you to enable HTTP2, specific caching logic, custom SSL certs and etc
  • Cluster Ready: Attach more nodes and create a cluster in seconds! CapRover automatically configures nginx to load balance.
  • Increase Productivity: Focus on your apps! Not the bells and whistles just to run your apps!
  • Easy Deploy: Many ways to deploy. You can upload your source from dashboard, use command line caprover deploy, use webhooks and build upon git push

Caprover Pre-requisites

Caprover runs as a container in your server which can be any that supports containerization. Depending on your preferences, you can use Podman or Docker to pull and run Caprover image. For this example, we are going to use Docker. In case you do not have Docker installed, the following guides listed below will be there to help you set it up as fast as possible.

Another pre-requisite is a wildcard domain name pointed to the IP of your server where Caprover Server will be running.

Onto installing Caprover

Once the pre-requisites are out of the way, the only task remaining now is to set up our Caprover and poke around its rooms just to see what it has to offer. The following steps will be invaluable as you try to get it up and running.

Step 1: Prepare your server

Once Docker is installed, you can install all of the applications you need during your stay in the server. They include an editor and such kind of stuff.

##On CentOS

sudo yum update
sudo yum install vim git curl 

##On Ubuntu
sudo apt update
sudo apt install vim git curl

That was straingtforward. Next, let us pull Caprover image to set the stone rolling

Step 2: Pull and execute Caprover Image

We are going to cover the installation of Caprover depending on where your server sits.

Scenario 1: Installation on a local server without Public IP

Install dnsmasq

After all, as mentioned in the pre-requisites section, we shall need a small DNS server to resolve domain names since Caprover is so particular with it. In case you have a local DNS server that supports wildcard domains, then you are good to go. You can skip the DNS setup part. In case you do not have it, install lightweight dnsmasq as follows:

sudo yum -y install dnsmasq

After dnsmasq is successfully installed, start and enable the service.

sudo systemctl start dnsmasq 
sudo systemctl enable dnsmasq 
Add Wildcard DNS Recod

Once dnsmasq is running as expected, we can go ahead and add the configs and wildcard domain name as shown below:

$ sudo vim /etc/dnsmasq.conf

listen-address=::1,127.0.0.1,172.20.192.38
domain=example.com
server=8.8.8.8
address=/caprover.example.com/172.20.192.38

Replace the IPs therein with yours accordingly.

Then restart dnsmasq

sudo systemctl restart dnsmasq

Test if it works

We shall use the dig utility to test if our configuration works

$ dig @127.0.0.1 test.caprover.example.com

; <> DiG 9.11.20-RedHat-9.11.20-5.el8 <> @127.0.0.1 test.caprover.example.com
; (1 server found)
;; global options:  cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32435
;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;test.caprover.example.com.     IN      A

;; ANSWER SECTION:
test.caprover.example.com. 0    IN      A       172.20.192.38

And it does!!

Next, since we are going to install Caprover on a local server, we will have to tweak our installation a little bit. We will create a directory and inject some configs into it then run our image with an environment variable that will represent the Public IP though it is a private IP. Proceed as follows

sudo mkdir /captain/data/
echo  "{"skipVerifyingDomains":"true"}" | sudo tee -a  /captain/data/config-override.json

After that, run the following docker command to pull and run the image. You will observe this on the command: “-e MAIN_NODE_IP_ADDRESS=172.20.192.38“. Since my local server does not have a public IP, “MAIN_NODE_IP_ADDRESS=172.20.192.38” tells Caprover to use the private IP “172.20.192.38” instead.

$ docker run -p 80:80 -p 443:443 -p 3000:3000 
  -e MAIN_NODE_IP_ADDRESS=172.20.192.38 -d 
  -v /var/run/docker.sock:/var/run/docker.sock 
  -v /captain:/captain caprover/caprover

##Sample Output you will observe
latest: Pulling from caprover/caprover
0400ac8f7460: Pull complete
fa8559aa5ebb: Pull complete
da32bfbbc3ba: Pull complete
e1dc6725529d: Pull complete
572866ab72a6: Pull complete
63ee7d0b743d: Pull complete
81a57610b526: Pull complete
8aa72b0fc009: Pull complete
caec757d11e1: Pull complete
adcef7d4d562: Pull complete
9b93a1807495: Pull complete
f5a44e685611: Pull complete
72b9d183035e: Pull complete
42af16174623: Pull complete

Captain Starting ...
Installing Captain Service ...

 Installation of CapRover is starting...
For troubleshooting, please see: https://caprover.com/docs/troubleshooting.html

 >>> Checking System Compatibility <<<
   Docker Version passed.
******* Warning *******    CapRover and Docker work best on Ubuntu - specially when it comes to storage drivers.
   X86 CPU detected.
   Total RAM 3985 MB
Pulling: nginx:1
Pulling: caprover/caprover-placeholder-app:latest
Pulling: caprover/certbot-sleeping:v1.6.0
December 15th 2020, 2:07:30.014 pm    Fresh installation!
December 15th 2020, 2:07:30.016 pm    Starting swarm at 172.20.192.38:2377
Swarm started: 0jz01mmwwg5ifoncrhqz0evee
*** CapRover is initializing ***
Please wait at least 60 seconds before trying to access CapRover.

Scenario 2: Installation on a cloud server with Public IP

Here, we are going to fetch a ready-made image that Caprover provides and then proceed to run it. It is a one liner as shared below. Caprover should automatically find the Public IP and continue with installtion

$ docker run -p 80:80 -p 443:443 -p 3000:3000 
  -v /var/run/docker.sock:/var/run/docker.sock 
  -v /captain:/captain caprover/caprover

##Sample Output you will observe
latest: Pulling from caprover/caprover
0400ac8f7460: Pull complete
fa8559aa5ebb: Pull complete
da32bfbbc3ba: Pull complete
e1dc6725529d: Pull complete
572866ab72a6: Pull complete
63ee7d0b743d: Pull complete
81a57610b526: Pull complete
8aa72b0fc009: Pull complete
caec757d11e1: Pull complete
adcef7d4d562: Pull complete
9b93a1807495: Pull complete
f5a44e685611: Pull complete
72b9d183035e: Pull complete
42af16174623: Pull complete

Captain Starting ...
Installing Captain Service ...

 Installation of CapRover is starting...
For troubleshooting, please see: https://caprover.com/docs/troubleshooting.html

 >>> Checking System Compatibility <<<
   Docker Version passed.
******* Warning *******    CapRover and Docker work best on Ubuntu - specially when it comes to storage drivers.
   X86 CPU detected.

Connect Root Domain

After the container runs, you will now need to connect your Caprover instance to a Root Domain.

Let’s say you own example.com. You can set *.something.example.com as an A-record in your DNS settings to point to the IP address of the server where you installed CapRover. To do this, go to the DNS settings in your domain provider website, and set a wild card A record entry.

For example: Type: A, Name (or host): *.something.example.com, IP (or Points to): 110.122.131.141 where this is the IP address of your CapRover machine.

TYPE: A record

HOST: *.something.example.com

POINTS TO: (IP Address of your server)

TTL: (doesn’t really matter)

To confirm, go to https://mxtoolbox.com/DNSLookup.aspx and enter somethingrandom.something.example.com and check if IP address resolves to the IP you set in your DNS. Note that “somethingrandom” is needed because you set a wildcard entry in your DNS by setting *.something.example.com as your host, not something.

Step 3: Accessing our CapRover PaaS

Once the CapRover is initialized, you can visit http://[IP_OF_YOUR_SERVER]:3000 in your browser and login to CapRover using the default password “captain42“. You can change your password later. However, do not make any changes in the dashboard. We’ll use the command line tool to setup the server. You should see something like this:

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

Enter the default password and you should be smoothly ushered in

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

Step 4: Setting up Caprover

Similar to the installation of Caprover, we shall configure it depending on where your server sits.

Scenario 1: Setting up on local computer

In this scenario, there is no need of running extra tools to setup caprover. Instead, go to http://[IP_OF_YOUR_SERVER]:3000 and manually set root domain to caprover.example.com. DO NOT enable/force HTTPS. Obviously, you cannot enable HTTPS on your local domain (caprover.example.com).

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

Once you set your root domain as caprover.example.com, you will be redirected to captain.caprover.example.com. Use caprover login and enter captain.caprover.example.com as your captain URL and captain42 as your default password once again. You will be logged in with the new url.

Guess what! you are finally set!

Scenario 2: Setting up on a cloud computer with Public IP

In this scenario, we already set the root domain to point to the Server running Caprover. Caprover team recommends setting up the server using its CLI tool. Before we proceed, you should understand that the server we just deployed can be running in the cloud and this CLI tool we are about to install can be setup in your local machine. So open up your local machine and let us go ahead to install CapRover CLI.

Install NPM

Node Package Manager is required to get our CapRover CLI up and running. You can get NPM installed easily using the guides below:

Install Node.js on Ubuntu / Debian / Linux Mint

Install Node.js on CentOS & RHEL

Install Node.js on Ubuntu & Debian

Set up Caprover CLI

After Node and NPM are installed, fetch and setup caprover as follows. Give it sometime to install.

sudo npm install -g caprover

Once caprover is installed, we can now proceed to configure the server from our local machine. Run the following command

$ caprover serversetup

##Sample Output
------------
CapRover CLI has recently been refactored. Please report potential bugs here: https://github.com/caprover/caprover-cli/issues
------------


Setup CapRover machine on your server...

? have you already started CapRover container on your server? (Y/n) Y
? IP address of your server: 172.20.192.38
? CapRover server root domain:  caprover.example.com
? CapRover server root domain: caprover.example.com
? new CapRover password (min 8 characters): [hidden] 
? enter new CapRover password again: [hidden] 
? "valid" email address to get certificate and enable HTTPS: [email protected]

Once everything is done, we can now login using caprover login command

$ caprover login


------------
CapRover CLI has recently been refactored. Please report potential bugs here: https://github.com/caprover/caprover-cli/issues
------------


Login to a CapRover machine...

? CapRover machine URL address, it is "[http[s]://][captain.]your-captain-root.domain": https://captain.caprover.example.com
? CapRover machine password: [hidden]
? CapRover machine name, with whom the login credentials are stored locally:

Step 5: Using Caprover PaaS to host Applications

We are going to install a sample application on this platform so that we can appreciate how it does its thing. While logged in Caprover, click on “Apps” tab then add a name to your application and hit “Create New App“.

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

A new place to hold your application will be created as shown below. Click on its link so that we can add the flesh of the project.

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

While inside there, there are many settings you will find for you to explore under “HTTP Settings, App Configs and Deployment“.

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

Under Deployment, you will find various methods you can deploy your application, For example, you can use your code in Github/Bitbucket/Gitlab, you can use plain Dockerfile, captain-definition file, CLI and much more. Caprover is a beautiful tool.

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

Install Apache via Dockerfile

Let us install a simple apache app using the Dockerfile method as shown below

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

You will see the deployment progress

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

Once it is done, you can click on the “HTTP Settings” tab and you will find the url that you can use to access your application.

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

I know what you are thinking, this Caprover is amazing, right?

Step 6: Add monitoring to Caprover PaaS

Caprover team in their wisdom knew that metrics and visibility into the applications and infrastructure will be a key necessity. They therefore developed Netdata as part of their Ecosystem by making it very easy to install. Simply click on “Monitoring” tab then click on “Start NetData Engine“. No sooner do you click on that than it begins installing it.

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

Later, once the installation is complete, which you will know from a notification, simply click on “Open NetData

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

and you will be redirected to another tab of your browser with amazing graphics with metrics. A sample is shown below

Setup your own Heroku PaaS using CapRover Automation caprover Containers Featured How To Linux Tutorials paas

Closing Thoughts

As you have witnessed, Caprover works almost the same as Heroku. It makes the deployment of your applications as painless as possible and guess what, it is totally free and you have full control of your server/infrastructure. In case you found this tool to be something you can use, set it up and check it out for yourself. Such a blessing it is.

Otherwise, we wish you an amazing festive season and a fruitful time with your loved one. You can check other guides below for your perusal.

Install Docker and Docker Compose on Kali Linux

How To Install Netdata on Kubernetes using Helm