Giter VIP home page Giter VIP logo

laravel-serverless-boilerplate's Introduction

Laravel Logo

It is important to note that this example can be improved, but it is an introductory example and I intend to bring more content of this type with more examples, consuming, for example, resources from cloud providers, such as SQS for queues, S3 for Storange, etc.

🏗 Laravel CI

Serverless applications are becoming increasingly popular due to their ability to automatically scale and reduce operational costs.

PHP is a programming language widely used for web development and can be used to create efficient and scalable Serverless applications.

Using this kind of approach when providing a PHP with Serverless application, we have a very big gain in time, money and mainly, scalability.

However, with this, we will no longer, for example, pay a fixed price for hosting, often with a fixed and small size of resources, such as memory and processing. In addition to the configuration being much more laborious and costing much more effort in a traditional hosting.

My example will use PHP version 8.1 and the Bref package. We will also use Laravel.

To get started, it's important to have the PHP environment set up with Composer, and also Node.js installed, to ensure that our tutorial flows.

First, we must install the Serverless Framework CLI, using the following command NPM:

npm install -g serverless

It is important to note that Bref is only compatible with versions above 3 of the Serverless Framework (which is the current version).

Have your AWS credentials in hand so that we can proceed with the tutorial, where you will have to configure Serverless with your credentials with the following command:

serverless config credentials --provider aws --key <key> --secret <secret>

With that, we will create a common project with Laravel, using the create-project command by composer:

composer create-project laravel/laravel laravel-serverless-boilerplate

Bref

With your new project open, install Laravel Bref using composer:

composer require bref/bref bref/laravel-bridge --update-with-dependencies

Now, with Bref installed, you will have Bref executables available within your vendor, knowing that, we will run the Bref initialization command:

php artisan vendor:publish --tag=serverless-config

Deploy

Finally, we reached the final stretch, the implementation of this idea. To launch it, just run the commands below:

We don't want to deploy "dev" caches that were generated on our machine (because the paths will be different in AWS Lambda). Let's clean up before going upstairs:

php artisan config:clear

When running on AWS Lambda, the Laravel application will automatically cache its configuration during startup. You don't need to run php crafter config:cache before deploying.

serverless deploy

When finished, the deploy command will show the URL of the application.

Know that this is the basics, this Serverless configuration is minimal and can be extended and adapted to your needs. So if you want to deploy to production or learn more about Serverless, follow me on YouTube for more content, (I want to create more related content)

Links

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

Or buy me a coffee 🙌🏾

📝 License

Copyright © 2023 Hebert F Barros.
This project is MIT licensed.

laravel-serverless-boilerplate's People

Contributors

dependabot[bot] avatar hebertcisco avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.