Skip to content

Modus-Logo-Long-BlackCreated with Sketch.

  • Services
  • Work
  • Blog
  • Resources

    OUR RESOURCES

    Innovation Podcast

    Explore transformative innovation with industry leaders.

    Guides & Playbooks

    Implement leading digital innovation with our strategic guides.

    Practical guide to building an effective AI strategy
  • Who we are

    Our story

    Learn about our values, vision, and commitment to client success.

    Open Source

    Discover how we contribute to and benefit from the global open source ecosystem.

    Careers

    Join our dynamic team and shape the future of digital transformation.

    How we built our unique culture
  • Let's talk
  • EN
  • FR

How to Build a Serverless Application Using Laravel and Bref

Published on March 10, 2021
Last Updated on December 9, 2022
Application Development, DevOps

Serverless architecture has grown more popular since Amazon Web Services (AWS) introduced Lambda. Serverless does not mean computing without servers as the name suggests, but it means delegating the responsibility of taking care of the infrastructure (servers, operating systems, disk space, software updates) to the cloud provider (AWS, Azure, Google Cloud). Serverless allows the developer to focus only on the code itself.

Cloud Service Models

Serverless code is often created in the form of functions, and that’s why this architecture is also called “Function as a Service (FaaS)”. This computation model places the responsibility of managing the servers on the cloud provider and frees the developer’s time to work on the product.


NEW RESEARCH: LEARN HOW DECISION-MAKERS ARE PRIORITIZING DIGITAL INITIATIVES IN 2024.

Get Report


Security continues to be the developer’s responsibility. There are a collection of guidelines and tools on Serverless security and Modus Create provides application security consulting, designed to enumerate threats, vulnerabilities, and risks. The results of this engagement are presented from a tactical and strategic perspective. With these findings, you can then take the next step in improving your application’s security posture.

The New LAMP Stack: Serverless on AWS

To face the challenges of scaling applications, AWS is offering new services to help PHP developers build reliable and efficient serverless applications. In comparison to traditional LAMP (Linux, Apache, MySQL, PHP) stack, serverless LAMP (Lambda, API Gateway, MySQL, PHP) applications are easier to scale and maintain while costing less than the alternative (using a pay-per-use model).

The Laravel framework has a healthy list of tools that enable easy deployment of a serverless application (including Laravel Vapor, Vercel). In this tutorial, I’ll be covering how to use Bref to build a serverless Laravel application.

Step 1: AWS User

First, we need to create an account for our application in AWS. To do this, you should go to the IAM management console of your account and create a new user with Programmatic access.

Select AWS access type

After following the user creation process, it’s important to securely store the access key ID and secret access key. Those will be used for your application to use AWS resources.

Step 2: Serverless Framework

After configuring your AWS account, it’s time to install and configure your serverless framework. Here we will use the access key ID and secret access key generated in the previous step.

npm install -g serverless
serverless config credentials --provider aws --key  --secret 

Step 3: Laravel + Bref

Now it’s time to create your Laravel application, installing the most recent version, and creating a new app.

composer global require laravel/installer
laravel new serverless-app

To have Bref configured with Laravel we also need to install the laravel-bridge component.

composer require bref/bref bref/laravel-bridge

Then let’s create a configuration file for serverless (serverless.yml).

php artisan vendor:publish --tag=serverless-config
service: laravel                                                                                                                                                                                           
 
provider:
    name: aws 
    # The AWS region in which to deploy (us-east-1 is the default)
    region: us-east-1
    # The stage of the application, e.g. dev, production, staging… ('dev' is the default)
    stage: dev 
    runtime: provided.al2
 
package:
    # Directories to exclude from deployment
    exclude:
        - node_modules/**
        - public/storage
        - resources/assets/**
        - storage/**
        - tests/**
 
functions:
    # This function runs the Laravel website/API
    web:
        handler: public/index.php
        timeout: 28 # in seconds (API Gateway has a timeout of 29 seconds)
        layers:
            - ${bref:layer.php-74-fpm}
        events:
            -   httpApi: '*' 
    # This function lets us run artisan commands in Lambda
    artisan:
        handler: artisan
        timeout: 120 # in seconds
        layers:
            - ${bref:layer.php-74} # PHP
            - ${bref:layer.console} # The "console" layer
 
plugins:
    # We need to include the Bref plugin
    - ./vendor/bref/bre

Step 4: Deploy

Before deploying, we need to clear any configuration change generated on our machine. After that, we’re ready to deploy.

php artisan config:clear
serverless deploy

Deploying example
Laravel website


This post was published under the Laravel Community of Experts. Communities of Experts are specialized groups at Modus that consolidate knowledge, document standards, reduce delivery times for clients, and open up growth opportunities for team members. Learn more about the Modus Community of Experts program in the article Building a Community of Experts.

References

  • What’s Serverless PHP?
  • Deploy Serverless Laravel Application using Bref
  • Bref Documentation
  • Benchmarking Serverless Laravel vs Lumen
  • Serverless Visually Explained
Posted in Application Development, DevOps
Share this

Guido Percú

Guido Percú is a Full Stack Engineer at Modus Create, where he creates software projects using Python, PHP and AWS solutions. Born and raised in Brazil, he lives in Rio de Janeiro with his wife. When he is not coding, he enjoys reading books, learning about stock markets and practicing Karate.
Follow

Related Posts

  • Build Secure Web Applications with Laravel
    Build Secure Web Applications with Laravel

    For modern web applications, reliability and security are top priority. The Modus Laravel Community of…

  • Serverless All The Things
    Serverless - AllTheThings (Part 1 of 3)

    Serverless software architecture reduces maintenence and operation costs of computing, provides scalable, on demand data…

Want more insights to fuel your innovation efforts?

Sign up to receive our monthly newsletter and exclusive content about digital transformation and product development.

What we do

Our services
AI and data
Product development
Design and UX
IT modernization
Platform and MLOps
Developer experience
Security

Our partners
Atlassian
AWS
GitHub
Other partners

Who we are

Our story
Careers
Open source

Our work

Our case studies

Our resources

Blog
Innovation podcast
Guides & playbooks

Connect with us

Get monthly insights on AI adoption

© 2025 Modus Create, LLC

Privacy PolicySitemap
Scroll To Top
  • Services
  • Work
  • Blog
  • Resources
    • Innovation Podcast
    • Guides & Playbooks
  • Who we are
    • Our story
    • Careers
  • Let’s talk
  • EN
  • FR