How do I deploy a golang app with Apache installed on Ubuntu 16.04?

Posted October 27, 2016 26.2k views
ApacheApplicationsGoUbuntu 16.04

Hi everyone,
I am learning Go at the moment and I have built really simple webapps following some tutorials with the net/http package. I have created a simple wishlist, where I add an item and than it does to a simple table of things I want, pretty simple.

Now I want to deploy this app to my Digital Ocean droplet, but I just don’t know how. I have some php websites with different domains already with Apache behind it.

I am really a begginer on this “servers configuration” thing, usually with php is pretty easy on webhosts and I didn’t need this much experience. Can you point me on the right direction to make my Go app available at a domain I own, without the ports bit? Preferably with Apache.

Thanks :)

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers


Just like you would install Go on local machine, you need to do on server.

For help about it you can refer to How to Install Go 1.6 on Ubuntu 16.04.

We need now to install Golang app.
In case you use GitHub for hosting, you can use go get to pull it:

  • go get

If not, you need to copy from your local machine $GOPATH/src/... to servers one. In tutorial you will set $GOPATH to ~/work so you need to unpack it in ~/work/src/....
Then go in that directory and run:

  • go install

When you run app it should be working.
You can access it via http://DropletIP:port.

To make it work on port 80, you need to make Reverse proxy with Apache or Nginx.

If you already have Apache on Droplet, go with it. But if you setup new Droplet for it, I’ll recommend Nginx as it’s easier to setup for Reverse proxy and less memory intensive.

Tutorial how to do it on Nginx.
About Apache you’ll have to refer to Apache docs.

If you have any questions, feel free to ask, we will try to answer them :D

by Brennen Bearnes
Go is a modern programming language developed at Google. It is increasingly popular for many applications and at many companies, and offers a robust set of libraries. This tutorial will walk you through downloading and installing Go 1.6, as well as building a simple Hello World application.
  • Hi @xMudrii,
    thanks for your reply. I made it to http://DropletIp:port and its working, but if I close the terminal the application shuts down. How could I make it run on background?

    • You can try setting up systemd service.
      Try something like this. We will first create service file:

      • sudo nano /etc/systemd/system/yourapp.service

      With following content:

      sudo nano /etc/systemd/system/yourapp.service
      Description=App description

      Save that. I would create folder yourapp under /opt and in it store app. Red highlighted is location where app is located (app is executable file name).
      You can find executable under $GOPATH/bin.

      Now when you:

      • sudo systemctl start yourapp

      And try to access it should work.
      To enable it on boot use:

      • sudo systemctl enable yourapp

      Please note, I’m not on my PC so I didn’t test it but it should works. If you get problem I will try to correct it. :)

      • It’s not working, should I change more than ExecStart on that file? I’ve only changed that.

        Thanks again

        ~~Should I paste the content in src anywhere?~~

        I’ve added:


        To the service file and it is working now.

        Thanks for everything

You could use a tool like OpsCaptain to deploy golang apps to your droplet. Simply connect your droplet and then download the opscaptain cli and then run [opscaptain deploy] to deploy your go apps to your server. You can also create MySQL, MongoDB and PostgreSQL databases using opscaptain on your droplet. Backups are also supported. OpsCaptain allows you to deploy apps written in any language on your droplet. You never have to do any configurations anymore, simply use OpsCaptain to deploy all your PHP and Go apps on your droplet the easy way. Learn more here: