| « PreviousNext » | |
![]() ![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
This section walks you through deploying a sample application to AWS Elastic Beanstalk using eb (an updated command line interface) and Git, and then updating the application to use the Symfony2 framework.
Eb is a command line interface that enables you to deploy applications quickly and more easily using Git. Eb is available as part of the Elastic Beanstalk command line tools package. Follow the steps below to install eb and initialize your Git repository.
To install eb, its prerequisite software, and initialize your Git repository
Install the following software onto your local computer:
Linux/Unix/MAC
Download and unzip the Elastic Beanstalk command line tools package at the AWS Sample Code & Libraries website.
Git 1.6.6 or later. To download Git, go to http://git-scm.com/.
Ruby version 1.8.7 or later. To view and download Ruby clients, go to http://www.ruby-lang.org/en/.
Python 2.7 or 3.0.
Windows
Git 1.6.6 or later. To download Git, go to http://git-scm.com/.
PowerShell 2.0.
Note
Windows 7 and Windows Server 2008 R2 come with PowerShell 2.0. If you are running an earlier version of Windows, you can download PowerShell 2.0. Visit http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx for more details.
Set up Symfony2 and create the project structure. The following walks you through setting up Symfony2 on a Linux operating system. For more information, go to http://symfony.com/download.
To set up your PHP development environment on your local computer
Download and install composer from getcomposer.org. For more information, go to http://getcomposer.org/download/.
curl -s https://getcomposer.org/installer | php
Install Symfony2 Standard Edition with Composer. Check http://symfony.com/download for the latest available version. Using the following command, composer will install the vendor libraries for you.
php composer.phar create-project symfony/framework-standard-edition symfony2_example/ 2.1.4 cd symfony2_example
Note
You may need to set the date.timezone in the php.ini to successfully complete installation.
Initialize the Git repository.
git init
Update the .gitignore file to ignore vendor, cache, logs, and composer.phar. These files do not need to get pushed to the remote server.
cat > .gitignore <<EOT app/bootstrap.php.cache app/cache/* app/logs/* vendor composer.phar EOT
Generate the hello bundle.
php app/console generate:bundle --namespace=Acme/HelloBundle --format=yml
When prompted, accept all defaults. For more information, go to Creating Pages in Symfony2.
You use eb, a command line tool, to configure AWS Elastic Beanstalk. If you haven't already installed eb on your local computer, do that now at the AWS Sample Code & Libraries website. If you are running eb on a Linux operating system, you will need to install Python 2.7 or 3.0.
Before you use eb, you can set your PATH to the location of eb. The following table shows an example for Linux/UNIX and Windows.
| On Linux and UNIX | On Windows |
|---|---|
$ export PATH=$PATH:
|
C:\> set PATH=%PATH%;
|
Use the init command, and AWS Elastic Beanstalk
will prompt you to enter this information. If a default value is available, and you want to
use it, press Enter.
To configure AWS Elastic Beanstalk
From your directory where you created your local repository, type the following command.
eb init
When you are prompted for the AWS access key, type your access key. To get your access key information, go to Access Credentials.
Enter your AWS Access Key ID (current value is "AKIAIOSFODNN7EXAMPLE"):
When you are prompted for the AWS secret key, type your secret key. To get your secret key information, go to Access Credentials.
Enter your AWS Secret Access Key (current value is "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"):
When you are prompted for the AWS Elastic Beanstalk region, type the number of the region. For information about this product's regions, go to Regions and Endpoints in the Amazon Web Services General Reference. For this example, we'll use US East (Virginia).
When you are prompted for the AWS Elastic Beanstalk application name, type the name of the application. AWS Elastic Beanstalk auto-generates an application name based on the current directory name if an application name has not been previously configured. In this example, we use HelloWorld.
Enter an AWS Elastic Beanstalk application name (auto-generated value is "windows"): symfony2app
Note
If you have a space in your application name, make sure you do not use quotes.
When you are prompted for the AWS Elastic Beanstalk environment name, type the name of the environment. AWS Elastic Beanstalk automatically creates an environment name based on your application name. If you want to accept the default, press Enter.
Enter an AWS Elastic Beanstalk environment name (current value is "windows-env"): symfony2app-env
Note
If you have a space in your application name, make sure you do not have a space in your environment name.
When you are prompted for the solution stack, type the number of the solution stack you want. For this example, we'll use 64bit Amazon Linux running PHP 5.4.
When you are prompted to create an Amazon RDS database, type y or
n. For this example, we'll type
n.
Create RDS instance? [y/n]: n
When you are prompted to enter your instance profile name, you can choose to create a
default instance profile or use an existing instance profile. Using an instance profile enables IAM users and AWS services to
gain access to temporary security credentials to make AWS API calls. Using instance
profiles prevents you from having to store long-term security credentials on the EC2
instance. For more information about instance profiles, see Granting Permissions to Users and Services Using IAM Roles. For this
example, we'll use Create a default instance profile.
After configuring AWS Elastic Beanstalk, you are ready to deploy a sample application.
If you want to update your AWS Elastic Beanstalk configuration, you can use the init command
again. When prompted, you can update your configuration options. If you want to keep
any previous settings, press the Enter key.
Next, you need to create and deploy a sample application. For this step, you use a sample application that is already prepared. AWS Elastic Beanstalk uses the configuration information you specified in the previous step to do the following:
Creates an application using the application name you specified.
Launches an environment using the environment name you specified that provisions the AWS resources to host the application.
Deploys the application into the newly created environment.
Use the start command to create and deploy a sample application.
To create the application
From your directory where you created your local repository, type the following command.
eb start
This process may take several minutes to complete. AWS Elastic Beanstalk will provide status updates during the process. If at any time you want to stop polling for status updates, press Ctrl+C. Once the environment status is Green, AWS Elastic Beanstalk will output a URL for the application.
In the previous step, you created an application and deployed it to AWS Elastic Beanstalk. After the environment is ready and its status is Green, AWS Elastic Beanstalk provides a URL to view the application. In this step, you can check the status of the environment to make sure it is set to Green and then copy and paste the URL to view the application.
Use the status command to check the environment status, and then use the URL to view the application.
To view the application
From your directory where you created your local repository, type the following command.
eb status --verbose
AWS Elastic Beanstalk displays the environment status. If the environment is set to Green, AWS Elastic Beanstalk displays the URL for the application. If you attached an RDS DB Instance to your environment, your RDS DB information is displayed.
Copy and paste the URL into your web browser to view your application.
After you have deployed a sample application, you can update it with your own application. In this step, we update the sample application with a simple "Hello World" Symfony2 application.
To update the sample application
Add your files to your local Git repository, and then commit your change.
git add -A && git commit -m "Initial commit"
Note
For information about Git commands, go to Git - Fast Version Control System.
Create an application version matching your local repository and deploy to the Elastic Beanstalk environment if specified.
git aws.push
You can also configure Git to push from a specific branch to a specific environment. For more information, see Deploying a Git Branch to a Specific Environment.
After your environment is Green and Ready, append /hello/AWS to the URL of your application. The application should write out "Hello AWS!"
You can access the logs for your EC2 instances running your application. For instructions on accessing your logs, see Working with Logs.
If you no longer want to run your application, you can clean up by terminating your environment and deleting your application.
Use the stop command to terminate your environment and the delete command to delete your application.
To delete the application
From your directory where you created your local repository, type the following command.
eb stop
This process may take a few minutes. AWS Elastic Beanstalk will display a message once the environment has been successfully terminated.
Note
If you attached an RDS DB Instance to your environment, your RDS DB will be deleted, and you will lose your data. To save your data, create a snapshot before you delete the application. For instructions on how to create a snapshot, go to Creating a DB Snapshot in the Amazon Relational Database Service User Guide.
From your directory where you installed the command line interface, type the following command.
eb delete
AWS Elastic Beanstalk will display a message once it has successfully deleted the application.