Deploy Golang Application
This guide will help you deploy a Golang application using FlashPanel's Service feature for auto-restart and reverse proxy with Nginx.
Prerequisites
- Server connected to FlashPanel
- Domain DNS pointed to the server
- Access to FlashPanel
Step 1: Install Go (Golang)
Use the Application feature in FlashPanel to install Go:
- Go to FlashPanel → Select server → Applications
- Find and select Go from the application list
- Click the Install button to install Go
After installation, open terminal to verify:
/usr/local/go/bin/go versionWARNING
You only need to install Go once on the server. If you already have Go installed, you can skip this step. Check the Applications list to see if Go is already present.
Step 2: Install and Configure Database (Optional)
If your Golang application needs to connect to a database, you can install and manage databases through FlashPanel. FlashPanel supports the following database types:
- MySQL - Popular relational database management system
- MariaDB - Open-source fork of MySQL
- PostgreSQL - Advanced relational database management system
- MongoDB - NoSQL database
All of the above databases have:
- Installation feature via Application
- Database and user management dashboard via Database
Install Database
Use the Application feature in FlashPanel to install a database:
- Go to FlashPanel → Select server → Applications
- Find and select the database you want to install (MySQL, MariaDB, PostgreSQL, or MongoDB)
- Click the Install button to install the database
WARNING
If the database is already installed, you can skip this step. Check the Applications list to see if the database is already present.
Create Database and User
Use the Database feature in FlashPanel to create database and user:
Create Database User
- Go to FlashPanel → Select server → Database
- Click Create database user
- Fill in information:
- Username: User name (e.g.,
myapp_user) - Password: Strong password for the user
- Access scope: Select access scope (localhost or remote)
- Username: User name (e.g.,
- Click Save to create the user
Create Database
- Still in the Database tab, click Create Database
- Fill in information:
- Database name: Database name (e.g.,
myapp_db) - Users: Select the user created above to grant access
- Database name: Database name (e.g.,
- Click Save to create the database
WARNING
Save the following information for use in the next steps:
- Database name (e.g.,
myapp_db) - Database username (e.g.,
myapp_user) - Database password
- Database host (usually
localhost) - Database port (MySQL/MariaDB:
3306, PostgreSQL:5432, MongoDB:27017)
Step 3: Create Website with Reverse Proxy
Go to FlashPanel → Select server → Sites → Add new site
Fill in website information:
- Domain: Enter your domain (e.g.,
api.example.com) - Proxy Port: Select a port for your Golang application to run on (e.g.,
8080) - PHP Version: Not needed (this is a Golang application)

- Domain: Enter your domain (e.g.,
Click Add site to create the website
Point DNS domain to the server IP and install SSL for the website
Step 4: Upload and Build Golang Application
Upload Source Code
There are 2 ways to get source code on the server:
Method 1: Upload via File Manager in FlashPanel
- Go to Sites → Select website → File Manager
- Upload source code files to the website directory
Method 2: Clone from Git
Use the Source Code feature in FlashPanel to clone source code from Git:
Go to FlashPanel → Select website → Source Code
Choose one of the following options:
Option A: GitHub/GitLab/Bitbucket (Recommended)
- Select GitHub, GitLab, or Bitbucket
- Select repository and branch you want to deploy
- Choose
Automatically add deployment key (Recommended) - Click Install GitHub/GitLab/Bitbucket Repository
WARNING
Before using GitHub/GitLab/Bitbucket, you need to connect your Git account with FlashPanel first.
Option B: Git Repository
- Select Git
- Enter SSH URL of the repository (e.g.,
[email protected]:username/repo.git) - Enter branch name (e.g.,
mainormaster) - Choose
Automatically add deployment key (Recommended)if you haven't registered a server global key - Click Install Git Repository
WARNING
Before using Git Repository, you need to add FlashPanel SSH key to your Git provider first.
After installation completes, source code will be cloned to the website directory
Build Golang Application
Open terminal for the site, run the following commands:
# Navigate to website directory
cd /home/flashpanel/your-domain.com
# Build application (replace main.go with your main file if different)
/usr/local/go/bin/go build -o app main.go
# Or build optimized for production
CGO_ENABLED=0 GOOS=linux /usr/local/go/bin/go build -a -installsuffix cgo -o app main.goWARNING
- Replace
your-domain.comwith your actual domain - Replace
main.gowith your application's main file if different - The binary file after building will be named
app(or the name you specify)
Create .env File for Environment Variables
Create a .env file in the website directory to store configuration:
cd /home/flashpanel/your-domain.com
nano .envAdd necessary environment variables:
# Database configuration (change according to your database type)
DB_HOST=localhost
DB_PORT=3306 # MySQL/MariaDB: 3306, PostgreSQL: 5432, MongoDB: 27017
DB_USER=myapp_user
DB_PASSWORD=your_strong_password_here
DB_NAME=myapp_db
# Application configuration
APP_PORT=8080
APP_ENV=productionSave the file (Ctrl+O, Enter, Ctrl+X in nano)
Step 5: Test Run the Application
Before creating the service, test if the application runs correctly:
cd /home/flashpanel/your-domain.com
./appIf the application runs successfully, you will see startup logs. Press Ctrl+C to stop the application.
WARNING
Make sure your application reads environment variables from the .env file or from system environment variables. If your application doesn't read .env, you will need to configure it in the service file in the next step.
Step 6: Create Systemd Service for Auto-Restart
Use the Systemd Service management feature in FlashPanel to create a service that automatically restarts your application.
Create Service in FlashPanel
Go to FlashPanel → Select server → Services → Add new service
Fill in service information:
- Service Name: Service name (e.g.,
myapporgolang-app) - Description: Service description (e.g.,
Golang Application - api.example.com)
- Service Name: Service name (e.g.,
Configure the Service as follows:
[Unit]
Description=Golang Application - your-domain.com
After=network.target mysql.service
# Replace mysql.service with mariadb.service, postgresql.service, or mongod.service depending on your database
[Service]
Type=simple
User=flashpanel
WorkingDirectory=/home/flashpanel/your-domain.com
ExecStart=/home/flashpanel/your-domain.com/app
Restart=always
RestartSec=10
StandardOutput=append:/var/log/services/myapp.log
StandardError=append:/var/log/services/myapp-error.log
# Environment variables (if application doesn't read from .env)
Environment="DB_HOST=localhost"
Environment="DB_PORT=3306" # MySQL/MariaDB: 3306, PostgreSQL: 5432, MongoDB: 27017
Environment="DB_USER=myapp_user"
Environment="DB_PASSWORD=your_strong_password_here"
Environment="DB_NAME=myapp_db"
Environment="APP_PORT=8080"
Environment="APP_ENV=production"
[Install]
WantedBy=multi-user.targetClick Add service to create the service
After creating the service, click the Enable button to automatically start the service when the server reboots
Click the Start button to start the service immediately
WARNING
Important:
- Replace
your-domain.comwith your actual domain - Replace
flashpanelwith the user that the website is running on (usually the domain name without dots) - Replace
myappin the service name and log files with the name you chose - Replace environment variable values with your actual information
APP_PORTmust match the Proxy Port you set when creating the website (e.g.,8080)- If your application reads from the
.envfile, you can omit theEnvironmentsection or only add variables not in.env After=mysql.serviceensures the database starts before the Golang application starts. Change the service name depending on your database (mysql.service, mariadb.service, postgresql.service, or mongod.service)DB_PORTneeds to be changed according to database type: MySQL/MariaDB:3306, PostgreSQL:5432, MongoDB:27017
Step 7: Check and Manage Service
View Service Status
In FlashPanel → Services, you can:
- Start: Start the service
- Restart: Restart the service
- Stop: Stop the service
- View log: View normal log
- View error log: View error log
- Enable/Disable: Enable/disable auto-start on server reboot
View Application Logs
To view detailed logs, you can:
- View logs in FlashPanel: Click View log or View error log
- View logs directly on the server:
# Normal log
tail -f /var/log/services/myapp.log
# Error log
tail -f /var/log/services/myapp-error.logStep 8: Test the Application
- Access your domain through a browser:
https://your-domain.com - If the application runs successfully, you will see it working
- If there are errors, check logs in FlashPanel or on the server
Troubleshooting
Application Won't Start
- Check error logs: Services → Click View error log
- Check executable permissions of the binary file:
chmod +x /home/flashpanel/your-domain.com/app- Check if the path in the service file is correct
- Test manual run to see errors:
cd /home/flashpanel/your-domain.com
./appDatabase Connection Error
- Check if the database is running:
# MySQL/MariaDB
sudo systemctl status mysql
# or
sudo systemctl status mariadb
# PostgreSQL
sudo systemctl status postgresql
# MongoDB
sudo systemctl status mongodOr check in FlashPanel → Applications → Select your database → View status
Check connection information in the
.envfile or service file. Make sure the information matches the database and user created in FlashPanel → DatabaseTest database connection manually:
# MySQL/MariaDB
mysql -u myapp_user -p myapp_db
# PostgreSQL
psql -U myapp_user -d myapp_db
# MongoDB
mongo -u myapp_user -p --authenticationDatabase myapp_db- If you forgot database information, you can view it again in FlashPanel → Database tab
Reverse Proxy Error
- Check if the application is running on the correct port:
sudo netstat -tlnp | grep 8080- Check if the Proxy Port configuration in the website is correct
- Restart Nginx:
sudo systemctl restart nginxSummary
After completing the above steps, you have:
✅ Installed Go on the server
✅ Installed and configured MySQL
✅ Created website with reverse proxy
✅ Built and uploaded Golang application
✅ Created Systemd Service for auto-restart
✅ Configured environment variables
✅ Application ready to serve via domain with SSL
Your Golang application is now successfully deployed with:
- Reverse proxy via Nginx
- Auto-restart when server reboots or application crashes
- SSL/HTTPS security
- Log management for easy monitoring