Deploy Laravel from Github to Elastic Beanstalk via CodePipeline

Last Updated on

CraftyTechie is reader-supported. When you buy through links on our site, we may earn an affiliate commission.

How to Deploy a Laravel PHP App to AWS Elastic Beanstalk using CodePipeline

This article demonstrates how to deploy a PHP (Laravel) application to Elastic Beanstalk using AWS CodePipeline. A breakdown of the article is as follows.

Table of Contents

This article is a complete walkthrough; by the end, you’ll have a CodePipeline ready to auto-deploy from GitHub to Elastic Beanstalk.

Additional Laravel Solutions

Deploy Laravel from Github to Elastic Beanstalk via CodePipeline

Deploy a Laravel PHP App from Github to AWS Elastic Beanstalk using CodePipeline. Learn how to set up a pipeline using AWS CodePipeline.

Deploy Laravel to Elastic Beanstalk using GitHub Actions in 2023

Deploy Your Laravel PHP App to AWS Elastic Beanstalk using GitHub Actions. Learn all about GitHub to Elastic Beanstalk CI/CD.

Before We Deploy to AWS Elastic Beanstalk from GitHub, We Must Have a Laravel App

If you’re replicating the steps of this walkthrough, make sure you do the following.

  • Fork or clone this repository from GitHub.
  • Deploy the PHP Laravel application to Elastic Beanstalk.

Don’t worry if you are not familiar with Elastic Beanstalk. FuelingPHP’s “Host and Deploy a Laravel PHP App to AWS Elastic Beanstalk” is a complete walkthrough of AWS Elastic Beanstalk and could help you understand deployment to AWS Elastic Beanstalk. This article uses the same linked repository – a sample Laravel application.

This article is a continuation or an extension of the previous article, where we deployed a Laravel application to Elastic Beanstalk. We left a side note about CI/CD pipeline and how that can help us deploy from the GitHub repository whenever there’s a change.

So, let’s build a CI/CD pipeline using AWS CodePipeline.

Background on AWS CodePipeline. What is it?

AWS CodePipeline is an AWS service for continuous delivery. Continuous delivery is a popular concept in agile software development, where code changes are automatically prepared for deployment to a production server. As it is a widespread industry practice, there’s much to expand on CI/CD (Continuous Integration/ Continuous Delivery).

You can learn more about CI/CD in this starter’s blog

So, AWS CodePipeline will integrate with the Laravel GitHub repository and detect changes. It will deploy the Laravel app changes to AWS Elastic Beanstalk in the last article.  Nevertheless, you can also host a sample application from scratch. The walkthrough is equally valid for any scenario.

Deploy PHP App to Elastic Beanstalk using CodePipeline
AWS CodePipeline

AWS CodePipleline can integrate with third-party servers like GitHub and Bitbucket, as well as other AWS services, including S3, ECR, and CodeCommit. It offers one active pipeline per month free of cost. AWS charges $1 monthly for every active pipeline, excluding the free tier. Learn more about the price plan here.

Alternative to CodePipeline? GitHub Actions?

CodePipeline is a continuous delivery pipeline from Amazon. GitHub also has a CI/CD platform called GitHub Actions. It is a promising feature from GitHub that comes with many built-in actions from the GitHub marketplace and helps you define an end-to-end deployment and integration pipeline.

Here’s a comparison between CodePipeline and GitHub Actions.

CodePipelineGitHub Actions
Supports GitHub, AWS CodeCommit, BitBucket, and Amazon S3Supports GitHub only.
The free tier offers one pipeline with 50 minutes per monthFree for public repositories: 2000 build minutes per month.
It works best with AWS; in theory, it could deploy to other cloud platforms.Works with any environment, including AWS.
IAM role defined. No need to worry about user credentials.Store IAM user secrets in repository secrets.
Comes with pre-built integrations provided by AWS.GitHub marketplace has thousands of integrations available that you can use as actions in your CI/CD. 
Pipeline as Code possible with CloudFormation or Terraform.Uses Pipeline as Code – a .yml file.
AWS CodePipeline vs. GitHub Actions

Interested in GitHub Actions? Learn how to deploy Laravel PHP on AWS Elastic Beanstalk using GitHub Actions at FuelingPHP.

Deploy Our Laravel PHP App from Github to AWS Beanstalk using CodePipeline

1. Click Create Pipeline in the CodePipeline dashboard.

AWS CodePipeline Dashboard
AWS CodePipeline Dashboard

2. Provide a Pipeline name, leaving the rest of the settings as such, and click Next.

Deploy PHP App to Elastic Beanstalk using CodePipeline
CodePipeline Settings

3. In the Source Provider drop-down, select GitHub (version 2) and click Connect to GitHub.

Connect to GitHub
Connect to GitHub

4. In the new window, provide a Connection name and click Connect to GitHub.

Deploy PHP App to Elastic Beanstalk using CodePipeline
Create Connection

5. Next, click Install a new app.

Install a new app
Install a new app

6. On the GitHub auth window, click on your GitHub profile.

Deploy PHP App to Elastic Beanstalk using CodePipeline
GitHub Auth

7. Select the correct repository, then click Install.

Select Repository
Select Repository

8. Back to AWS, select the correct repository and branch, then click Next.

Deploy PHP App to Elastic Beanstalk using CodePipeline
CodePipeline Repository

9. Click on Skip Build Stage.

Build Stage
Build Stage

10. Select Elastic Beanstalk as the deploy provider in the deployment stage. Choose the application name and environment. Then click Next.

Deploy PHP App to Elastic Beanstalk using CodePipeline
Deploy Stage

11. Next, review the details of the pipeline and then click Create Pipeline. The creation will take a while.

12. The pipeline will be created and will start deploying from the source (GitHub) to the destination (Elastic Beanstalk).

Deploying

Congratulations! We have created a pipeline to auto-deploy from GitHub to Elastic Beanstalk. Let’s put it to the test right away.

Commit and Push to Github to Deploy PHP App to Elastic Beanstalk using CodePipeline

Open your Laravel project locally and run the following command in the local main branch.

git pull origin main

Make a small change – it could be as simple as adding a comment. Afterward, run the following two commands

git commit -am “your commit message”

git push origin main

Switch to the CodePipeline in the AWS, and you’ll see that deployment has been initiated.

Deploy PHP App to Elastic Beanstalk using CodePipeline
Deploying

Voila! We have successfully tested the pipeline, and it has worked. So, it is time for a goodbye until next time  🙂

Deploy Laravel to Beanstalk Using CodePipline & Github

This article demonstrates how to deploy a PHP Laravel app in Github to AWS Elastic Beanstalk using CodePipeline. AWS CodePipeline is a CI/CD platform from Amazon that helps you readily set up a pipeline from your code repository to Elastic Beanstalk. The article overviews CodePipeline and also discusses an alternative – GitHub Actions.

 The last two sections include the bulk of the article as they explore how to create a pipeline and put it to the test by committing to the source repository in GitHub. Hopefully, you’ve enjoyed the article. Stay tuned for more at FuelingPHP.

Latest AWS News on CraftyTechie

Deploy a Monorepo in App Runner: AWS New Repository Support

AWS announces new feature to deploy a monorepo into App Runner. This is a positive development & step in the platform system.

Automate MSK Topics to S3 Data Lake: New AWS Delivery Service

Automate data transfer from Kafka topics into data lake via AWS MSK, S3 & Kinesis. New managed data delivery service announced.

AWS App Runner Default Auto-Scaling Configurations + Versions

AWS App Runner now supports Auto-Scaling default configurations with versions. This update will improve managing environments.

AWS CodePipeline + Gitlab: Deploy Apps into the Cloud

You can now deploy your web apps into AWS with Gitlab using CodePipeline. This is a new repository source that opens more opportunities.

Did you find this article helpful?

Join the best weekly newsletter where I deliver content on building better web applications. I curate the best tips, strategies, news & resources to help you develop highly-scalable and results-driven applications.

Build Better Web Apps

I hope you're enjoying this article.

Get the best content on building better web apps delivered to you.