is one of the most beloved companies on the internet for me and for many others. However, many feel orphaned due to their decision to . Heroku terminate their free products Some other free or cheap services can replace part of Heroku’s free products, but what about having your own hosting solution for your apps on the cloud for free? I'm going to show you how to do that by installing , a free, self-hosted, alternative to Heroku, on an VM, step by step. Dokku Oracle Cloud Requirements An . Oracle offers, at the time of this writing, two free VMs per user. It can be a trial account or a standard one. We are only going to use Oracle Cloud account free resources. with ssh keys installed; git An you can deploy to Dokku (something you would deploy to Heroku); app A you own (we are going to call it ); domain <your-domain-name> A drink and a snack. 1 - Creating the VM Go to , click . Give it a name. Compute → Instances Create Instance Go to Select for the image. For the shape, select Image and Shape. Canonical Ubuntu, version 18.04 VM.Standard.E2.1.Micro; Go to Select the existing and . Create one if you don’t have one already. Choose Networking. Primary Network Subnet Assign Public IP Address; Go to . Either generate a key pair (requires installing them on your system), upload or paste your own public key; Add SSH Keys Click . Wait until the VM finishes provisioning (the orange box turns to green); Create On the VM page, click on the link to your ( ); subnet Primary VNIC section Click on the on the panel; Default Security List Security Lists Check if there are for ports 80 and 443 (likely not); Ingress Rules Create an with the following settings: Ingress Rule Stateless: CheckedSource Type: CIDRSource CIDR: 0.0.0.0/0IP Protocol: TPCSource Port Range: leave blank Destination Port Range: 80,443 Description: HTTP(s) 2 - Installing Dokku Now return to the Instances page and copy your VM's (we are going to call it from now on); Public ID <public-ip> Open a terminal; SSH into the VM with (if asked if you want to continue, type yes); ssh ubuntu@<public-ip> Run the following commands (depending on when you are doing this, it may be wise to check Dokku’s website for updated commands): wget https://raw.githubusercontent.com/dokku/dokku/v0.28.1/bootstrap.sh sudo DOKKU_TAG=v0.28.1 bash bootstrap.sh Wait while Dokku is installed, this will take around 5 to 8 minutes; Open your ssh public key on a text file (or on the terminal) and copy its contents. Let's call them . Then run the next command: <CONTENTS_OF_ID_RSA_PUB_FILE> echo '<CONTENTS_OF_ID_RSA_PUB_FILE>' | sudo dokku ssh-keys:add admin 3 - Setting up Global Domains Remember that we talked about? It's the domain you are going to use as the global domain for your Dokku installation. Now run the following commands: <your-domain-name> dokku domains:clear-global dokku domains:add-global <your-domain-name> Now may also be a good time to set up your domain's DNS fields. I'm using Namecheap and I just had to create two (* and @) pointing to . A fields <public-ip> 4 - Creating your first app We are going to create our first app on Dokku and deploy it from our local computer. I'm using a basic Sinatra app, but you can use any technology supported by Dokku (Rails, Django, Node, PHP. The list goes on). I'm gonna call this app Starter. You can use any name you want (let's call it . Run the following command: <your-app-name> dokku apps:create <your-app-name> 5 - Deploying your app Depending on the stack you are using, there may be different requirements for your deployment. In my case, I'm using so I need to have a config.ru file or a PROCFILE. You may also need (and want even if not needed) to install (you can use Heroku's buildpacks which are open source). Please check Dokku documentation about that. Sinatra buildpacks With a terminal in your project folder, setup git: git init git add . git commit -m "create app" git remote add dokku dokku@<public-ip>:<your-app-name> git push dokku master The app will be created with the default subdomain of . For instance: if your app is called starter and your domain example.com, the app domain will be . But you can point your domain name directly to the app with the command (in our case: ). That way our app would be visible directly on . <your-app-name>.<your-domain-name> starter.example.com dokku domains:add <your-app-name> <your-domain-name> dokku domains:add starter example.com example.com 6 - Accepting web requests on your VM Opening the ports on the network isn't enough. You need to enable web traffic on the VM's (at least for Oracle Cloud’s version of Ubuntu 18.04): iptables sudo iptables -P INPUT ACCEPT sudo iptables -P OUTPUT ACCEPT sudo iptables -P FORWARD ACCEPT sudo iptables -F 7 - Enabling SSL with Letsencrypt Run the following commands: sudo dokku plugin:install https://github.com/dokku/dokku-letsencrypt.git dokku config:set --no-restart <your-app-name> DOKKU_LETSENCRYPT_EMAIL=<your-email-address> dokku letsencrypt:enable <your-app-name> If you run into errors you may want to try and retry sudo service docker restart dokku letsencrypt:enable <your-app-name> And now your app should be up and running on https://<your-app-name>.<your-domain-name> The End And that's all for now. You should be able to run one reasonably sized app on this VM or multiple smaller apps. You can install buildpacks for databases (like Postgresql) and connect your apps to them. Oracle Cloud provides two free VMs so you can play a little bit with it. VM.Standard.E2.1.Micro Of course, if you consider using this kind of hosting for serious apps, you will probably want to go with a stronger VM and robust services around it. Sources / Further Reading Getting Started with Dokku - Dokku Documentation https://stackoverflow.com/questions/54794217/opening-port-80-on-oracle-cloud-infrastructure-compute-node Free Tier: Install Apache and PHP on an Ubuntu Instance
Share Your Thoughts