This blog lists the actions I went through to setup an AWS EC2 Ubuntu Server and add the usual applications. This follows on from my guide to setup a Digital Ocean server server guide and Vultr setup guide.
Variable Pricing
Amazon Web Services give developers 12 months of free access to a range of products. Amazon don’ t have flat rate fees like Digital Ocean instead, AWS grant you a minimum level of CPU credits for each server type. A “t2.micro” (1CPU/1GB ram $0.013c/hour server) gets 6 CPU credits an hour. That is enough for a CPU to run at 10% all the time, you can bank up to 144 CPU credits that you can use when the application spikes. The “t2.micro” is the free tier server (costs nothing for 12 months), but when the trial runs our that’s $9.50 a month. The next server up is a “t2.small” (1 CPU, 2GB ram) and you get 12 CCPUredits and hour and can bank 288, that enough for 20% CPU usage all the time.
The “t2.medium” server (2 CPU’s, 4GB Ram), allows 40% CPU usage credits, 24 CPU credits an hour with 576 bankable. That server costs $0.052c and hour and is $38 a month. Don’t forget to cache content.
I used about 40 CPU credits generating a 4096bit secure prime Diffie-Hellman key for an SSL Certificate on my t2.micro server. More Information on AWS Instance pricing here and here.
Creating an AWS Account (Free Trial)
The signup process is simple.
- Create a free AWS account.
- Enter your CC details (for any non-free services) and submit your account.
It will take 2 days or more for Amazon to manually approve your account. When you have been approved, navigate to https://console.aws.amazon.com login and set your region in the top right next to your name (in my case I will go with Australia ‘ap-southeast-2‘).
My console home is now: https://ap-southeast-2.console.aws.amazon.com/ec2/v2/home?region=ap-southeast-2#LaunchInstanceWizard
Create a Server
You can follow the prompts to set up a free tier EC2 Ubuntu server here.
1. Choose Ubuntu EC2
2. Choose Instance Type: t2-micro (1x CPU, 1GB Ram)
3. Configure Instance: 1
4. Add Storage: /dev/sda1, 8GB+, 10-3000 IOPS
5. Tag Instance: Your own role specific tags
6. Configure Security Group: Default firewall rules.
7. Review
Tip: Create a 25GB volume (instead of 8GB) or you will need to add an extra volume mount it with the following commands.
Part of theEC2 server setup was to save a .PEM file to your SSH folder on your local PC ( ~/.ssh/mysererkeypair.pem).
You will need to secure the file:
Before we connect to the server we need to configure the firewall here in the Amazon Console.
Type | Protocol | Port Range | Source | Comment |
HTTP | TCP | 80 | 0.0.0.0/0 | Opens a web server port for later |
All ICMP | ALL | N/A | 0.0.0.0/0 | Allows you to ping |
All traffic | ALL | All | 0.0.0.0/0 | Not advisable long term but OK for testing today. |
SSH | TCP | 22 | 0.0.0.0/0 | Not advisable, try and limit this to known IP’s only. |
HTTPS | TCP | 443 | 0.0.0.0/0 | Opens a secure web server port for later |
DNS
You will need to assign a status IP to your server (apparently the public IP is not static). Here is a good read on connecting a domain name to the IP and assigning an elastic IP to your server. Once you have assigned an elastic IP you can point your domain to your instance.
Installing the Amazon Command Line Interface utils on your local PC
This is required to see your servers console screen and then connect via SSH.
You now need to configure your AWS CLI, first generate Access Keys here. While you are there setup Multi-Factor Authentication with Google Authenticator.
Once you have configured your CLI you can connect and review your Ubuntu console output (the instance ID can be found in your EC2 server list).
Now you can hopefully connect to your server and accept any certificates to finish the connection.
Success, I can now access my AWS Instance.
Setting the Time and Daylight Savings.
Check your time.
My Daylight savings have not kicked in.
Install ntp service
Set your Timezone
Go to http://www.pool.ntp.org/zone/au and find my NTP server (or go here if you are outside Australia)
Add the NTP servers to “/etc/ntp.conf” and restart he NTP service.
Now check your time again and you should have the right time.
🙂
Installing NGINX
I am going to be installing the latest v1.11.1 mainline development (non-legacy version). Beware of bugs and breaking changes here.
NGINX is now installed. Try and get to your domain via port 80 (if it fails to load, check your firewall).
Installing NodeJS
Here is how you can install the latest NGINX (development build), beware of bugs and frequent changes. Read the API docs here.
NodeJS is installed.
Installing MySQL
Install PHP 7.x and PHP7.0-FPM
I am going to install PHP 7 due to the speed improvements over 5.x. Below were the commands I entered to install PHP (thanks to this guide)
Now install misc helper modules into php 7 (thanks to this guide)
NGINX Configuration
NGINX can be a bit tricky to setup for newbies and your configuration will certainly be different but here is mine (so far):
File: /etc/nginx/nginx.conf
File: /etc/nginx/sites-available/default
Test and Reload NGINX Config
Don’t forget to test PHP with a script that calls ‘phpinfo()’.
Install PhpMyAdmin
Here is how you can install the latest branch of phpmyadmin into NGINX (no apache)
If you need to import databases into MySQL you will need to enable file uploads in PHP and set file upload limits. Review this guide to enable uploads in phpMyAdmin. Also if your database is large you may also need to change the “client_max_body_size” settings on nginx.conf ( see guide here ). Don’t forget to disable uploads and reduce size limits in NGINX and PHP when you have uploaded databases.
Note: phpMyAdmin can be a pain to install so don’t be afrait of using an alternative management gui. Here is a good list of MySQL management interfaces. Also check your OS App store for native mysql database management clients.
Install an FTP Server
Follow this guide here then..
Install: oracle-java8 (using this guide)
Install: ncdu – Interactive tree based folder usage utility
Install: pydf – better quick disk check tool
Install: rcconf – display startup processes (handy when confirming pm2 was running).
I started “php7.0-fpm” as it was not starting on boot.
I had an issue where PM2 was not starting up at server reboot and reporting to https://app.keymetrics.io. I ended up repairing the /etc/init.d/pm2-init.sh as mentioned here.
Install IpTraf – Network Packet Monitor
Install JQ– JSON Command Line Utility
Install Ruby – Below commands a bit out of order due to some command not working for unknown reasons.
Install Twitter CLI – https://github.com/sferik/t
Mutt (send mail by command line utility)
Help site: https://wiki.ubuntu.com/Mutt
Configuration:
Configure postfix guide here
Extend the History commands history
I love the history command and here is how you can expand it’s hsitory and ignore duplicates.
Don’t forget to check your servers IP with www.shodan.io to ensure there are no back doors.
Cont…
Next: I will add an SSL cert, lock down the server and setup Node Proxies.
If this guide was helpful please consider donating a few dollars to keep me caffeinated.
Donate and make this blog better
Ask a question or recommend an article
[contact-form-7 id=”30″ title=”Ask a Question”]
v1.61 added vultr guide link