Skip to content

Instantly share code, notes, and snippets.

@bertoort
Last active March 8, 2016 02:51
Show Gist options
  • Save bertoort/fda92a1b1dbbf9609d99 to your computer and use it in GitHub Desktop.
Save bertoort/fda92a1b1dbbf9609d99 to your computer and use it in GitHub Desktop.
Portfolio site VPS set up with AMS EC2

Part 1: Set Up Server

Create AWS Account

Go into aws and set up an account. It's free with the basic account but credit card and phone verification is still required. Takes a few minutes.

Create an instance

Go to "My Account" > "AWS Management Console". Then "Launch Instance":

  1. Choose 64-bit Ubuntu Server with the free tier instance.
  2. Launch Instance (don't worry about security for now).
  3. A prompt to add key pair will show up. Create and download a new one. (don't lose it)
  4. Launch again!

Edit Security

Under Network Security, click on Security Groups. Select the group created for the instance. At the bottom, there are tabs with options, click on Inbound. This is were rules can be added to only allow certain IPs and connections to the server. For now, edit and add a new rule to allow all TCP from anywhere.

Connecting through SSH

Under "Instances", click on instances and find the public IP for the instance that we created. We'll use it in a bit.

Copy the SSH key (that was downloaded and not lost) and paste it into the /.ssh file. Then change ownership to secure it: chmod 600 /.ssh [ssh_key].pem

Now, connect to the instance: ssh -i ~/.ssh/[ssh_key].pem ubuntu@[ip address]

Part 2: Buy Domain

Go to a domain site and purchase a name. They range around $10. Here are some places to start:

Then, navigate to editing the DNS records for that domain. Add a basic type A host with the IP of the AWS server previously set up and the name of the domain.

Extra: add a type CNAME host with the same IP address and the name of www to catch and redirect anyone trying to go to www.yourdomain

Part 3: Power Ubuntu Server

Replace Ubunut user

  • Connect back to the AWS Server: ssh -i ~/.ssh/[ssh_key].pem ubuntu@[ip address]
  • Add a new user through the following commands
    • sudo adduser [your name]
    • sudo gpasswd -a [your name] sudo
  • Remove root user
    • vi /etc/ssh/sshd_config
    • find PermitRootLogin yes, and change to no
  • service ssh restart
  • su [your name]

Install Tools

Use sudo apt-get install to install most technologies into the server. To get started, type sudo apt-get update.

Nginx and Passenger:

  • sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
  • sudo apt-get install apt-transport-https ca-certificates
  • sudo touch /etc/apt/sources.list.d/passenger.list
  • sudo vi /etc/apt/sources.list.d/passenger.list
    • include this inside: deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main
  • sudo chown root: /etc/apt/sources.list.d/passenger.list
  • sudo chmod 600 /etc/apt/sources.list.d/passenger.list
  • sudo apt-get update
  • sudo apt-get install nginx-extras passenger
  • sudo vi /etc/nginx/nginx.conf
    • uncomment passenger_root and passenger_ruby by removing #
  • sudo service nginx restart

EXTRA

Git:

  • sudo apt-get install git

Node:

  • Node Instructions or
  • sudo apt-get install nodejs
  • sudo apt-get install npm
  • sudo ln -s /usr/bin/nodejs /usr/bin/node

Set up Nginx

Create a file and tell Nginx where we keep the files we want it to serve up to browsers

  • sudo mkdir /usr/share/nginx/www
  • cd /usr/share/nginx/www
  • sudo chown -R [your name] .
  • sudo chgrp -R www-data .
  • sudo chmod -R 750 .
  • sudo chmod g+s .

Add project

Inside nginx's www file, add your project (git is the easiest way). Then, add it as an enabled site:

  • sudo vi /etc/nginx/sites-enabled/default
    • change root /usr/share/nginx/html; to root /usr/share/nginx/www; to point to the correct folder
    • change server_name _; to server_name [yourdomain];

Install Project Dependencies

Lastly, install the dependencies for the project. They are unique to each case, here are some examples:

Rails:

  • sudo apt-get update
  • curl -L get.rvm.io | bash -s stable
  • source ~/.rvm/scripts/rvm to load
  • rvm requirements to install dependencies of rvm
  • rvm use ruby --latest and then rvm install [whatever lastest version]
  • gem install rails
  • sudo apt-get install bundler

Postgres:

  • sudo apt-get install postgresql-9.3
  • sudo apt-get install libpq-dev
  • use sudo su - postgres to gain access

That's it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment