Provisioning Approach Overview0:00
Alright, we're almost there. Now we have everything we need to run the Laravel application behind the load balancer. We have the public IP addresses of the instances in the output of the CloudFormation stack. We may use these to SSH into the servers, provision them, and deploy our application. I have developed a DevOps tool for Laravel called Flight, and I'm going to use it to provision the servers and deploy the application. But you can use any service you are comfortable with, like Laravel Forge or Pluie, or you can do it manually by following the Servers for Laravel course on Laracasts. Now let's provision the two servers. I've filled the configuration file for the DevOps tool here, and I've configured PHP
Provisioning EC2 Servers0:46
Now let's provision the two servers. I've filled the configuration file for the DevOps tool here, and I've configured php 8.1 and instructed the tool, which I call Flight. I instructed it to install the php 8.1 configuration on the two servers. I've also marked the servers as web servers, so Flight installs PHP, FPM, and Nginx. Let's run Flight provision Laracasts 1, which is the first server. It will take a few seconds for the server to be provisioned. And let's give it a little time. And here we go. Now let's run Flight provision Laracasts 2 to provision the second server.
Releasing and Configuring App1:28
And here we go. Now let's run Flight provision Laracasts 2 to provision the second server. And all looks good. It's now time we push a release on the two servers. And I will do that by running Flight apps release Laracasts. This will configure the repo on the two servers and set up zero downtime deployments. I've configured this app here to use PHP 8.1, run some commands on every release, and symlink some directories so it works correctly with atomic deployments. Once done, we will run Flight apps configure Laracasts. This is to configure Nginx and FPM to serve our application.
Adding Cloudflare DNS2:08
Once done, we will run Flight apps configure Laracasts. This is to configure Nginx and FPM to serve our application. I've configured it to serve the application on port 80 instead of 443 as the DLS certificate will be terminated at the load balancer as we explained. Now once Flight is done, let's go to our CloudFormation output and copy the DNS record. Then we go to CloudFlare and add a new DNS record. The type is CNAME and the domain is laracasts.gowithphp.com. And we paste the value here. This record will also be DNS only, no need to proxy requests through CloudFlare's CDN. Now let's go to the browser, visit laracasts.gowithphp.com, and here we go.
Verifying Load-Balanced Setup2:58
This record will also be DNS only, no need to proxy requests through CloudFlare's CDN. Now let's go to the browser, visit laracasts.gowithphp.com, and here we go. Our application is up and running behind the load balancer. Now we have a production-ready setup with high availability. We distribute the traffic across two EC2 instances and we can easily add more instances when needed. The DLS certificate is served by the load balancer and is terminated there. That way, we remove the overhead of DLS negotiations from the servers and let them handle web requests only. With this setup, we can also configure some URL paths to be handled by a different set
Discussing Scaling Options3:43
only. With this setup, we can also configure some URL paths to be handled by a different set of servers. Could be php servers running a program that is optimized for certain workload or servers running programs written in other programming languages like Go and Rust. We can configure also an autoscaling group to add or remove servers as the traffic increases or decreases. But that's a topic we are going to discuss in future courses.
