How to install Go and host Hugo on your own VPC

Install Go from source

First thing first, you need to create the user that will be the owner of the code that we are going to deploy. In my case, I use deploy as the owner of the site.

For this to work properly this user must be in the sudo or admin group.

# e.g. Create the admin user `deploy` if not already exist
sudo useradd -m -d /home/deploy -d /home/deploy -s /bin/bash -U deploy

# Take note of the password
passwd deploy

# Add this user to the admin group
groupadd admin && usermod -a -G admin deploy

# Then we can go in as this user
su deploy

cd ~/

Note: this is to be run as root using the script below

e.g. run it like sudo ./

# file:
# Install Go and prerequisites
apt-get -qq update
apt-get -qq install build-essential curl git-core libpcre3-dev mercurial pkg-config zip
hg clone -u release /opt/go
cd /opt/go/src && ./all.bash

# Setup the GOPATH
mkdir -p /opt/gopath
cat <<EOF >/etc/profile.d/
export GOPATH="/opt/gopath"
export PATH="/opt/go/bin:$GOPATH/bin:\$PATH"

# Make sure the GOPATH is usable by deploy user
# Edit to your correct user when appropriate
chown -R deploy:deploy /opt/go
chown -R deploy:deploy /opt/gopath

Once this done you may need to add the following to your paht

# Add go to the path of your ~/.zshrc or ~/.bashrc (just in case)
export GOROOT=/opt/go
export GOPATH=$HOME/go
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH

# Then make sure that we use the updated path
source ~/.zshrc # source ~/.bashrc

# You should be able to run go command
go version

Install Hugo for hosting our Blog

Installation of Hugo is very simple if we have Go install

# Get the code
$go get -v

# After you may like to use `-u` to update the Hugu's dependencies
$go get -u -v

You may like to follow the following links for more details

Install nginx as your web server

Please follow this easy instruction on how to install Nginx on Ubuntu 14.04 LTS

Update your web server (e.g. Nginx, etc) to use the new content

For my case, I am using the nginx to host the content so my setup is as follow:

The configuration I have to do is just edit the existing config to point to the new public url generated by Hugo.

# Edit your nginx to point to this path e.g.
# sudo vim /etc/nginx/nginx.conf
# sudo vim /etc/nginx/sites-enabled/default
# This is the one
# sudo vim /etc/nginx/sites-available/default

The significant line is something like

# ..
server {
   # ..
   listen 80 default_server;
   listen [::]:80 default_server ipv6only=on;

   # Edit this line to point to our Hugo's public directory
   # e.g. /home/deploy/path/to/your/public

   ## the default value will be something like the next line
   root /usr/share/ngnix/html;
   index index.html index.htm;
   # ..
# ..

Useful Links

comments powered by Disqus