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
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
Start PuTTY (from the Start menu, click All Programs > PuTTY > PuTTY).
In the Category pane, select Session and complete the following fields:
In Host Name, enter ec2-user@public_dns_name.
Ensure that Port is 22.
In the Category pane, under Connection type, expand SSH, and then select Auth. Complete the following:
.ppkfile that you generated for your key pair, as described in Create a Key Pair, and then click Open.
Click Open to start the PuTTY session.
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
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 /
You'll see a response like the following.
The authenticity of host 'ec2-198-51-100-1.compute-1.amazonaws.com (10.254.142.33)' 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)?
You'll see a response like the following.
Warning: Permanently added 'ec2-198-51-100-1.compute-1.amazonaws.com' (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
To ensure that your software packages are up to date on your instance, use the following command to perform a quick software update.
sudo yum update -y
Install the Apache web server, PHP, and MySQL software packages using the following command.
sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd php56-mbstring php56-gd php56-opcache
Start the Apache web server using the following command.
sudo service httpd start
Configure the Apache web server to start at each system boot using the following command.
sudo chkconfig httpd on
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
Go to https://www.drupal.org/project/drupal and note the version of Drupal that you'd like to use.
On your instance, use the following command to download Drupal, where x.y is the Drupal version you chose.
Extract Drupal using the following command, where x.y is the Drupal version.
tar -xzvf drupal-
(Optional) You can use the following command to verify that the current directory contains the compressed and uncompressed versions.
(Optional) To remove the compressed version of Drupal, use the following command, where x.y is the Drupal version.
filesdirectory using the following commands.
cd drupal-[ec2-user drupal-x.y]$
settings.phpfile using the following command.
cp sites/default/default.settings.php sites/default/settings.php
Move Drupal to
/var/www/html/using the following command.
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.
cd ..[ec2-user ~]$
rm -rf drupal-
Grant ownership of the
/var/wwwdirectory and its contents to the
apacheuser using the following command.
sudo chown -R apache /var/www
Enable clean URLs, as recommended by Drupal, using the following command.
sudo vim /etc/httpd/conf/httpd.conf
Find the section
<Directory "/var/www/html">, and set
Save the file (using Esc, :x, Enter), and then restart the Apache web server using the following command.
sudo service httpd restart
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
Open a web browser on your computer, and enter the public DNS address of your instance in the address bar.
On the Choose language page, select the language and then click Save and continue.
On the Choose profile page, click Standard and then click Save and continue.
If you see the Verify requirements page, address any errors and then continue.
On the Set up database page, do the following:
Select MySQL, MariaDB, Percona Server, or equivalent as the database type.
In Database name, enter the name of the database on your DB instance. In this tutorial, we used the name
In Database username, enter the username for your database. In this tutorial, we used
In Database password,enter the password that you used when you created your DB instance.
Expand ADVANCED OPTIONS.
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
Click Save and continue.
After the install completes, the Configure site page is displayed. On the Configure site page, do the following:
In Site name, enter a name, such as
In Site e-mail address, enter an email address.
In Username, enter a user name.
In Password, enter a password. In Confirm password, enter the same password.
Under Regional Settings, select the default country and time zone.
Click Save and continue.
Test the Website
Upon success, your website is displayed.
If you'd like, you can create a front page.
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
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
In the navigation bar, verify that US West (Oregon) is the selected region.
In the navigation pane, click Instances.
On the Instances page, select your instance, click Actions, select Image, and then click Create Image.
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
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.