Serve landing page with Go Iris backend on CentOS

For one of my current project, I should serve landing page with Go Iris backend. So under more tage you can find a ready solution from me and deep explanation of how to prepare it for production.

Requirements and constraints

  • Server with CentOS 7.5. I used for it
  • Golang 1.11
  • All actions in this article done under root user

Install and configure Go

Get the needed version of Go

For this guide, I use Golang 1.11. In this article I get it by curl  instead of wget in my previous article:

curl -LO

Install Golang

Unpack it to /usr/local. Please do not change destination directory because it is the recommended path from the publisher:

tar -C /usr/local -xvzf go1.11.linux-amd64.tar.gz

Make needed dirs

For proper work of the Go, we need to create a workspace directory with bin, pkg and src subdirectories. I will use ~/workspace/go for it:

mkdir -p ~/workspace/go/{bin,pkg,src}

Setting paths for Go

Firstly we need to add /usr/local/go/bin to the $PATH variable by creating a custom sript in the /etc/profile.d directory:

vi /etc/profile.d/

and add to it following line:

export PATH=$PATH:/usr/local/go/bin

Also we should create the GOPATH and GOBIN variables in own user’s .bash_profile. Open it:

vi ~/.bash_profile

and add the following lines at the end of the file:

export GOBIN="$HOME/workspace/go/bin"
export GOPATH="$HOME/workspace/go"

That’s it. To apply the changes to your current session use source command instead simple reboot:

source /etc/profile && source ~/.bash_profile

You can check variables for go using:

go env

In my case I get somethig like this:

GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build135090936=/tmp/go-build -gno-record-gcc-switches"

Use golanding for serve a landing page

I’m developing for my purposes golanding – simple backend for serving static pages. I have app

For gettings things done we should install the git which needed for go get command:

yum install git 

Now we can get golanding from github by a simple command:

 go get -u

Remember, own sourses placed in ~/workspace/go/src. Change current directory:

cd ~/workspace/go/src/

At this time we can build current project by typing:

go build

After this in current directory appears golanding executable file which we can run as any other program:


But we will get an error linked with an absent .env file. About setup, you may check golanding Github Page but in a simple case you just need to create .env by copying .env.example:

cp .env.example .env

and change needed variables. Now we can start the golanding and see provided Coming Soon page on http://localhost:80


You may change .env for your needs

Prepare to production

Install golanding

inside golanding directory run:

go install

There are some differences between go build and go install but the main difference is that the go install build and place binary file to GOBIN directory (we set up is as ~/workspace/go/bin):

Put golanding in /opt directory

There are opinions that placing apps to home way is a bad way so we place golanding to /opt with .env file:

mkdir /opt/golanding
cp ~/workspace/go/bin/golanding /opt/golanding/golanding
cp ~/workspace/go/src/github/danilborchevkin/golanding/.env /opt/golanding/.env

Place landing page to /var/www directory

Good way so save your static pages is putting it to /var/www directory. If it not exist – create it.

Select directory fo UPLOAD_PATH

I think that put the uploads to /var/tmp is a good idea because the files inside /var/tmp directory periodically deleted. So problem about overflow is vanished by this feature.

Change .env file

We need to fix .env file because we put the landing page onto /var/www and for the uploads we start use /var/tmp.

Daemonize golanding

There are a lot of ways doing it (supervisor, forever, pmgo) but my choice is create a service for systemd. It’s quite simple.

Let’s create file /usr/lib/systemd/system/golanding.service with following content:

Description=golanding service



After this we need to enable and start own service:

systemctl status golanding
systemctl enable golanding
systemctl start golanding
systemctl status golanding

Cool – no dependencies=))

This is not the end

Manual deploy is a bad way if you need some agility. For your project will be better if you setup CI/CD for your project. Also, you need to check all security issues and the systemd’s service options – all of it should be revised and improved by yourself.

Option – firewall installation and setup

Seems I put it in my everything article about DevOps. Even for PostgreSQL on CentOS. It’s usual:

yum install firewalld
systemctl enable firewalld
systemctl start firewalld
firewall-cmd --permanent --zone=public --add-service=http


I spent 16 hours for this article and coding. If it save your time then I will be happy. Let me know about it=))

Useful links

Your or your company have similar projects or tasks which need to be done?

I offer services linked with things which mentioned in this article. Please write to me by this feedback form

Published by

Danil Borchevkin

IoT Full-Stack Developer

Leave a Reply