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 the Host Name box, 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, run the following command on your instance to perform a quick software update.

    [ec2-user ~]$ sudo yum update -y
  2. Install the Apache web server and PHP software packages as follows.

    [ec2-user ~]$ sudo yum groupinstall -y "Web Server" "PHP Support"
  3. (Optional) If you need PHP support for MySQL, as Drupal does, run the following command.

    [ec2-user ~]$ sudo yum install php-mysql php-xml php-mbstring php-gd
  4. Start the Apache web server using the following command.

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

    [ec2-user ~]$ sudo chkconfig httpd on
  6. Before you continue to the next step, 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, run the following command to download Drupal, where x.y is the Drupal version.

    [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

    You can 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, run the following command, where x.y is the Drupal version.

    [ec2-user ~]$ rm drupal-x.y.tar.gz
  4. Grant ec2-user permission to write files to the Apache document root, /var/www/html as follows.

    1. Create a group and add ec2-user to the group.

      [ec2-user ~]$ sudo groupadd www
      [ec2-user ~]$ sudo usermod -a -G www ec2-user
    2. Close the terminal window and connect to your instance again.

    3. Grant the www group ownership of /var/www and its contents, and change permissions for the directory and its subdirectories.

      [ec2-user ~]$ sudo chown -R root:www /var/www
      [ec2-user ~]$ sudo chmod 2775 /var/www
      [ec2-user ~]$ find /var/www -type d -exec sudo chmod 2775 {} +
      [ec2-user ~]$ find /var/www -type f -exec sudo chmod 0664 {} +
    4. Restart the Apache web server as follows.

      [ec2-user ~]$ sudo service httpd restart
  5. Move Drupal to /var/www/html/ using the following command.

    mv drupal-x.y/* /var/www/html/
  6. Create the files directory and the settings.php file.

    [ec2-user ~]$ cd /var/www/html/
    [ec2-user html]$ sudo mkdir sites/default/files
    [ec2-user html]$ sudo chmod 777 sites/default/files/
    [ec2-user html]$ sudo cp sites/default/default.settings.php sites/default/settings.php
    [ec2-user html]$ sudo chmod 666 sites/default/settings.php

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

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 profile page, click Standard and then click Save and continue.

  3. On the Choose language page, click English (built-in), 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, or equivalent as the database type.

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

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

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


    6. In the Database host box, 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. On the Configure site page, do the following:

    1. In the Site name box, enter a name, such as My Site.

    2. In the Site e-mail address box, type an email address.

    3. In the Username box, type a username.

    4. In the Password box, type a password.

    5. In the Confirm password box, re-type the password.

    6. Click Save and continue.

Test the Website

Upon success, the following page is displayed. Click Visit your new site to see your website.

Your new website looks something like this.

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

To add a page

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

  2. In the Title box, enter Hello World!.

  3. In the button pane, select the Publishing options tab and then select Promoted to front page.

  4. Click Save.

  5. Refresh the website to see your new header and front page.

Update Permissions

Now that your new site is created, you should remove write permissions from your default directory and settings.php file as follows. Otherwise, the Drupal status report for your site warns you that your settings.php file is not protected from modification and poses a security risk.

[ec2-user html]$ sudo chmod 644 sites/default/settings.php
[ec2-user html]$ sudo chmod 755 sites/default

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.