Skip to content

Instantly share code, notes, and snippets.

@josephspurrier
Created October 12, 2015 19:19
Show Gist options
  • Save josephspurrier/407dbbde454a6a3afc3d to your computer and use it in GitHub Desktop.
Save josephspurrier/407dbbde454a6a3afc3d to your computer and use it in GitHub Desktop.
Setup Golang on AWS Ubuntu
###############################################################################
# New Server - AWS
###############################################################################
# Update software
sudo apt-get update
sudo apt-get upgrade
# Install Apps
sudo apt-get install unzip
sudo apt-get install ntp
# Reboot to ensure machine boots
sudo reboot
# Install MySQL
sudo apt-get install mysql-server-5.6
#######################################
# Firewall
#######################################
# Update the firewall
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 3306/tcp
sudo ufw enable
#######################################
#######################################
# MySQL
#######################################
# Secure MySQL
sudo mysql_secure_installation
# Login to MySQL
mysql -u root -p
# Create the database
CREATE DATABASE database DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci;
# Create the user
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL ON database.* TO 'user'@'localhost';
#######################################
# Go Language
#######################################
# Source: http://www.hostingadvice.com/how-to/install-golang-on-ubuntu/
# Source: http://blog.isaacdontjelindell.com/blog/2014/01/19/using-gvm-go-version-manager-to-install-golang/
# Install software
sudo apt-get install git binutils bison gcc make
# Clone the GVM Repo
bash < <(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
# Restart bash
exec bash -l
# Install the latest stable version of Golang
gvm install go1.4.2
gvm use go1.4.2 --default
export GOROOT_BOOTSTRAP=$GOROOT
gvm install go1.5
gvm use go1.5 --default
#######################################
# Go Application
#######################################
# Create a dir for Go
mkdir ~/golang
# To create a zip from the old server
zip -r web.zip .
# Extract on new zip
unzip web.zip
# Start a screen session
screen
# Set the export variable
export GOPATH=/home/ubuntu/golang
# Compile the application
cd src/github.com/josephspurrier/gowebapp
go build gowebapp.go
# Edit the configuration
sudo nano config/config.json
# Change the "Server/Hostname" to the private IP of the virtual machine
# Change the "Session/SecretKey" to something random
# Change the "Session/Name" to something specific to the website
# Run the application
cd ~/golang/src/github.com/josephspurrier/gowebapp
sudo ./gowebapp >> log.txt 2>&1 &
# Recall the application
fg
# Ctrl + C to stop the application
# Or force kill the application
pkill gowebapp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment