Hosting a Damn Website on AWS for Normal People

Hosting a Damn Website on AWS for Normal People

Update November 14th, 2016 – “Google Apps for Work” is now called the “G Suite”, no I’m not kidding

Ok, so you have to be a bit techie, so… almost normal people.

Hosting in the Cloud without cPanel

This has been a huge frustration for me and was always my problem, I like building things – I hate having to manage the foundation they run on. This led me to forever using cPanel and WHM (Web Host Manager) just so I wouldn’t have to worry about all that server juju.

I also use my domain name for email, forwarded onto my Gmail account, which means email flows through my server before it makes it home. Transitioning everything to AWS meant I had to figure out what to do with email, because without cPanel, setting up email on AWS was turning into a pain in my ass – and as much fun as that was, it… was not fun.

(If you don’t use an @yourdomain.com email you can skip anything to do with Google Apps for Work)

But it was all good. Sort of.

I finally decided to move a few of my websites to the cloud for the reliability (though even AWS can go down, it seems to happen less often than my current host…) and scalability, but while researching how to transition my beloved cPanel over, it all went tits up – cPanel just isn’t very compatible with AWS. Blown opportunity for them I guess, because I finally found a service that works (Haha! Suck it cPanel).

Unfortunately there’s no actual replacement for cPanel (I’ve looked at them all), but if you rearrange your expectations a bit, you’ll probably realize you don’t need it as much as you think.


 

cPanel → ServerPilot, AWS, Google Apps for Work and BitBucket

cPanel → ServerPilot, AWS, Google Apps for Work and BitBucket

The Goods

I’ll shortcut you here and give you the tools I use –

What it took me for-royally-ever to figure out is how exactly these new puzzle pieces fit together, and what old puzzle pieces I was actually missing without cPanel and WHM.

What Those Goods Do

ServerPilot

  • Installs Apache, MySQL, PHP and configures them (ServerPilot does a lot, and they should really sell it better in their dashboard)
  • Sets up server to receive domains and subdomains (you’ll still have to point them to your server)
  • Sets up MySQL databases

Google Apps for Work

  • Handles email – this was a big part of my confusion in not having cPanel, what do I do for email? Honestly the best answer is just to pay the $5/month/user (I’m just a single user, so it’s not cost prohibitive personally) and get email off your server. You basically sign up for Google Apps and set the MX records of the domain to Google’s. Boom, done.

Amazon Web Services

  • Hosts your damn website – using EC2
  • Manages domain records (A, MX, CNAME etc – not too complicated) – using Route53

BitBucket

  • Deploys your site’s files to your server – eliminates the need for FTP which always sucked anyway, but yes, you will need some limited command line skills such as “git commit -m ‘Commit message'”, “git push” and “git pull”

What we’re missing

There are a few things I’m still missing from this setup, which at this point will require me to learn enough command line to do, but I haven’t used them enough for them to be deal breakers for me

  • Password protecting directories with htpasswd (it would be great if  ServerPilot picked this up)
  • Cron jobs (also ServerPilot)
  • Databases other than MySQL (also ServerPilot)

Make It So, Number One

I’ll assume we’re starting with a pretty typical PHP website with a MySQL database

Sign up for AWS and configure ServerPilot

I’ll also piggyback off ServerPilot’s AWS setup guide, but you’re basically launching the following EC2 instance –

  • Micro instance (currently t2.micro is the cheapest so roll with that)
  • Ubuntu Server 14.04 (ServerPilot supports Ubuntu 12.04 or 14.04, go with the newer one)
  • Whatever the rest of the defaults are

What the guide doesn’t mention is that you’ll want to attach an Elastic IP to your EC2 instance and when SSH’ing into the server to install ServerPilot you want to use the “ubuntu” user (you’ll need that .pem key AWS made you save for this as well) –

>ssh ubuntu@{elastic-ip}

Their setup guide also throws in enabling SFTP as what appears to be an afterthought, when it’s actually mandatory for you to later be able to login as the “serverpilot” user, so don’t miss the “Note: Using passwords for SFTP will not work by default on EC2.” section at the very bottom.

Note – After installing ServerPilot you’ll need to set the password for the new “serverpilot” user in the ServerPilot dashboard and login to your server with the “serverpilot” user to do any website related management

I’d also recommend ServerPilot’s guide to setting up PHPMyAdmin as your first App, with a few caveats –

  • For the app name just use “site” (you’ll never see it, it’s just the folder it’s installed in)
  • Use your server’s IP address as the domain (instead of a real domain name) which’ll make the app only available at http://{server-ip}/phpmyadmin and not tied to any particular domain
  • Instead of downloading/uploading PHPMyAdmin, just SSH into your server, navigate to your new “site” App’s folder and download the latest .tar.gz version directly from http://www.phpmyadmin.net/home_page/downloads.php

>ssh serverpilot@{elastic-ip}
>cd ~/apps/site/public/
>wget http://sourceforge.net/projects/phpmyadmin/files/phpMyAdmin/4.2.8.1/phpMyAdmin-4.2.8.1-english.tar.gz
>tar -zxvf phpMyAdmin-4.2.8.1-english.tar.gz

Upload your site to BitBucket

I personally use BitBucket because it offers private repositories for free, but GitHub is the other popular option.

Once you have an account you’ll need to add your current website files to a repository, and we can do this one of two ways –

  1. SSH into your current server
  2. Get the files onto your computer (or if you already have them there)

Then

  • Navigate to your files’ directory (ex. public_html)
  • Initialize a repo, add the files, commit and push. BitBucket provides good instructions when creating your repo, but roughly –

>cd /path/to/website/public_html/
>git init
>git remote add origin https://{bitbucket-username}@bitbucket.org/{bitbucket-username}/{bitbucket-repository}.git
>git add */* (this might miss a few like .htaccess that you'll have to git add manually, check with "git status")
>git commit -a -m "{commit message}"
>git push

Download your site from BitBucket

Now, much like setting up PHPMyAdmin you need to setup a new App in ServerPilot, SSH into your AWS server as the “serverpilot” user, navigate to your app’s directory and this time pull your site down from your repository –

>git init
>git remote add origin https://{bitbucket-username}@bitbucket.org/{bitbucket-username}/{bitbucket-repository}.git
>git pull

Boom. Your files.

Database

Now you’ll still need to go export your old MySQL database, add a new database through ServerPilot (write that password down it autogenerates for you), login into PHPMyAdmin (with the database username and password you just generated) and re-import your database. You’ll also probably need to update your site’s database config with the new username and password.

Almost There

Now we just need to repoint our domain name to our AWS EC2 instance and (if needed) setup new MX records for our email.

If you haven’t signed up for Google Apps for Work yet pop on over and do that and save those MX records it spits out.

Now head on over to AWS’s Route 53 and create a new Hosted Zone (you’ll have one hosted zone per domain if you’re moving more than one over). It’ll ask you what domain you’re going to use and spit out the nameservers for you to update your registrar with – go update those and hop back here to add a few more records –

  • “A” record with your EC2’s elastic IP
  • “CNAME” record of “www” pointing towards your non-www domain name (this is optional)
  • “MX” records provided to you by Google Apps for Work (only if you’re using them to handle your email now)

Give everything a bit and your domain name should be pointing at a new working copy of your site in the cloud. Look at you go.

Post Mind-Blowing Hosting Revelation

Whew, I think that covers most of it.

You will have to switch up the way you update your website’s files – you’ll want to install Git (GitHub has GUI clients that come with the command line tools for Mac and Windows) on your development machine and pull everything down, make changes, test, commit, push, then login to the remote server as serverpilot, navigate to your app folder and git pull to update your site.

Lather, rinse, repeat!

Comments

  1. I actually have this (almost) same exact configuration. I had been delaying my migration from a much more expensive managed VPS service because I, too, did not want to deal with server juju (also disliked cPanel). It wasn’t until this past weekend when I really understood the power of ServerPilot. I had skimmed through their site a month or two earlier and thought was interesting, but didn’t fully get what they offered. Now that I do, ServerPilot is great, and will save me a lot of anxiety attacks in the future.

    Here’s my setup: ServerPilot (free tier) | DigitalOcean ($10/mo VPS) | BitBucket (free) | Google Apps (Gmail, Calendar, Drive – Free thru grandfathered plan) | CloudFlare for DNS records (free)

    I only spend money on my VPS’s here, which is AWESOME!!! I chose Digital Ocean because it’s the best that I know of in terms of pricing and quality of service/tools/UI. Here’s my link, with $10 free, in case anyone wishes to sign up: Digital Ocean Sign Up.

    However, I didn’t install PHPmyadmin for the potential security risk. I would recommend trying to use an SSH Tunnel per their recommendation. It was pretty easy connecting using SQLPro on Mac, and I’ve done this before with HeidiSQL on Windows tunneling through PuTTY.

    BitBucket – I started using them in November. Before BitBucket, I had a plan to use GitLab off of a DigitalOcean One-Click built box, but more of that server juju-phobia kept me from tinkering around.

    Google Apps – I get Google Apps for Business for free (I was grandfathered into a program that no longer exists).

    CloudFlare – The last thing I started using in December is CloudFlare. In the past, it was sometimes very cumbersome making sure every DNS record copies over fully for the several clients I manage, most of whom use different domain registrars with varying levels of flexibility–especially when adding in third services like google apps for business. CloudFlare’s DNS service is free and really saved me a lot of headache. When you first add a site, they scan and get your current DNS records (with the exception of my gmail TXT values). Then you just do a simple DNS pointer from the registrar to one of CloudFlare’s servers. Set it once, never have to go back to the clients registrar again. And their interface is very easy to use. They also add a secuirty layer to your server, include simple site analytics, and even cache responses to speed up response times. A highly recommended option IMO!

    Hope this helps anyone else, cheers!

  2. Ian says:

    @Julian – You’ve got the other great setup I’d recommend to people (using Digital Ocean), I hear ServerPilot’s actively working on improving its experience with DO as well, it’s really exciting.

    I probably should look at setting up the SSH tunnel instead of PHPMyAdmin, but for now PMA’s just been so dang easy – I’ll make it eventually.

    I don’t have any experience with CloudFlare, but I have heard of it, I’ll definitely give that a shot if I ever end up managing a client’s DNS again.

  3. Ed says:

    I’ve got the exact same setup as Julian but use Zoho for absolutely free email (and a good one at that). The free account lets you have up to 10 users with 5gb storage each. Solid and saves me from paying google.

Leave a Reply

Your email address will not be published. Required fields are marked *