Not every Laravel professional is a server professional and that is fine. Still, many Laravel apps are hosted on VPS instances. Serverless gives a way to host Laravel or PHP without thinking about hosting.
In this article we compare various options.
Hosting on AWS Lamda via Bref
There is an excellent package called Bref, which is a bridge for Laravel to AWS Lambda.
It is as easy as following their getting started guide and you have your app up and running. Setting this up in Homestead does not always work. You might need to run this in your main computer, instead of on a virtual server, because there might not be enough resources.
Pros
- No more web hosting needed
- Easy to set up
- Documentation is clear
- Their additional services are priced decently
- Almost free (except from AWS costs of course)
Cons
- Linking via a RDS database is possible via a VPC. You need a jumpbox for this to access this easily via TablePlus. Their software 7777 start at another $19 at the moment of writing.
- It is still a bit hard to work with env variables
- Still has some AWS hassle, setting up S3 for storage, setting up RDS for databases. DynamoDB or ElastiCache for cache. And also CloudFront / Route53 for DNS.
- Deployment easily takes up to 1-2 minutes without Continues Integration software.
Hosting on AWS Lambda via Laravel Vapor
I do not have experience with Laravel Vapor, but it seems a nice option for having a complete ecosystem that manages databases, cache, S3, etc. into one panel.
The big con is the $399 per year price tag. Understandable if you are a bigger company, but it is a steep pricing curve.
Also, it is a con that you give extra access to a third party to your AWS credentials.
A little bit less server: Amazon Elastic Beanstalk
The promise of Amazon Elastic Beanstalk is to deploy a web application in minutes, but is that really true?
Not for me.
When creating a database later on while having created an EB instance with default settings, it give an error that you need to have selected a VPC. You also cannot select another VPC. This will require you to restart the process, create a new instance. Pretty frustrating …
It is also pretty complex with the requirement to setup various IAM keys that are not set as a default. And deployment also takes pretty long.
Hosting on Fortrabbit or other PaaS provider
Fortrabbit is an easy way to host Laravel. Their documentation is easy. Their support is adequate. But their pricing is also pretty steep and when for example upgrading to a larger database it is not uncommon to pay the double price.
Personally, I experienced that when my database was full, I did not receive any warning mail. And when emptying the database to free up space the database got locked, preventing to resume again. The only way that an unblock would happen was to upgrade to a more pricey database plan.
That means you might have to upgrade your database from a €20 plan to a €50 plan. Not so fun for an average hobby project, but not a problem for a highly profitable SaaS app.
This is an option that you might forget. Some web hosting providers offer excellent CPUs, SSDs and RAM for their plans. If the web hosting supports composer + git + a few basic requirements for Laravel it might be worth to host your app here.
Especially, if it is a low-traffic, hobby app.
What is your favorite serverless option?