Uploading web files to a new Amazon EC2 instance

Projects and Code466 words3 minutes to read

This is one of a few quick tutorials I’ve had sitting around on my hard drive for a while. I’m posting it now for the sake of anyone who may find these instructions useful.

It’s important to note that these are the instructions you’d use for a standalone EC2 instance. If your app is low-traffic enough to only need a single server, a better option would be to leverage a single-instance Elastic Beanstalk environment which gives you more, better and simpler deployment options.

Launching an instance

  1. You’ll need to launch a new EC2 instance. The simplest way is from the AWS Management Console.

  2. As part of this process, you’ll create a new keypair. The key pair will have a name and a keypair file (.pem). The .pem file is a replacement for a password. You’ll need this file to log into your EC2 instance.

  3. Once the instance has launched, you’ll want to select it in the EC2 console, and find the public hostname in the details section of the screen.

Logging in and fixing access permissions

  1. Armed with Terminal/PuTTY, your keypair file (.pem), and the public hostname of the instance, you’re ready to log into your instance.

  2. If you’re using Terminal, log into your instance using the following command:

    ssh -i {path-to-keypair-pem} ec2-user@{public-hostname}
  3. If you’re using a GUI tool for connecting (e.g., PuTTY), here are the important bits:

    • Hostname: {public-hostname}
    • User: ec2-user
    • Key: {path-to-keypair-pem}
  4. Once you’re logged into the EC2 instance as the ec2-user user, you’ll need to switch to the root user.

    sudo -i
  5. Move into the default Apache DocumentRoot directory.

    cd /var/www/html
  6. Change the owner of this directory to the ec2-user user. This will enable you to use a GUI-based tool to upload your web files.

    chown ec2-user .

Installing any required software

A new EC2 instance is essentially a blank slate. Very little is installed on the instance by default (which keeps it lean and fast), but there are many, many packages available for install via yum.

  • yum list available will show you all of the packages that are available to install.
  • yum list installed will show you all of the packages that are already installed.
  • yum help will show you which commands are available to use.

If you wanted to install PHP and Apache on your server, you would type (assuming you’re already the superuser (i.e., sudo -i)):

yum install php apache

Uploading your web files

  1. Using the SFTP client of your choice (I prefer Transmit or Cyberduck, depending on what I’m doing), connect to your EC2 instance over SFTP using the following credentials:

    • Hostname: {public-hostname}
    • User: ec2-user
    • Key: {path-to-keypair-pem}
  2. Move to the /var/www/html directory.

  3. Drag your web files into this directory to upload them. index.html will be loaded as the homepage when you load the public hostname in your web browser.

Ryan Parman

Ryan Parman is an experienced software engineer, open source evangelist, and passionate user advocate currently living in Seattle. He is the creator of and , and worked on DevOps and Security at . He is now bringing learning into the digital age as an Engineering Lead and Site Reliability Engineer at . Ryan's aptly-named blog, , is where he writes about ideas longer than .