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 mainimport (
"fmt"
"net/http"
)func hello(w http.ResponseWriter, req *http.Request) {
fmt.Fprintf(w, "hellon")
}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 builderWORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o ./http-serverFROM 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.