Getting Started with AWS
Hosting a Web App

Step 3: Deploy Your App

Deploy the app to your EC2 instance by completing the following tasks. For this tutorial, you'll install Drupal and create a test page.

Connect to Your Linux Instance

After you launch your instance, you can connect to it and use it the way that you'd use a computer sitting in front of you.

Before you connect to your instance, get the public DNS name of the instance using the Amazon EC2 console. Select the instance and locate Public DNS on the Description tab.


If your instance doesn't have a public DNS name, open the VPC console, select the VPC, and check the Summary tab. If either DNS resolution or DNS hostnames is no, click Edit and change the value to yes.


The tool that you use to connect to your Linux instance depends on the operating system running on your computer. If your computer runs Windows, you'll connect using PuTTY. If your computer runs Linux or Mac OS X, you'll connect using the SSH client. These tools require the use of your key pair. Be sure that you created your key pair as described in Create a Key Pair.

To connect to your Linux instance from Windows using PuTTY

  1. Start PuTTY (from the Start menu, click All Programs > PuTTY > PuTTY).

  2. In the Category pane, select Session and complete the following fields:

    1. In Host Name, enter ec2-user@public_dns_name.

    2. Ensure that Port is 22.

  3. In the Category pane, under Connection type, expand SSH, and then select Auth. Complete the following:

    1. Click Browse.

    2. Select the .ppk file that you generated for your key pair, as described in Create a Key Pair, and then click Open.

    3. Click Open to start the PuTTY session.

  4. If this is the first time you have connected to this instance, PuTTY displays a security alert dialog box that asks whether you trust the host you are connecting to. Click Yes. A window opens and you are connected to your instance.

To connect to your instance from Linux or Mac OS X using SSH

  1. Use the ssh command to connect to the instance. You'll specify the private key (.pem) file and ec2-user@public_dns_name.

    $ ssh -i /path/my-key-pair.pem

    You'll see a response like the following.

    The authenticity of host ' ('
    can't be established.
    RSA key fingerprint is 1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f.
    Are you sure you want to continue connecting (yes/no)?
  2. Enter yes.

    You'll see a response like the following.

    Warning: Permanently added '' (RSA) 
    to the list of known hosts.

Configure the EC2 Instance

To configure the instance, we'll start the web server, install the app, and then configure the app to use our database server. If you don't have the files for your web app, you can use the Drupal application, as we do in this tutorial.

Start the Web Server

Use the following procedure to start the web server.

To start the web server

  1. To ensure that your software packages are up to date on your instance, use the following command to perform a quick software update.

    [ec2-user ~]$ sudo yum update -y
  2. Install the Apache web server, PHP, and MySQL software packages using the following command.

    [ec2-user ~]$ sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd php56-mbstring php56-gd php56-opcache
  3. Start the Apache web server using the following command.

    [ec2-user ~]$ sudo service httpd start
  4. Configure the Apache web server to start at each system boot using the following command.

    [ec2-user ~]$ sudo chkconfig httpd on
  5. Before you continue, verify that the web server is running. In a web browser on your computer, paste the public DNS name of your instance into the address bar and press Enter. This displays the Apache test page. If you don't see the test page for Apache, verify that your security group allows HTTP traffic.

Install the App

Now you are ready to install and configure the web app. The procedures depend on the app that you're running. This tutorial installs Drupal to demonstrate how to download files to your instance and configure your app to use your database server.

To install Drupal

  1. Go to and note the version of Drupal that you'd like to use.

  2. On your instance, use the following command to download Drupal, where x.y is the Drupal version you chose.

    [ec2-user ~]$ wget
  3. Extract Drupal using the following command, where x.y is the Drupal version.

    [ec2-user ~]$ tar -xzvf drupal-x.y.tar.gz

    (Optional) You can use the following command to verify that the current directory contains the compressed and uncompressed versions.

    [ec2-user ~]$ ls
    drupal-x.y drupal-x.y.tar.gz

    (Optional) To remove the compressed version of Drupal, use the following command, where x.y is the Drupal version.

    [ec2-user ~]$ rm drupal-x.y.tar.gz
  4. Create the files directory using the following commands.

    [ec2-user ~]$ cd drupal-x.y/
    [ec2-user drupal-x.y]$ mkdir sites/default/files

    Copy the settings.php file using the following command.

    [ec2-user drupal-x.y]$ cp sites/default/default.settings.php sites/default/settings.php
  5. Move Drupal to /var/www/html/ using the following command.

    [ec2-user drupal-x.y]$ sudo rsync -avh . /var/www/html/

    (Optional) To remove the decompressed version of Drupal, you can use the following commands, where x.y is the Drupal version.

    [ec2-user drupal-x.y]$ cd ..
    [ec2-user ~]$ rm -rf drupal-x.y/
  6. Grant ownership of the /var/www directory and its contents to the apache user using the following command.

    [ec2-user ~]$ sudo chown -R apache /var/www
  7. Enable clean URLs, as recommended by Drupal, using the following command.

    [ec2-user ~]$ sudo vim /etc/httpd/conf/httpd.conf

    Find the section <Directory "/var/www/html">, and set AllowOverride as follows:

    AllowOverride All

    Save the file (using Esc, :x, Enter), and then restart the Apache web server using the following command.

    [ec2-user ~]$ sudo service httpd restart

Configure Drupal

Drupal includes an installation wizard that you can use to configure your website. In the previous procedure, you installed Drupal to the Apache document root, so you can start the installation wizard by opening the website.


This procedure covers Drupal 8. If you are configuring Drupal 7, the steps are similar but there are some differences.

To configure Drupal

  1. Open a web browser on your computer, and enter the public DNS address of your instance in the address bar.

  2. On the Choose language page, select the language and then click Save and continue.

  3. On the Choose profile page, click Standard and then click Save and continue.

  4. If you see the Verify requirements page, address any errors and then continue.

  5. On the Set up database page, do the following:

    1. Select MySQL, MariaDB, Percona Server, or equivalent as the database type.

    2. In Database name, enter the name of the database on your DB instance. In this tutorial, we used the name my_database.

    3. In Database username, enter the username for your database. In this tutorial, we used db_user.

    4. In Database password,enter the password that you used when you created your DB instance.


    6. In Host, enter the endpoint of your DB instance. (To find this endpoint, select the DB instance in the Amazon RDS console. Do not include the :3306.)

    7. Click Save and continue.

  6. After the install completes, the Configure site page is displayed. On the Configure site page, do the following:

    1. In Site name, enter a name, such as My site.

    2. In Site e-mail address, enter an email address.

    3. In Username, enter a user name.

    4. In Password, enter a password. In Confirm password, enter the same password.

    5. Under Regional Settings, select the default country and time zone.

    6. Click Save and continue.

Test the Website

Upon success, your website is displayed.

If you'd like, you can create a front page.

To add a page

  1. From your Drupal website, click Add content and then click Basic page.

  2. In Title, enter Hello World!.

  3. Expand Promotion Options and then select Promoted to front page.

  4. Click Save and publish. Your updated website looks something like this.

Create a Custom AMI

Now that you have customized your EC2 instance, you can create your own AMI. With your own AMI, you can quickly launch a new EC2 instance with the same configuration as this one.

To create an AMI from a running Amazon EBS-backed instance

  1. Open the Amazon EC2 console at

  2. In the navigation bar, verify that US West (Oregon) is the selected region.

  3. In the navigation pane, click Instances.

  4. On the Instances page, select your instance, click Actions, select Image, and then click Create Image.

  5. In the Create Image dialog box, specify a unique image name and an optional description of the image (up to 255 characters), and then click Create Image. Click Close.

To view the status of your AMI, go to the AMIs page. While the AMI is being created, its status is pending. If you go to the Snapshots page, you'll see that we created a snapshot that is used to create the root device volume of any instance that you launch using your new custom AMI.

Now that you have a custom AMI, you no longer need the instance that you created it from, because we'll use Auto Scaling to launch new instances in the next step. To terminate the instance, go to the Instances page, select it, click Actions, select Instance State, and then click Terminate, and then click Yes, Terminate.