Deploy a PHP(Laravel) app on AWS Elastic Beanstalk via CodePipeline
Tags: aws, elastibeanstalk, devops, php
Published: 2022-07-29 07:14:00

In this tutorial I will explain you to deploy a PHP laravel application on AWS Elastic Beanstalk service.
**About :** Amazon Elastic Beanstalk is an easy-to-use service for deploying and scaling web applications and services developed with Java, .NET, PHP, Node.js, Python, Ruby, Go, and Docker on familiar servers such as Apache, Nginx, Passenger, and IIS.
**Working:** You simply upload your code and Elastic Beanstalk automatically handles the deployment, from capacity provisioning, load balancing, and automatic scaling to web application health monitoring, with ongoing fully managed patch and security updates.


## Step-1) Create a Beanstalk Environment and APP
- Select environment as **web server environment** 
![Image1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/feqjzry1lhsy3ey555sb.png)
- Create the Application and Environment name:
![Image 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2d6ijxakjnjgcfyq1upg.png)
- Choose the Platform on which you want to deploy your app.Here We will choose PHP for our laravel project.
![Image 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sc6ikul42se79sm8wh6y.png)
- The next step is to upload the code(for now we will go with sample code as we will push the original code in the next version with the code pipeline.)
![Image 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nzof40d3f0pz9vj2l379.png)
- Click on create and let the enviornment get created.
![Image 5](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3roql837ihqx6ds6eaen.png)
Finally It will show something like this
![Image 6](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6970sspsg2av6gk3uh79.png)
And when you click the APP url like this `http://laravelapp-env.eba-muin3rqg.us-east-2.elasticbeanstalk.com/` it will open your app with sample code.
![Image 7](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kc70pc2dazaboegerhhf.png)
 
---

## Step-2) Create the CodePipeline
Go to searchbar, type codepipeline and click create codepipeline
![Image 8](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k33e6ybcbxk99uvzuagb.png)
- Now Add the source stage, connect to your version control system(like Github here) and select the repository(laraval-demo) and branch(dev)
![Image 9](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/md9wei3bbnzmoeijh3ku.png)
- Check the Start the pipeline on source code change to automatically starts your pipeline when a change occurs in the source code. 
![Image 10](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rzw63wjvic6fmkztilll.png)

- Skip the Build stage for now. Add Deployment stage (Pipelines must have at least two stages. Your second stage must be either a build or deployment stage.)
Choose Elastic Beanstalk at the place of Deployment Provider, application name and environment name.
![Image 23](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yhxwng9shyi15lifex5w.png)
Click Next and Review all the steps and cofiguration.
Finally Click on `Create Pipeline`
![Image 23](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/txynl5pi8i1auuk6yirh.png)
- After Pipeline is succesfull create and deployed it will look something like this:
![Image 24](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3v2k5ja12ym89x5985ia.png)
-  Now Go to Beanstalk enviornment dashboard and open the application version you will found out that the latest version deployed is via codepipeline 
![Image 26](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jpprjw013h1sb4vblnvx.png)
- See the health of our app as `OK` 
![Image 44](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7kxh795t39ludmi6w14v.png)
 
- Click on Beanstalk App URL like `http://laravelapp-env.eba-muin3rqg.us-east-2.elasticbeanstalk.com/` to see our deployed laravel app.
![Image 54](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n196fw3hehm4urpiyx9w.png)
 
### Summary:
The CodePipeline will trigger whenever we will push the changes into the git. Hence it is our Continuous integration pipeline.