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.

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

http://aws.amazon.com

https://www.serverpilot.io/?refcode=c5396c019696 (that link’ll get you a $10 credit)

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 –

SSH into your current server 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!