This is the first of a few articles detailing how to host multiple Node.js or PHP websites on a single EC2 instance.

  1. Log in to AWS, and click on EC2
  2. Click on Launch Instance under Create Instance EC2 Dashboard
  3. Select the underlying OS you'd like to use. I've chosen Amazon Linux because it's essentially RHEL but cheaper and qualifies for the free-tier. There are a lot of other free-tier base OS options, but Amazon is the cheapest after the first year ends. AMI image selection
  4. Choose an instance type. The free-tier gives you one option, t2.micro, 1 vCPU and 1 gig of RAM. Not much but sufficient for a few Node.js instances assuming they're not getting slammed. Just remember that for a 64-bit system a Node.js application defaults to a max memory usage of 1 gig. In practice you'll probably see ~115 megs for something like Ghost.
  5. Now you can select Review and Launch but my recomentation is to continue with Next: Configure Instance Details. Here I would turn on Enable termination protection which prevents your instance from being erased unless you really want it to be. Instance details
  6. Continue on with Next: Add Storage. The defaults here are fine, but you can get up to 30 GiB on the free-tier, so why not bump that up. Storage setup I would also de-select Delete on Termination just to provide more hoops before doing something irreversible.
  7. Click Next: Tag Instance. I don't personally tag my instances, but feel free to do so.
  8. Proceed by clicking Next: Configure Security Group. Here you'll need to open up the ports to any services you want externally available. SSH is there by default, but as a web-server make sure that HTTP and HTTPS are open. This acts as your instances 'Firewall'. Add additional open ports
  9. Now select Review and Launch. Double check everything, and if it's how you expect it hit Launch.
  10. Time to generate a key pair to access your instance via ssh. Generate key pair Pick a name, and then 'Download Key Pair'. Time to launch the instance.
  11. The instance will have a temporary IP that will only belong to the instance as long as it's running. As a more persistent solution go back to the dashboard and click on 'Elastic IP' and then Allocate New Address. Confirm the allocation, and then associate the new Elastic IP to the instance. Associate Address Click inside the Instance input field, and the instance's ID should pop up.
  12. Time to setup ~/.ssh/config. Move the .pem key pair file downloaded earlier into ~/.ssh and then add the following to your ~/.ssh/config, substituting the new Elastic IP and key pair name:
Host aws  
        HostName <Elastic IP>
        User ec2-user
        IdentityFile ~/.ssh/<newkey>.pem

Now things are all set up to log into the instance and continue the configuration of services: ssh aws