Running websites in Go

Running websites in Go

Running web apps in Go on a shared hosting server that provides apps running on a proxy custom port which can then be mapped to the domain

With a $5/mo DigitalOcean or even a $2.50/mo Vultr account you can get a whole VPS running with n number of low traffic sites running on few hardware resources. This is a good starting point for a website / app that you may want to scale on a higher level if it can bring in decent business or maybe just leads or footfalls if not business-oriented.

But if you don't know how to set up a linux server with security / firewall or you're just a rookie in system administration then you'll find yourself spending a whole lot of time setting up the server before you even try to deploy your app after which you'll defintely land up with configuration issues. All this ... just to deploy your app which you are eagerly waiting to see how it runs online.

This is tiresome from a developer's point of view. What if you know someone who is an expert in linux server administration ? Good. Can you depend on that person all the time when something requires immediate attention like an update or bug fix or server restart ?

Most (like > 90%) shared web hosting companies offer PHP out of the box which is one of the reasons why PHP is the most popular stack in the world wide web.

But the hosting company where my sites sit on, on a fully managed shared server, OpalStack.com, has the option to deploy an entirely new / different server like Tomcat running on a new proxy port which can then be connected to a domain. All this without root access as the entire app, sometimes including the server, would be in your home directory with a custom random 5-digit port number.

(OpalStack also offers VPS and Dedicated servers which is 100% fully managed and relieves the developer from setup - and even if there is something that is strictly required with root access, Sean of support would gladly set it up for you at no extra cost ! - This sounds like a paid promo isn't it ? It's not - I am just so exited that I also got a Tomcat 10 server running in my home directory on a custom port app - so much stress relieved from server administration)

Here are the steps required to run a Go app on a shared hosting account on OpalStack.com :

  1. Create a new proxy port app at my.opalstack.com/apps and make a note of its port assignment. Let's say this app name is called go.

  2. Assign the app to a site at my.opalstack.com/domains - let's say this site is connected to go.my-domain.com.

  3. SSH into the server and goto the app folder go and download or clone this repo : github.com/tsawler/bookings-udemy/tree/v27

  4. mkdir ~/tmp && export TMPDIR=$HOME/tmp

  5. nohup go run cmd/web/*.go >> ~/logs/apps/go/app.log 2>&1 &

  6. Now you can goto go.my-domain.com in the browser and it'll show a homepage and has an about page at go.my-domain.com/about

If you are interested in knowing how to create web apps in Go, I recommend this Udemy courses by Trevor Sawler : udemy.com/user/trevor-sawler

Did you find this article valuable?

Support Anjanesh by becoming a sponsor. Any amount is appreciated!