Plesk & SocialBee have teamed up. Save 30% now!

How to Host a Go App on Plesk

In modern web development, deploying applications is crucial to bringing your software to life. The Go programming language, a statically typed and compiled language known for its efficiency and performance, has gained immense popularity among developers. You can build robust and high-performance web applications by leveraging the power of Go.

However, deploying Go applications can be complex, requiring a solid grasp of server configurations, environment settings, and other technical nuances. This is where the Plesk control panel comes into play as a game-changer. Plesk, a powerful web hosting control panel, provides an intuitive and user-friendly interface for managing various web hosting and server administration aspects.

In this article, we’ll take you through the process of running Go applications with Plesk, step by step. We’ll show you how to harness the benefits of both Go’s speed and the Plesk control panel’s ease of use, making hosting and managing your web applications more effortless than ever.

You’ll learn how to prepare your Go application for deployment, set up Plesk, configure your server environment, and deploy your application successfully. By the end of this guide, you’ll clearly understand how to utilize Plesk to streamline the deployment of your Go applications, reducing the technical complexities that often come with hosting web applications.

Whether you are a beginner or an experienced developer, this article will equip you with the knowledge and tools to run Go applications on your server efficiently.

Prerequisites

Before diving into the process of running Go applications with Plesk, it’s essential to ensure you have the necessary prerequisites in place. Here’s a detailed breakdown of what you need:

Plesk Installation

To use Plesk, you must install it on your server. Ensure you have the latest version installed, or the version you intend to use. If you haven’t already installed Plesk, you may need to follow the official installation guide for your specific server and operating system. There is no need to worry about the license, you can get a two-week trial license right from the panel.

Server or Hosting Environment

You should have access to a server or hosting environment where Plesk is installed. This environment will be the foundation for hosting your Go application.
Also, you need to know that Docker is available only for Plesk administrators.

Go Knowledge

While this guide will walk you through the technical aspects of deploying Go applications, having a basic understanding of the Go programming language is beneficial. You should be familiar with concepts like package management, building, and running Go applications.

With these prerequisites in place, you’ll be well-prepared to follow the steps in this guide for running your Go application with Plesk. It’s essential to ensure you have a reliable hosting environment (Plesk), as well as a basic understanding of Go, to make the process smoother and more efficient.

Preparing Your Go Application

Before you can deploy a Go application with Plesk, you’ll need to prepare your application for hosting. For demonstration purposes, let’s create a simple HTTP application. Here are the steps to follow:

1. Create a directory for the project:
mkdir go-http-sample
cd go-http-sample
2. Create the main.go file in the go-http-sample directory:
package main

import (
"fmt"
"net/http"
)

func hello(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hello\n")
}

func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":8090", nil)
}

3. Test your application locally:
#> go run main.go &         
~/Source/go-http-sample
#> curl localhost:8090/
hello
4. Then let’s create a sample Dockerfile:
FROM golang:1.20.10-alpine3.18 as builder

WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o ./http-server

FROM scratch

WORKDIR /app
COPY --from=builder /app/http-server .
EXPOSE 8090
CMD ["/app/http-server"]

5. Test your docker image:
#> docker run -itd -p 8090:8090 $(docker build -q .)
dae1ae701a2f876978874e995420080cd86f66c95bc6b2f0db39bed2e849e2d7
~/Source/go-http-sample
#> curl localhost:8090/
hello
Cool, so everything should be working as expected and we can now prepare the Plesk control panel!
 

Setting Up Plesk 

I’m assuming you already have a Plesk instance. Then, you need to install a docker extension. You can do it easily via the extension catalog.  
How to Host a Go App on Plesk - Plesk blog post

Plesk has a useful feature – you can create a domain with a temporary domain name for the test purpose, so let’s create a new domain.

How to Host a Go App on Plesk - Plesk blog post

Nice, now we have a test domain, and we can deploy our test service.

How to Host a Go App on Plesk - Plesk blog post

Deploying Your Go Application

First of all, we need an image that we have to run on our server. You can do it by the command (I’m using MacOS)

#> docker buildx build --platform=linux/amd64 -t go-http-sample:latest .
#> docker save go-http-sample:latest | gzip > go-sample.tar.gz

Next, open the docker extension and upload the created image, then run it.
Also, you can push the image to the official Docker Hub.

How to Host a Go App on Plesk - Plesk blog post

In the settings, turn off auto port mapping. Next, open the Docker Proxy Rules:

How to Host a Go App on Plesk - Plesk blog post

Add the rule:

How to Host a Go App on Plesk - Plesk blog post

Testing Your Application

Now you can open a browser and follow the link: https://reverent-ganguly.139-59-209-22.plesk.page/ 

How to Host a Go App on Plesk - Plesk blog post

Conclusion

As you can see, you can simply deploy any Go application. Also, using Plesk control panel you can easily add an SSL certificate, maintain security fixes, monitor your application, and do many other important actions. Using the Docker extension, you can fully manage your application, update or restart it, view logs, and so on.

No comment yet, add your voice below!

Add a Comment

Your email address will not be published. Required fields are marked *

GET LATEST NEWS AND TIPS

  • Yes, please, I agree to receiving my personal Plesk Newsletter! WebPros International GmbH and other WebPros group companies may store and process the data I provide for the purpose of delivering the newsletter according to the WebPros Privacy Policy. In order to tailor its offerings to me, Plesk may further use additional information like usage and behavior data (Profiling). I can unsubscribe from the newsletter at any time by sending an email to [email protected] or use the unsubscribe link in any of the newsletters.

  • Hidden
  • Hidden
  • Hidden
  • Hidden
  • Hidden
  • Hidden

Related Posts

Knowledge Base

Plesk uses LiveChat system (3rd party).

By proceeding below, I hereby agree to use LiveChat as an external third party technology. This may involve a transfer of my personal data (e.g. IP Address) to third parties in- or outside of Europe. For more information, please see our Privacy Policy.