This step-by-step guide will help you get a sample PHP application up and running with AWS Elastic Beanstalk (EB). EB supports other languages besides PHP, such as Java, .NET, Node.JS, Python, Ruby, Docker, and Go, but the focus of this tutorial will be on PHP (other languages will follow the same process). You will first configure your EB application, then setup your EB environment where your application will be launched into.
In this tutorial, we will be using a pre-built sample PHP application. To download this sample PHP application file, please click here.
When you click here, the AWS management console will open in a new browser window, so you can keep this step-by-step guide open. When this screen loads, enter your user name and password to get started. Then find Elastic Beanstalk under Compute, and click to open the Elastic Beanstalk dashboard.
Now that you’re in the AWS Elastic Beanstalk dashboard, click on Create New Application to create and configure your application.
Fill out the Application name with php-sample-app and Description field with Sample PHP App. Click Next to continue.
a. For this tutorial, we will be creating a web server environment for our sample PHP application. Click on Create web server.
b. Click on Select a platform next to Predefined configuration, then select PHP. Next, click on the drop-down menu next to Environment type, then select Single instance.
Note: an “instance” is referring to Amazon’s Elastic Compute Cloud (EC2) compute service. A “single instance” means we will be using one virtual server to deploy our application into.
We will discuss how to scale and load balance your application in a separate tutorial. Click Next to continue.
c. Under Source, select the Upload your own option, then click Choose File to select the sample php-v1.zip file we downloaded earlier. Before moving on, double click on the php-v1.zip file that you downloaded to your local machine to view the contents within. This will help you better understand what your zip file should look like when working with your own PHP application.
Note: PHP does not enforce a strict file structure for applications; flat file structure will work fine.
Click Next to continue.
d. Fill in the values for Environment name with phpSampleApp-env. For Environment URL, fill in a globally unique value since this will be your public-facing URL; we will use phpsampleapp-env in this tutorial, so please choose something different from this one. Lastly, fill Description with Sample PHP App. For the Environment URL, make sure to click Check availability to make sure that the URL is not taken. Click Next to continue.
e. Check the box next to Create this environment inside a VPC. Click Next to continue.
f. Here, leave all fields with their default values. Click on Next to continue and then click Next again on the next screen dealing with Environment Tags. On the next screen, Select the first availability zone listed by checking the box under the EC2 column. Your screen may look different than the one shown, but this is okay as long as you select one subnet.
Note: An availability zone (AZ) is a cluster of data centers that are isolated from other AZs in a geographic region. This is used when you want to increase to a highly available architecture. For this tutorial, we will be using a single AZ.
Leave everything else to their default values, then click Next to continue.
g. At the Permissions step, leave everything to their default values, then click Next to continue. Then review your environment configuration on the next screen and then click Launch to deploy your application.
Note: Launching your application may take a few minutes.
a. Go back to the main Elastic Beanstalk dashboard page by clicking on Elastic Beanstalk. When your application successfully launched, your application’s environment, phpSampleApp-env, will show up as a green box. Click on phpSample-App-env, which is the green box.
b. At the top of the page, you should see a URL field, with a value that contains the Environment URL you specified in step 3 part d. Click on this URL field, and you should see a Congratulations page.
Congratulations! You have successfully launched a sample PHP application using AWS Elastic Beanstalk.