Search code examples
deploymentgoweb-deploymentproduction

Upload and Deploy Golang application to VPS


I've made a Go app and when I run the exe locally it works fine. Where would I upload this to on my VPS? public_html/domain.com/somefolder ? or /usr/somefolder with SSH?

I have my app, my .exe and src-files, but what do I do with it when I deploy online on my VPS? I haven't been able to find a tutorial about this, so I hope you can help me.

  1. do I upload all files in my src folder including the binaries from when I've written "go build"?
  2. upload to where on my VPS? using ssh or cpanel / ftp program or what?

What are the steps from "go build" on your own local windows 8 computer to uploading and running it online on a linux server?

Ps.

Additionally will CentOS 5.1.1 although not supported https://golang.org/doc/install - allow for me to run an already linux compiled go program on my VPS, and does it only mean that I cannot install Go and do compilation on the CentOS 5.x server? Would CentOS 5.1.1 explain the "segmentation fault" error shh gives me when running the command "./[filename]"?


Solution

  • Well, usually, you would:

    • Copy the binary you created + all resource files (html, css, images, ...)
      • (optionally the source code as well)
    • Have a way to ensure the program keeps running
      • crontab can be used to check if your program is alive, but a simple monitoring program would suffice as well (which you can write yourself)
    • Run the binary as a non-privileged user
      • (you can also combine it with something like Docker if you want)

    It does not make sense to put it inside public_html/domain.com/somefolder, as it is not public html code. You'd want your files somewhere they cannot be accessed unless using the application/binary you created.


    My apologies for not having neat source links to my story. However, this does seem like the best thing to do.


    Another important note: Even though your VPS may run Windows, you can also deploy linux binaries to a Linux VPS (which are drastically cheaper) - looking at this SO question.