Deploy a go backend to web-hoster?

Hi,
Sorry for the basic question. I’m a total noob. In go and any other language.
Can I deploy a go backend to a regular web-hoster? I mean, for example the hoster I use allows instances of various CMSs and obviously PHP code. I only see this because the PHP version is a very prominent setting in my webspace.
How about go? Can this run on a regular webserver?

Background: I’d like to start learning programming. For some reasons I’d prefer to do so in go. I’m not super interested in programming web stuff, but “unfortunately” the only actual usecase I currently have is a webpage with some DB functionality in the background. And since I found that learning programming without an actual problem in mind is futile, this would be me first project.

Thanks in advance!

If you have root access it should be possible. But I guess that you will have to use a VPS or similar.

Hmm, sure, but this sounds to me like I’d be installing an application on a virtual linux server, not really something on a web server. Am I mixing up things?

What host are you planning on using? This is an incredibly broad question, like “how do I built an app?”. I would hone in on what you’re trying to build, and where you want to deploy it, then start asking specific questions. Here are a few ideas though:

1 Like

Sorry, maybe I’m expressing myself not well enough (I’m not native English. I have good understanding of technology, but zero programming skills - yet) Let me try again:
My current provider supports PHP. I upload the website’s files, HTML and also .PHP files and the website just “runs”.
AFAIK this is also the case with a self-hosted Apache server. It just “understands” PHP.

Are there providers which support go in the same way?
I had a quick look at Vultr and at first glance this looks like it’s a Cloud host. So I rent a slice of an operating system and can make it do anything, including interpreting go. But AFAIK this is a totally different thing and much more costly than just buy some webspace.

The purpose of my question is only to find out, if this website (a re-write of our old Choir page) is a worthy first project and go is ideal for it, or if such things are still better written in PHP. Then I’d just look for something else to start with.

Not quite to my knowledge, but you can get something KIND of close to that. Check out Google Cloud Run (I linked to it above). It’s slightly more complicated but you can do a similar “ship it and not worry about servers” approach. It scales down to 0 and has a free tier which is nice as well.

It really depends. You can get a server for like $5 a month. But you can probably host cheap static sites for free depending on where you host them.

That sounds like static content to me. In which case Go is probably not ideal. You could probably use a static content generator (check out Hugo and Jekyll + GitHub Pages!).

I have a different opinion. Go is IMHO well suited for static web sites. But Hugo may be an option.

Go is a good choice for web development in general, but I cannot say for your site as I have never seen it. But this site is built by Go and here is how I hosted it. Basically a Go web site is built by Go html templates together with CSS and Javascript if needed.

1 Like

It’s fine, but it’s not exactly the first tool I’d reach for for this purpose. Like - you could also use Rust to build an executable that serves static content, but I wouldn’t SUGGEST it unless you had a reason (maybe you wanted to learn Rust, maybe you already know Rust really well so it’s fast for you to build it using Rust, etc.).

Just for example, in your guide you have 9 steps to get it deployed (setting up a reverse proxy, etc.). If you used something like GitHub Pages and a static site generator, that would be simplified to something like “check in your code to your repo, it builds automatically and is automatically hosted”. I’m not trying to discourage anybody and Go is a very useful tool that I use daily in my career, but I’m also not going to say that Go is the best tool for ALL jobs.

That said, @reach if you want to learn Go, this would be a fine project. Maybe let us know what you consider cheap hosting-wise and we can suggest hosts (I think Digital Ocean has a $4/month droplet). You can then start asking more specific questions along the way.

My provider, which is coincidentally the same as the one our choir page runs on charges more than 4$/month (I think 8 EUR), so that argument indeed mute. I think, for these 8 EUR I also get SSH access to the server, but I don’t know, if I can execute code on it.
So go it is. Please don’t expect me to present the result here anytime soon - this is a long term project for sure :slight_smile:

Regardless of whether it is the most straightforward solution to your proposed problem as Dean points out, Go is a relatively simple language that promotes straightforward code, and one of it’s primary use cases is web stuff. Learning to program in Go by implementing web stuff sounds like a great start. An advantage to learning with Go is that it is strongly and statically typed. It likely goes against the current trends, and maybe it’s just that I’m older, but I think learning with types early is good. I’ve seen some young devs that learned programming with dynamic languages have a hard time picking up static typing later.

Just to get you started on serving static content (and you can start adding more dynamic stuff later), check out this example for a file server:

About as easy as it gets. If you want to start mixing logic in with that, check out this blog post I did a while ago with a kind of hybrid approach:

Or just clone this repo and run it:

Haha, what you write is one of the reasons for me to chose go. I’m 47 years old, can’t write a single line of code in any language, but I have a fairly good understanding of the matter. Good enough so weak typed languages look like voodoo to me. How can I just use a variable without declaring it first? :slight_smile: It feels dirty.
But that’s off topic and shouldn’t trigger a principle discussion. Surely I understand that every problem needs the right tools and that these languages have very good reasons to exist.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.