Amazon Web Services (AWS) provides a robust cloud computing platform that allows you to create virtual servers in the cloud. Two primary services for this are Amazon EC2 (Elastic Compute Cloud) and Amazon Lightsail. Amazon EC2 is designed for highly configurable and performant environments, offering granular control and scalability, while Amazon Lightsail focuses on being easy-to-use and affordable, ideal for simpler applications.
This guide will walk you through the process of hosting your web applications on Amazon EC2. For those seeking a more streamlined approach, consider exploring Amazon Lightsail, as detailed in our tutorial – how to setup Amazon Lightsail to host your websites.
Step 1. Launching Your Amazon EC2 Instance
To begin, you’ll need an AWS account. You can sign up or log in to access the AWS Management Console.
Tip: New AWS users can take advantage of the AWS Free Tier, which offers free access to many AWS services up to certain usage limits. This is an excellent way to explore and experiment with hosting a server on AWS without initial costs. The Free Tier includes 12-month free access, always-free offers, and short-term trials. Refer to the AWS Free Tier documentation for complete details.
Selecting Your AWS Region
Before proceeding, choose an AWS Region from the dropdown menu typically located in the top-right corner of the AWS Management Console. AWS Regions are geographically isolated locations around the world, each containing multiple Availability Zones.
AWS boasts a global infrastructure with regions spanning across the globe, including regions like N. Virginia, London, Singapore, and Sydney. Choosing a region close to your user base or yourself is crucial for minimizing latency and improving application performance. Lower latency translates to faster loading times and a better user experience for your website or application visitors.
Launching an EC2 Instance
To begin setting up your virtual server, search for “EC2” in the AWS service search bar at the top of the console. Navigate to the Amazon EC2 dashboard and click on “Instances” in the left-hand sidebar.
Next, click the “Launch Instances” button to initiate the server setup process.
On the subsequent screen, you’ll be prompted to configure your server instance. Start by providing a descriptive name for your server in the “Name” field. This name will be used for identification within your AWS dashboard.
Choosing an Ubuntu Server Image
The next critical step is selecting an Amazon Machine Image (AMI). An AMI is essentially a template that contains the operating system, application server, and applications required to launch your EC2 instance. For optimal compatibility with RunCloud, we recommend using Ubuntu 20.04, 22.04 LTS, or later versions.
To select the latest Ubuntu LTS release, locate the “Quick Start” tab and click the “Ubuntu” option under the “OS” section. This will automatically select the current LTS version of Ubuntu, ensuring a stable and well-supported operating system for your server.
Selecting an EC2 Instance Type
Under the “Instance type” section, you need to choose the hardware configuration for your virtual server. AWS offers a wide range of instance types, each offering different combinations of vCPUs (virtual Central Processing Units), memory (RAM), storage, and networking performance.
For users eligible for the AWS Free Tier, the t2.micro
instance is a popular choice, providing 1 vCPU and 1GB of memory. This instance type is sufficient for testing and small-scale applications. Keep in mind that pricing varies based on instance type and AWS Region. Consult the AWS EC2 pricing page for the most up-to-date pricing information.
Creating and Downloading an SSH Key Pair
Secure Shell (SSH) keys are essential for securely accessing your server. In the “Key pair (login)” section, you’ll configure your SSH key. If you already have an existing key pair, you can choose to use it. Alternatively, AWS allows you to create a new key pair directly within the console.
To create a new key pair, select “Create new key pair” from the dropdown. Provide a descriptive name for your key pair and choose “RSA” as the key pair type and “PEM” as the private key file format (for use with OpenSSH). Click “Create key pair” and ensure you download and securely store the .pem
file. This is the only time you’ll be able to download the private key, and it’s crucial for accessing your server via SSH.
Configuring Security Groups (Opening Essential Ports)
Security groups act as virtual firewalls for your EC2 instance, controlling inbound and outbound traffic. Configuring your security group correctly is critical for making your server accessible over the internet.
You need to open specific TCP ports to allow necessary connections:
- SSH (Port 22): For secure remote server access.
- HTTP (Port 80): For standard web traffic.
- HTTPS (Port 443): For secure web traffic (SSL/TLS).
- Custom (Port 34210): Required for RunCloud management.
To configure these rules, click “Edit” next to “Network settings“. Modify the settings as follows:
- Auto-assign public IP: Set to “Disable” (we will assign a static Elastic IP later).
- Firewall (security groups): Choose “Create new security group“.
- Security group name:
runcloud-security-group
(or a name of your choice). - Description:
RunCloud required ports
(or a relevant description).
- Security group name:
Next, add inbound rules to allow traffic on the required ports. For each port (22, 80, 443, and 34210), add a rule with the following settings:
- Type: Select the port type (e.g., SSH for port 22, HTTP for port 80, HTTPS for port 443, Custom TCP for port 34210).
- Protocol: TCP.
- Port Range: Enter the specific port number (or range if applicable).
- Source type: For SSH (port 22), it’s recommended to select “My IP” for enhanced security. This restricts SSH access to only your current public IP address. For HTTP, HTTPS, and the RunCloud port (34210), set the Source type to “Anywhere” (
0.0.0.0/0
) to allow access from any IP address.
Important Note: Residential internet connections often have dynamic IP addresses, meaning your IP address can change periodically (usually every 24 hours or so). If you use “My IP” for SSH and your IP changes, you’ll need to update the security group rules in the AWS console to reflect your new IP address to regain SSH access.
After configuring the security group rules, scroll down to the “Storage” section. Your configurations are temporarily saved and will be applied when you launch the instance.
Adding Storage
The “Storage” section allows you to configure the storage volume for your EC2 instance. AWS offers different volume types, including:
- General Purpose SSD (gp3 or gp2): Balanced price and performance, suitable for most workloads.
- Provisioned IOPS SSD (io2 or io1): High performance for I/O intensive applications.
- Magnetic (standard): Lower cost, suitable for infrequently accessed data.
Select the storage type and size you require. Be mindful that you are billed separately for storage, and charges persist even if the storage is not fully utilized. For example, if you allocate 200 GB of storage but only use 5 GB, you will still be billed for the full 200 GB.
Once you’ve configured storage, click the “Launch instance” button in the bottom right corner. This will initiate the creation of your new EC2 server with the specified settings.
Step 2. Allocating a Static Public IP Address (Elastic IP)
After launching your EC2 instance, you might notice that the “Public IPv4 address” field is empty. This is because we disabled automatic public IP assignment in the network settings to use a static IP.
Why a Static IP Address is Essential
- By default, the public IP address assigned to an EC2 instance is dynamic. This means it changes every time you stop and start the instance.
- For hosting websites or applications, a static IP address is highly recommended. A static IP ensures that your website or application remains accessible at the same consistent IP address, regardless of instance restarts.
AWS provides Elastic IP addresses to address this need. An Elastic IP is a static, public IPv4 address that you can allocate to your AWS account. It remains associated with your account until you explicitly release it. While there’s no charge for an Elastic IP address actively associated with a running instance, you will incur charges for Elastic IPs that are reserved but not in use.
Furthermore, if you terminate (delete) your EC2 instance, the associated Elastic IP is not automatically released. You must manually release it from the Elastic IPs dashboard to avoid incurring charges.
Note: AWS imposes a default limit of five (5) Elastic IP addresses per AWS account per region. If you require more than five Elastic IPs, you can request a quota increase through the AWS Service Quotas console.
Allocating and Associating an Elastic IP
To allocate a static IP, navigate to “Elastic IPs” under the “Network & Security” section in the left-hand menu of the EC2 dashboard.
On the Elastic IPs page, click “Allocate Elastic IP address“. In the allocation settings, you can typically accept the default options and click “Allocate“. This will reserve a new Elastic IP address for your account. Click on the newly allocated IP address to view its details.
To associate this Elastic IP with your EC2 instance, click the “Associate Elastic IP address” button. In the association dialog:
- Select your EC2 instance from the “Instance” dropdown menu.
- Choose the corresponding private IP address for your instance from the “Private IP address” dropdown.
Click “Associate“. Your EC2 instance now has a static public IP address, making it ready to host your websites and applications with a consistent and reliable IP.
Step 3. Connecting Your Amazon EC2 Instance to RunCloud
RunCloud simplifies server management by providing a user-friendly interface to manage your cloud servers. RunCloud offers multiple methods to connect your servers. For Amazon EC2 instances, the manual server installation method is commonly used.
Log in to your RunCloud dashboard and click the “Connect a new server” button.
Choose “AWS EC2” from the “Server Provider” list. Enter a descriptive server name and the static Elastic IP address you allocated in Step 2. Click “Add this server“.
On the next screen, select “Manual Installation“. RunCloud will display a script that you need to execute on your Amazon EC2 instance to complete the connection process.
Connecting to Your EC2 Instance via SSH
Return to your Amazon EC2 dashboard and locate your running instance under the “Instances” menu. Select your instance and click the “Connect” button at the top.
In the connection options, select the “SSH client” tab. AWS provides instructions and the necessary command to connect to your server using SSH.
Open your preferred SSH client (like Terminal on macOS/Linux or PuTTY on Windows) and navigate to the directory where you saved your SSH private key file (.pem
file). You can use the ls
command to verify if the key file is present in the current directory. For example, if your key file is named my-SSH-Key.pem
, type ls my-SSH-Key.pem
and press Enter.
If the key file is listed, you are in the correct directory. Otherwise, use the cd
command to navigate to the correct directory.
Before connecting, you may need to adjust the permissions of your SSH private key file to ensure it’s not publicly accessible. Use the chmod 400 <your-ssh-key-name>.pem
command (replace <your-ssh-key-name>.pem
with the actual name of your key file).
Now, use the SSH command provided in the AWS console to connect to your server. It will typically look like: ssh -i <your-ssh-key-name>.pem ubuntu@<your-ec2-public-ip-or-dns>
. Replace <your-ssh-key-name>.pem
with your key file name and <your-ec2-public-ip-or-dns>
with your instance’s public IP address or public DNS.
When connecting for the first time, SSH might display a warning about the server’s authenticity. Type yes
and press Enter to proceed.
Running the RunCloud Installation Script
Once connected to your server via SSH, you need to execute the RunCloud installation script. To do this, you first need to switch to the “root” user. Run the command:
sudo -s
After becoming the root user, copy the RunCloud installation script from your RunCloud dashboard and paste it into your SSH terminal. Press Enter to execute the script. The RunCloud installation process will take a few minutes to complete. You can monitor the installation progress in your RunCloud dashboard.
Upon successful installation, your server details will appear in your RunCloud dashboard, indicating that your Amazon EC2 server is now connected and managed by RunCloud.
After completion, RunCloud will display the MySQL root password for database management and the “runcloud” system user password. It is crucial to securely store this information.
Video Tutorial – Setting Up Amazon EC2 (AWS) with RunCloud
For a visual walkthrough of these steps, you can watch this concise video tutorial that demonstrates the entire process of setting up Amazon EC2 with RunCloud in under 3 minutes.
Next Steps
This guide has demonstrated how to host a server on AWS EC2 and connect it to RunCloud for simplified server management.
RunCloud empowers you to effortlessly deploy and manage web applications on various cloud servers, including AWS. The combination of RunCloud and AWS provides a high-performance, secure, and scalable hosting solution for your websites and applications.
RunCloud is an invaluable tool for streamlining server management, especially if you prefer to avoid manual server administration or lack extensive Linux expertise. With RunCloud, you can easily deploy and manage your web applications on any cloud server with ease.
Continue your journey and learn how to Create Your First Website on RunCloud.