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.
Did you know? AWS made it even easier to launch a web application. Jumpstart your application with Amazon Lightsail >>
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 type in "elastic beanstalk" in the search bar and press Enter.
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. 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. On the Configuration Details step, you can set configuration options for the instances in your stack. For this tutorial, you don't need to change anything. Click Next.
On the Environment Tags step, you can tag all the resources in your stack. For this tutorial, you don't need to tag any resources but can if you would like. Click Next.
On the VPC Configuration step, select the first AZ listed by checking the box under the EC2 column. Your list of AZs may look different than the one shown as Regions can have different number of AZs. Click Next.
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.