With AWS, Amazon’s cloud computing platform, you can create virtual servers in the cloud using either Amazon EC2 or Amazon Lightsail.

Amazon EC2 is for highly configurable and performant environments, while Amazon Lightsail is for easy-to-use and affordable ones.

This tutorial will guide you through hosting your web applications on Amazon EC2. You can also follow a short video tutorial at the end.

Note: If you want to use Amazon Lightsail, please check our other tutorial – how to setup Amazon Lightsail to host your websites.

Step 1. Create an Amazon EC2 Instance

To use AWS, you need to sign up or log in to your account.

Tip: You can try out AWS services for free up to certain limits with the AWS Free Tier. The Free Tier has three types of offers: a 12-month Free Tier, an Always Free offer, and short term trials. Refer to AWS documentation for more details.

Choose An AWS Region

Before you create your Amazon EC2 instance, you need to pick a region from the top-right menu. Different regions have different Amazon EC2 dashboards.

AWS has many regions around the world, such as N. Virginia, Cape Town, Hongkong, Mumbai, Seoul, Tokyo, etc. You should pick a region that is near you or your customers. This way, your users will have less delay when they access your web applications.

Launch Instance

Search for “EC2” in the search bar at the top of your screen. Go to your Amazon EC2 dashboard and click the “Instance” menu on the left sidebar.

Then click the “Launch Instance” button to start setting up your server.

On the next screen, you can provide a descriptive name for your server. This name will be displayed in AWS dashboard.

Choose Ubuntu Server Image

Next, you need to choose an Amazon Machine Image (AMI) for your instance. If you use RunCloud, we support Ubuntu 20.04, 22.04 and later LTS versions.

To pick the latest LTS release, just Click on the “Ubuntu” button in the quick start tab under the OS section.

Choose Amazon EC2 Instance Type

Under the “Instance Type” option, select one of the predefined instance types for your instance. Each type has a certain number of vCPUs (virtual Central Processing Unit) and memory.

For example, you can choose the t2.micro instance with 1 vCPU and 1GB Memory that is free for AWS Free Tier users. Each instance type in different AWS region is priced differently. Refer to the AWS pricing chart for up to date information on this topic.

Create and Download a SSH Key

Next, you will need to specify the SSH key that you want to use to log into this server. If you already have an existing key-pair, you can either use that, or use the built-in utility to create a new key pair and save it to your local computer. You will not be able to download the file again after it’s created.

Configure Security Group (Open Required Ports)

Next, you need to open the required ports on your EC2 instance. This step is very important to make your Amazon EC2 instance reachable on the internet.

You need open the following 4 ports:

  • SSH – TCP Port 22
  • HTTP – TCP Port 80
  • HTTPS – TCP Port 443
  • Custom – TCP Port 34210

To add the above rules, click on “Edit” next to the “Network Settings” sub menu and fill in the following details:

  • Auto-assign public IP: Disable (we will assign a static IP in next step)
  • Firewall (security groups): Create New security Group 
    • Security group name: runcloud-security-group
    • Description: RunCloud needs these ports to function properly

Next, you need to add the rules to open required TCP ports and allow connections from anywhere. For the SSH rule, we recommend setting the source type to “My IP“. This will block any connection requests that originate from outside your network.

You should note that most residential internet connections do not have a permanent IP address, which means that your IP address will change roughly every 24 hours. Due to this, if you try to log in to your server in future, your SSH connection will be blocked.

To fix this, you can just log back into your AWS account and edit the runcloud-security-group again to use your new IP.

After adding all of the rules, just leave it and scroll down to the Storage section. Your configuration is temporarily saved in your browser and it will be deployed to AWS when we launch the instance.

Add Storage

Within the Storage option you can configure the storage of your server. There are 3 volume types: General Purpose SSD, Provisioned IOPS SSD, and Magnetic storage. Pick the storage type and size that you want, but keep in mind that you will be billed for storage separately.

Moreover, you will continue to get billed even if you don’t use the storage. For example, if you allocate 200 GB of storage and your server only uses 5 GB then you will be billed for the whole 200 GB every month.

After adding the storage, you can click on the “Launch Instance” button on the right. This will create a new server with the required settings.

Step 2. Create A Static Public IP Address

After creating the server, you will notice that the “Public IPv4 address” filed does not have any value. This is because we disabled the automatic assignment of public IP.

Why You Need a Static IP Address

  • The public IP address that Amazon EC2 assigns to your instance automatically changes every time you stop and start the instance.
  • If you host your website on Amazon EC2, you should use a static IP address for your server. This way, your website will always be accessible at the same IP address.

Amazon EC2 provides an Elastic IP address feature for this purpose. An Elastic IP address is a static IP address that stays the same after you stop and start your instance. Please keep in mind that if you use an Elastic IP address, you will not be charged separately. However, if you reserve an IP address and do not use it, then you will be charged for it.

Moreover, if you terminate (delete) your EC2 instance, your Elastic IP will not be deleted automatically. You will need to go back to Elastic IP dashboard and manually release the IP address.

Note: AWS limits each account to five (5) Elastic IP addresses per region by default. If you need more than 5 Elastic IP addresses in your AWS account, you can request a quota increase from the AWS Service Quotas console.

Allocate An Elastic IP Address

To reserve a new static IP address, go to the “Elastic IPs” section under the “Network & Security” tab in the left menu.

On the next screen, click on “Allocate Elastic IP address“. This will open up a new screen – select the default values, and click “Allocate“, which will reserve a new IP address. Click on the newly allocated IP address to view its summary.

After creating an Elastic IP address, you can continue to click the “Associate Elastic IP address” button. This will open up a new page – select the instance you wish to use this Elastic IP address from the drop down menu, and also select its corresponding private IP address.

Click on “Associate“. Now your Amazon EC2 instance has a static IP address and is ready to be used to host your websites.

Step 3. Connect Amazon EC2 Instance To RunCloud

RunCloud lets you connect your cloud servers using three different methods. For Amazon EC2, you can use the manual server installation method.

Log in to the RunCloud dashboard and click the “Connect a new server” button.

Select “AWS EC2” from the Server Provider list, and then enter a server name and the static IP address that you created in Step 2. Then click the “Add this server” button.

On the next screen, choose “Manual Installation” and you will see the script that you have to run on your Amazon EC2 instance.

Connect to Your Amazon EC2 Instance Using SSH

Go back to the Amazon EC2 dashboard and find your server under the Instances menu. Select the instance and click on the “Connect” button at the top.

On the next screen, switch to the “SSH Client” tab. There you will see the commands that you need to execute to connect to your server.

Open an SSH client and go to the directory where you saved the SSH key that you downloaded when creating the server. To verify that you are in the correct directory, you can run ls <key name> to see if the key is present in the current directory.

For example, is the name of your key is my-SSH-Key.pem, you will run ls my-SSH-Key.pem. If this shows you the name of your key, then you are in right place. If you don’t get anything then you need to change the directory using cd command.

From this directory, run the following command to change the permissions of the SSH key:

chmod 400 <SSH Key name>.pem

You can copy the exact command from your AWS dashboard. After changing the permissions, you can run the example command provided in AWS dashboard:

ssh -i <SSH Key name>.pem ubuntu@myamazonec2-public-dns

After running the above command, you will get a warning that the authenticity of the server can’t be established when you connect to this server for the first time. Type ‘yes‘ and press “Enter“.

Run the RunCloud Installation Script

Finally, we will install the RunCloud agent. We need to run the RunCloud installation script command as the “root” user. Run this command to start a “root” shell.

sudo -s

Then, paste and run the RunCloud installer script command. You can find this script in in your RunCloud dashboard. The RunCloud installation will take a few minutes to complete.

You can check the installer progress on the RunCloud panel too.

If successful, data about your server will appear, and you will have successfully set up your Amazon EC2 server with RunCloud.

Once it is completed, you will see the MySQL root password for your database management and the “runcloud” system user password. Please save this information in a secure place.

Video Tutorial – Set Up Amazon EC2 (AWS) With RunCloud

You can watch this short video tutorial to show you all steps that we have explained above in under 3 minutes.

Next Steps

In this article, we have shown you how to set up Amazon EC2 (AWS) to host your websites on RunCloud.

RunCloud makes it easy to deploy and manage web applications on any cloud server, including AWS. RunCloud and AWS work in tandem to provide you with a fast, secure, and scalable hosting solution for your websites.

RunCloud is a fantastic tool that saves you a lot of time and hassle when you don’t want to manage your server or don’t have Linux expertise. With RunCloud, you can easily deploy and manage your web applications on any cloud server.

Continue your journey and learn how to Create Your First Website on RunCloud.