Taylor Otwell - Intro to Laravel Vapor

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
alright folks up next he's been kind of teasing what he's been working on this whole kind of six months now maybe longer you folks ready give it up for Taylor oh well alright thank you for coming to Larrick on us 2019 our seventh and biggest lyric on really the biggest player con ever in the United States or Europe so far so thank you so much for supporting the community and thank you for coming out for nothing another awesome event quick announcement after my talk we will have two hours of food drinks which are on on me basically for the first hour and lots of food so please stay and and enjoy that food I think it's gonna be really good and then if you have a ticket for lyric on after dark that's a separate event at 8:30 at Lucky Strike bowling on 42nd Street there is bowling ping-pong pool and there's also just a lot of space to hang out so if you if you're not into bowling don't feel like you have to avoid the event come and hang out and and chat with the community so I've quite a bit to cover today so I'll just kind of hop right into it and the first thing I want to talk about is sort of laravel itself and as you may know the next release of laravel is due in august laravel is on a six month release schedule so the last release was in February so that puts the next one right around the end of August and so let's talk about that a little bit to get started so as you know we've been on the 5.0 release of laravel for about four years now and laravel 5.0 was released in February for 2015 and since that time a lot has happened actually a whole lot has happened so here are some things that did not exist when laravel 5.0 came out and raise your hand if you've used one of these tools laravel horizon laravel nova laravel echo laravel scout laravel passport valley dusk socialite telescope notifications as a concept in laravel mailable z' in laravel model factories did not exist authorization policies did not exist so a whole lot has happened since laravel v dot own it's kind of crazy you kind of take for granted a lot of these things that we use every day that didn't exist it's a short time ago countless community packages have been written in those in in those years staff members for laravel have been hired back then I was the only person working on laravel full-time since then we brought on Mohammad first a few years ago yeah give it up for Mohammed so Muhammad's done a great job is kind of holding down the the commercial side of laravel our our products like Forge and on voir and spark and then we recently brought Andres Vince who's here give it up for Greece so Greece has been holding down the fort on the other side of the spectrum the open source stuff and lately that's been a lot of cashier work but I'm really thankful to have those two guys on board and they've they've really allowed me to work on a lot of the cool new stuff that I'm going to show you today and I also want to announce that we're bringing on a third laravel team member James Brooks he'll be starting next week actually so I think he'll probably start looking at some laravel Nova stuff to start but I'm sure he'll bounce around and into all of our our whole ecosystem basically yeah [Applause] so instead of the next release being laravel 5.9 I've decided to go ahead and make the jump to semantic versioning for the framework for itself and we'll be shipping laravel 6.0 in August now that being said we'll laravel 6.0 does six auto indicate that it would be a paradigm shifting release that forces you to rewrite all your code no it will likely be just like the typical laravel releases you're used to the main differences the switch to the different versioning scheme so in previous releases of laravel we use sort of our own versioning scheme for the framework itself all of the components were already semantically version like cashier telescope Nova all that stuff is already semantically versions and we used to use that first number in the version like the five to indicate sort of the era of laravel so to speak where era represented this whole aisle basically a full rewrite almost of the underlying framework because the framework was young it was changing a lot in the early days especially from one to two to three to four that happened in quick succession and we were sort of finding our footing in terms of the right architecture we wanted to adopt for the framework but I really feel like with this five dot x-series I'm just really happy with the way that whole architecture turned out with service providers and middleware the way the container works and I think moving to 6.0 is more just like a stamp of approval on that as sort of a solid architecture to move into the future with four years to come and not place as much emphasis on sort of the first number of that version so does this mean that you know we'll have big paradigm shifting or leases no but I think it just gives kind of more consistency in the ecosystem with the rest of the package is sort of as least so as less surprising when you come to laravel to have to remember this custom versioning scheme you can just use semantic versioning so that does mean that any breaking change would necessitate a new version so that means next spring there will be like a laravel 7.0 eventually an 8.0 again that doesn't mean that you're gonna have to rewrite all your stuff it's just the versioning scheme we're adopting but hopefully that just gives you one thing to think about when you are thinking about laravel no let's talk about the branding of laravel some of you may know with each major release of laravel we've actually given it a fresh design treatment if you've been around the laravel community for a while so like laravel one to two to three the websites were different the logos actually looks slightly different different people designed the websites and in the past and probably this is case the case with a lot of open source projects that's sort of a volunteer effort right we didn't have a lot of resources to pour into sort of marketing design it was all sort of me coaxing people to help me with the design like you know bugging someone like Jack McDade to help me with the website and and stuff like that so now that Larry Bell is more mature and we have sort of a budget to pour into these things I really wanted to work with a top-notch design for him to give laravel a fresh look going into Larry Bell 6.0 it's been a while actually it's been years and I I chose to work with focus lab they're one of the top digital design agencies in the United States and we spent weeks sort of poring over you know the history of laravel what it's looked like in the past how we can sort of iterate that in a way that still pays homage to the past and not sort of just do away with everything and so we actually have a fresh new logo treatment of fresh logo type treatment and actually a brand new website that I want to show you now so first let me show you the fresh logo the fresh logo type the version number I think focus lab did a really good job on this the original logo of laravel was actually three Lego bricks on the laravel 1.0 website and the logo has always kind of rift on that ever since then and this obviously pays homage to that it looks there's echoes of the previous logos here but it kind of brings it into one plane and tightens everything up a little bit and I'm really I really like the custom logo type they built for this as well so I think that turned out really well and as I said we did a new website treatment for the framework which I think turned out really nice so we've got this nice animation here in the header again with the logo we've got nice subtle animation with these building blocks floating around the page as you scroll down just highlighting all the different parts of laravel which is a lot now a lot of components and you can hop into any of those highlighting some parts of the community which we can kind of swap out and rotate as people build cool things to show what the community is doing and of course showing our laravel partners which are the development agencies that we sort of recommend if you need laravel work done of course with the new web page we have really beautiful documentation you know I care a lot about documentation I get like really obsessed with it so we made sure the documentation looks really beautiful you know no matter what size your screen is you get a nice clean reading experience good typography good fonts all of that so it's really great to use and of course still the fast search provided by Algol yet so that is a the new website I'm really happy with how that turned out and I hope you like it as well alright so swapping back to my presentation here yeah on this topic you may have noticed you haven't gotten your t-shirts yet Justin joked that we didn't do t-shirts that this year in a sense that is true we didn't do Larrick on t-shirts but we did do laravel 60 shirts for everybody so you will all get a fresh clarabelle's 60 shirt on the sleeve you have the new six logo here and then on the back laravel and of course on the front the new laravel logo so when you go out for the after party here to get food I'll go get your food and drinks and then we're going to set up the shirts here on the stage organized by size and then after you get some refreshments you can file back in and pick up your fresh laravel 60 shirt alright so what else does the future of laravel hold that's what I want to talk about for the rest of my time and if you stuck around laravel for a little while you know I love to keep laravel ahead of the curve so to speak so we were the first major PHP framework to introduce introduced cues into the core of the framework the first major PHP framework to embrace middleware in the core of the framework the first major framework to have real-time event broadcasting right there in the core of the framework the first official oh aw - server part of the framework and the first major framework to ship a powerful notification system right in the core so I'd love to try to be forward-thinking with laravel a lot of that comes from my own experience building apps with laravel and kind of dog food in the framework and seeing where does it fall short where do I want it to improve upon and going from there and right now I want to talk about the ways you get your laravel application into production so right now there's there's basically one official product you can use to get your application into production and that's laravel forge and if you haven't used forge forge is it's a tool that you sign up for like a sass monthly build product you connect your digitalocean your AWS account your Linode account and it provision servers on those services for you and it installs PHP and installs my sequel it installs retinas it does all of that server stuff for you and gives you kind of a control panel for managing that server and Forge is a really amazing product for a lot of people and matter of fact we have new features coming for forge this year that we have planned and some of the things that forged us well is painless VPS management this was really a hassle for me before forged I had a lot of scripts laying around that used to configure stuff it was just a pain perfect for small and medium projects really easy to throw up you know a project you did for a client on a forge server and have it out in the world really quickly basic load balancing is even part of forge so you can spin up a load balancer balance between a small handful of servers pretty easily and distribute traffic to those servers and one benefit is you maintain full server access on forge so that since the server's live on your digitalocean or Amazon account you can SSH into them you have full route access to them and you can customize them however you want and a lot of people are really happy with this but for years people have been asking is there something else that would be better for larger projects that need a little more things like auto scaling I don't want to have to think about what if my site receives its burst of traffic and I'm not ready for and I'm down and it's really embarrassing something that's a little more managed you know with Forge you still have to do worry about operating system updates your PHP going out of date things like that and I thought about this for actually a really long time and matter of fact a couple years ago I wrote an entire product called laravel cloud which I kind of hinted that the last time we were here in New York and I actually finished the whole product and it was kind of like a forged pro so to speak where you could connect or digitalocean account or your Linode account specify how many web servers how many workers servers you wanted and it was scaled and based on those numbers in your configuration file and when I got done with it I just didn't feel like it was revolutionary enough it just didn't blow me away we had Steve did the whole front end for the products we had the whole back-end built and we actually just tabled the whole product even after it's finished and I wanted something that just really blew me away that felt really next-generation for deploying PHP applications so for the last nine or ten months that's what I've been working on 40 hours a week I've been heads down trying to solve this problem and what I've come up with is something that I'm calling laravel vapor and laravel vapor is definitely ready for scale so this is me bumping up to 5000 users using an application the purple line you can see is requests per second and a green line is the number of users scaling up this is just over a couple minutes and you can see the response time down there not even breaking a sweat at this load so no problem at all so we made over half a million requests in these few minutes with an average response time of 12 milliseconds we're making a lotta a quest to this vapor application it's no problem at all it's really great alright so instead of talking more about it what I'm going to show it to you and we can take a look at it all right so I've been hiding this vapor marketing page for quite a while but let me just pull that up for you now alright so this is the landing page for laravel vapor similar to forge which is a hosted platform that you can link your AWS account and gives you an entire server list deployment platform for laravel finely tuned for laravel we even made small tweaks within laravel itself secretly over the last few months to make sure this experience was really seamless really nice and I think you'll really like it so you may have seen tools for PHP to put applications in a serverless environment but you haven't seen anything quite this fleshed out yet which I think you'll really like so deployments databases caches queues cloud storage asset management DNS certificates metrics we're gonna look at all this today as we dive into vapor um so before I really get into the app too far I want to just stop for a second and say what is serverless because I don't want to take it for granted that every one of you is familiar with server lists as a concept so server list is sort of this new hot tech that's been trending over the past few years driven by cloud providers like Amazon with their Amazon lambda offering driven by Google with Google Cloud functions and Microsoft has their own offering and idea behind server list is that you deploy to their platform and you never worry about your infrastructure now of course there are some where there are servers somewhere in Amazon that run you can code of course but you never think about it you never think about even the underlying operating system really updating it you never think about updating your PHP version you never think about managing your certificates and you never even think about how much scale does my application need to handle because it all elastically scales on demand really quickly to handle literally incredible scale so in the past you might have used something like horizon when managing your queues where you want to say I want 20 horizon processes working queue jobs and 400 jobs come in then those those 20 processes sort of picked them off the queue and work them with vapour you don't even have to really guesstimate your processes you deploy your application if you get a thousand jobs on your queue those jobs are going to be executed literally within seconds I mean really really quickly and you didn't have to do anything if no jobs are on the queue nothing's happening there's no workers that you're out there managing it's all totally elastically scaling on demand alright so let's go ahead and log into vapor here vapor dot laravel comm slash login all right hopefully you can see this ok so if I log into vapor I can see my projects and some of the recent activity that's happened on my vapor account and vapor is also built around teams from day one so right now I'm on my personal team which is the team that's created when I first signed up for vapor but you can create as many teams as you want you don't have to pay extra for teams and you don't actually one one single plan gives you unlimited deployments unlimited teams unlimited users unlimited projects there's no extra paying for that so you can create other teams to organize your projects by client or whatever you want to do and then you can add users to those teams and your team settings you have really fine grained control about what each team member can do can they create databases can they delete databases all the way down the line across every resource that vapor manages and you can see your team members here so let's hop back over to the projects and it's worth stating here that vapor itself is running entirely on vapor so this is an entirely server little arabella application that will be interacting with throughout this demo so if we drill into this project which I have here you can see that the project has multiple environments as well as the recent deployments for each environment so the cool thing about vapor is each environment gets its own vanity URL so you can see right here under production I have that snow a hurricane and then kind of a random token vapor dot build and I can access that URL and see my application so this is really nice because typically if you deploy to a server list environment you don't really have any kind of staging domain to interact with your application with vapor gives you these staging domains for free basically and it lets you immediately access your application with a really nice domain that you can share with your co-workers or whatever until you're ready to actually assign a custom domain to the application so it's a really nice way to get started alright so we also add when someone accesses this vanity domain we add the no index headers to the response to avoid these vanity domains getting picked up by search engines and stuff like that alright so before we go any further let's talk about how do we deploy on vapor so we have this production environment how do we actually push fresh code on to vapor so if I go on my command line this is my project actually my little dummy project will be deploying vapor layer icon and to deploy I just do vapor deploy production and what that's gonna do it's gonna do a bunch of stuff in my console but I'm just gonna hop back out here into the website because we can view it there too once it gets going so first it's going to build the project and upload it it's gonna upload my assets to cloud front so they're on a CD in and then it's gonna kick off the back-end deployment process here on vapor I can see every step that runs what it's doing to get my application out in production this is always zero downtime so it's just like on foyer when you're deploying your users are not going to get any error pages anything like that it's all going to be zero downtime so they can keep using the application as normal so you can see this is already finished deploying out into the serverless environment and for we can again use that vanity URL to access it so really quick to deploy from the command line if you wanted to deploy like a different environment like staging you would just do vapor deploy staging and you're good to go so a lot of things happen during deployment and how did vapor know what to do during the deployment that's all controlled from a configuration file in your project so I'm gonna hop over to that dummy project and there is a vapor dot yeah mol file here which just has the name of the project and then it has my different environments in it and in production you can see I have some build steps so this is what vapor did before it sent my application out into AWS and installed my composer dependencies and it does this all in a temporary directory within the project that it deletes when it's done and maybe a cache my advanced and you can do whatever else you want to do to sort of prepare your project to go out to be deployed and then as I mentioned it automatically extracted our assets and because vapors fine-tuned for laravel it knows where to find your assets it extracts them all out of that public directory it puts them on s3 it configures cloud for it all of that behind the scenes is happening that you don't have to think anything about you just can take advantage of it all right so that's the vapor configuration file now if want to look at my assets real quick I'll show you what I mean by how they're on a CDN so if I go to this login screen for laravel and I expect the source you can see that right here there's a cloud front URL so all I did to generate this URL was used to asset helper and laravel when vapors running my layer of application it injects an asset URL environment variable so any URL I generate using that helper automatically spawning to the right cloud front distribution and my assets just work as you would expect so it's really seamless all right what if we want to rollback a deployment we can actually do that right in the vapor UI so if I come to an environment and I take a look at my recent deployments I've been doing a lot of test deployments backstage because I was making sure everything was working and say we want to roll back to this deployment right here we just click on the deployment rollback to roll back that's going to start a fresh deployment it's gonna run some steps and boom or already rolled back atomically with no downtime alright what if I want to put what if I were to put an application in maintenance mode for example like when you're building a level application you might use PHP artisan down to put the application in maintenance mode well here there are no servers it's all dynamically scaling you don't have to worry about any servers so how do we do this well this is also built right into the vapor UI so I can actually do it right here from this little menu on the production environment enable maintenance mode I'll just click that confirm that action that again is going to fire off sort of a fresh deployment for that indicating that we're in maintenance mode right here with the badge it's gonna update our code on AWS all right looks like we're active now I want to show you something that I think is pretty cool if I visit this vanity URL let me close that tab I can still access the application but let's look at my paper yeah mol configuration file you can see that I've signed a custom domain to the production environment just an extra domain I had lying around called scenery to i/o if I try to access that URL I get the typical laravel maintenance mode screen so that's really nice because your users that are accessing the application using the actual URL they get your maintenance mode screen which of course can be customized and you as the developer you can still access the entire application from the vanity URL which is not index and is hidden so it gives you a way to manipulate your application log in make sure everything looks okay before you disable maintenance mode which I can do straight from the vapor UI all right so I'll come back to that environment again we can see those recent deployments the rollback in the maintenance mode we can just disable maintenance mode right here from the menu it's gonna fire off a deployment update our code all right and that is active and so if we hit this URL we're out of maintenance mode and we're back up and running so really easy to manage that directly from the UI what about environment variables how do we manage that so I think what you'll find with vapours you actually manage environment variables a lot less than you used to using other things because we know so much about your application as we'll see we can automatically inject database environment variables for you you'll see later we can automatically inject cache environment variables for you we automatically inject queue environment variables for you so you'll find that you actually think about environment variables a lot less and the main ones you think about are sort of your third-party services so for example if I'm using something like pusher or bug snag or whatever else all those environment variables can be managed right here in the text box in vapour I will rotate these keys afterwards these are just test accounts but you can manage them right here and you can see I don't have as many as you might expect to see in a normal laravel environment file because I'm not having to worry about so much of them because they'll all be automatically injected anyway you can update them here save them they won't take effect until you actually deploy so if you don't have any fresh code to deploy say you just wanted to change an environment variable and you didn't really need to change the code you're going to hit redeployed on the active environment and that will actually just redeploy the current code but it will update the environment variables and any other sort of secrets which we'll see later that you have for the application so that's just a quick way to update the environment variables straight from the Vapor you arrived without pushing to get hub or whatever alright so secrets while we're on the topic of an environment variables secrets are kind of like environment variables but when you're running on AWS lambda you're limited in terms of how long your environment variables can be to four kilobytes so if you're using like something like Passport those private keys those are really long private keys secrets have no limit on them and they're encrypted at rest so you can add those right here in vapour with just like a name and a value so like foo and bar add that secret those are versioned you can see right here current version one so what that means is if I deploy with currentversion let's say - out into production and I roll back it will actually use whatever version of the secret that that deployment was originally using it's sort of locked in with that deployment so when I roll back it uses the previous version of the secret so it all sort of rolls back together but anyway when I redeploy this application foo will be available as an environment variable just like any other environment variable all right so I'm just gonna delete that cuz we don't really need it let's kind of dig into some of these other tabs let's check out the commands tab so commands are a way to sort of run one-off artisan commands against your server this application again there's no servers to SSH into this is all auto-scaling we're not thinking about service at all anymore those days are over basically hopefully so I can just run a command right here for example like I don't know the PHP artisan inspire command an execute really quickly I can see the output here and this command didn't write anything to the logs of course but if it did write to the logs we could see that information right there all right so it's just a really quick way if you sometimes you just have a situation where you want to run the migrated command against staging or whatever really cool gray to do it right from the UI without like adding it to your deploy steps blah blah blah all right so again I'd make one fail like I had this fail command that I wrote in this dummy application that just throws an exception so you can say I see it says finished with errors and if we look at my dummy application at route slash console the fail you can see this through an exception that something went wrong and then if we hop into that in vapor we can see that output we can also see the log message that was written out so we can sort of debug what happened with that command so really easy to fire off these one-off commands against a service application all right let's move on to metrics so this is something that is not offered in something like forge this is a little bit more of an advanced feature where you can get actually really nice metrics on any environment in vapor so you can see how many HTTP requests have I got in the last 24 hours how many CLI invitations of I had what's the average duration of those things and actually how much does it cost me on lambda to do this and you can see over the last 24 hours I've had a few thousand things and it cost me a couple pennies actually on a lambda to do that we can expand out over the last 30 days and you can see I've had I don't know maybe 600 thousand total in vacations between HTTP and Q that cost me a couple bucks on an lambda and average duration for those things you can see sort of a nice chart which this demo application has not gotten a lot of use so let me scale this back down a little bit how many HTTP requests I've gotten not many until recently how much the duration is taking so I can see you know if I made a deployment I see this chart spiking up that means I probably deployed some bad code that's running a lot slower same thing on the Q side how many in vacations and then how long are those Q jobs or CLI commands taking to run on average all right so really nice and we can get this across a variety of time periods all right now there's also alarms on this screen so this is really nice where I can configure an alarm to say like hey if I'm receiving more than a hundred requests per minute which is not a lot for at least five minutes then I want you to email me or it could send a slack message or I could send you a web hook those are sort of our three notification channels so I can save that alarm and maybe configure another one for the Q if I get more than 100 per minute for five minutes email me and now I'll get an email if any of those thresholds is broken so I can know to kind of dig in and see what's going on on my application so really easy to be notified about the health of the application right from the vapor UI all right I'm gonna get rid of those so logs so you can do you can view your recent logs kind of like tailing your logs right here from vapor now if you've ever dug into AWS cloud watch you know that this is not actually the funnest thing to do in an AWS dashboard so you can see right here I've had some exceptions thrown and they're all showing up here in my logs I can go into the queue side see what's happening there there's that command we fired that failed and something went wrong you can see I've got something logging for my scheduler which is running every minute automatically without any configuration from us and if something else comes up it will just update live right here in the vapor UI so it's really nice if you get an error you can hop in here see what went wrong fix it in your application really nice especially while you're developing like in your staging your testing environments all right you can also search these logs so if you wanted a fear query by something you know you can search the log and just sort by a certain phrase I've been throwing a lot of exceptions so who knows what this will even come back all right so this will auto-update anything that matches that phrase so I don't really have to refresh this page anything new that comes in that matches query exception will be updating right here in the logs all right so pretty cool [Applause] so databases so right now we're not attaching any databases to the application so let's go ahead and do that so if I hop over to the databases screen you can see a list of the databases that I have in this team so I've got a couple here we'll use the lyric on DB database mainly but you can provision two types of databases in vapours so I can provision a fixed-size database which is a typical database where you pick how much performance do you want it to have out of the box so if I go to create database you can see right here a fixed size database I can give it a name and then I sort of pick you know what kind of specs doesn't need how much RAM does it need ahead of time and of course you just pay Amazon for that database these costs aren't really marked up or anything you just link your Amazon account what's the maximum this size that I want AWS to scale this to so you don't really have to you know you don't pick a fixed this size you just give it a maximum and in a start small and it will scale you up in like five gigabyte increments up to your maximum and then you can either make it public or private so public databases just get a username and password that you can access you can access the database from your local machine Private database is sort of live within your own isolated network that can't be accessed by the outside Internet in any way even if you have the password but the environment variables are automatically injected into your application so that it can use that database all right so how do we how do we attach a database to an application so I have this layer icon DB let's attach it to her this test application I'll go to my vapor config file just add a database key layer called DB which is just the name of the database I will just fire off another deployment let's go watch that deploy and again we don't really have to do any other configuration we don't have to worry about the environment variables we don't have to flip any other switches here vapor is going to make sure that all the right information we need to connect to that database is already injected into our application so what's that deploys we'll see if we can hit this database I've got this little tester out out here called database where we're just gonna pull everything from the user table to see if we can access that come on Amazon all right so we're finishing up here let's go ahead and hit that database route all right so it looks like we pulled back a couple records here and we can see that everything is working correctly all right so really easy to attach that database to our application so that's a fixed-size database now you might have noticed I have a server list database so how this works is you create a server list database you don't have to pick how much RAM it has you don't have to pick how much disk size you need it will automatically scale based on the demand on the database so you attach it to your application in the same way and you just kind of forget about it Amazon will automatically scale it for you you can view information about it here in vapor and if I scroll down you can see you actually get metrics so let's go through our database that we attached to our application and if I scroll down here you can see I get my max connections over the last 24 hours my average connections and my average CPU utilization over the last 24 hours and also I get charged for each of those statistics so again this database not being used very heavily so my free disk space pretty constant not using hardly any CPU at all and I can also set up alarms for these metrics as well just like on the environment so I can tell Vapor hey if my max connections are more than say a hundred connections for five minutes straight email me about that I set up that alarm I can set up alarms on CPU utilization or whatever else I want to monitor all right so really easy to manage that directly from vapor all right what about database scaling so I told you this for the fixed size database and does that mean that I'm stuck with this size forever no actually you can scale this database directly from the vapor UI so if I go to this context menu I can hit scale and pick any new size I want to scale this database to and it will be scaled for me and that's all I have to do I can just continue using my application again with a serverless database you don't really need to worry about this what about backing up and restoring my database again I can do this directly from vapor so what's really cool again if I in this go into this context menu I can pick restore and not gonna restore to any point in time in the past three days so what I do is actually give a name to my restored database so i'm gonna call this lyric on restored I'm gonna pick like to say yesterday at this time and I'm gonna hit restore and what that does is actually create a new database matching the same specs as the old database and it puts all the data in it that existed down to the second for that point in time so you don't really have like hourly backups or nightly backups whatever it's just point in time down to the second anytime in the last three days you can create a new database that replicates one of your other databases exactly so it's really easy to huh to restore your databases you don't have to worry about setting up any cron jobs to do that it's just kind of baked right in to the UI here so that's gonna provisional for a while we won't sit here till that's done but really easy to do that and not have to worry about did you remember to set up database backups when it's too late all right so let's talk about private databases so this is a private database I mean there's two types public and private if its private how can we interact with it and vapor lets you do this in a couple of ways so one quick ways just from your terminal so I can do vapor database shell layer icon DB and that puts me into a my sequel shell for that database if I have permissions to that database in vapor if I permissions to update that database and then from here I can run queries against the database and get and get results which people are apparently putting stuff in here all right so also there's another way to access my database I can go into the network here and I mentioned that we put you in your own isolated network this is all done for you don't don't have to worry about this too much kind of a power user feature in here but you can create a jump box which there's a tiny little box that we put within that private network and we give you the SSH key to that box and what that means is you can come into something like table plus or a database GUI and use that SSH key to connect to the database and then you can manage the database right from your GUI client on your local machine that you're used to all right so really easy to do that as well all right let's jump into caches so this works very similarly to databases you can create Redis clusters directly from the Vapor UI with as many nodes as you want in the cluster so I've got one here called Larrick on cache let's go ahead and attach that to the application in the same way actually before I do that let's see what happens if I hit this cache route before I attach the cache the database alright to the application so I'm a config file you might remember where you just added that database thing we didn't add anything for caches but let's go ahead and hit this cache route and see what happens so we're just gonna try to put something in the cache and then get it back out alright so if I go to this URL go to cache DynamoDB you can see I dumped out as my cache driver and it did work I did get Taylor as the result so what happened here and what happened is if you do not specify a cache to an application we automatically create a dynamo DB table for that application that can serve as a cache and laravel has a dynamo DB cache driver baked into the framework so if you don't really need a Redis cluster for your application maybe you're just doing a few basic cache operations you don't have to do anything you can just deploy and start using the cache no configuration at all dynamo DB is totally server list it's totally auto-scaling you don't have to think about it this also works really well if you're just using like the scheduler and laravel and that's really all you're using the cache for maybe to prevent like your scheduler jobs from overlapping this works great for that as well but if you want a little more power and you want a little more speed you can can create a Redis cluster so let's go ahead and attach that to the application just like we did database basically we're just going to say cache Larrick on cache paper deployed production that's gonna attach all the right environment variables we need to make this happen again putting our assets out on cloud front and once this updates we should be able to hit this cache route and see that our cache driver has been automatically changed to Redis the Redis C extension for PHP is already installed in the vapor runtime we don't have to worry about that so we know we're going to get great performance and then we'll be accessing this Redis cluster without flipping any other switches or injecting any other environment variables manually on our application so it's really easy to attach these clusters to your projects alright let this finish up all right so that should be active now you see it switch to Redis our cache is working we didn't have to worry about any other configuration we can just continue using our application now what's really cool is say we want to scale up our Redis cache right now I've got two Redis nodes on this cache and I can just go right into this context menu bump up those nodes to like three or four and start scaling it just that easy alright and that's gonna do your app is not gonna go down necessarily when you do that you can people can continue using the application while your cache is scaling also just like databases we get nice metrics here about the cache how much CPU CPU we're using our cache hit rate how many times we're hitting the cache how many times we're missing the cache we've got a pretty good hit rate right now on these last few hits and also the CPU utilization across our individual nodes in the cluster so if you're like me before something like this came along it would be really intimidating for me to manage ElastiCache clusters to manage RDS subnet groups to manage V pcs to manage security groups and rules and a lot of stuff is happening behind the scenes to make this as seamless as possible for laravel developers to deploy service applications all right so that's kind of a basic overview of how the cache system works in vapor all right so again how do we interact with this cache from our local local application so while we're developing it would be really nice to be able to sort of inspect the reddest cache see what's in it and maybe debug a problem in our application and all these elastic caches are within your own private networks so it's hard to access them from the outside again we're gonna leverage that jump box feature that I showed you of the network and right here from my command line I can do a really cool command called cache tunnel where I give it the name of that cache and what that does is open up a port an SSH tunnel to that elastic cache on port six thirty seven eight which is one lower than the default Redis support and then I can go to any sort of Redis GUI application localhost on that port and I'm right there connected to my cache and let's see if we can put something in it here well I don't know why it's not showing this variable but I can connect to this cache and inspect anything that's in it and sort of delete them add keys whatever I need to do right here from my local machine and then when I'm done I can just close off that connection and close the tunnel all right so that's caches and cache scaling cache metrics and all that so what about queues you'll notice in my configuration file I didn't have any configuration items about queues that's because you actually don't have to do anything you don't have to add any configuration you can just deploy and start dispatching jobs so let me show you how that works they get rid of meta meta striping at me here all right so I've got a couple dummy routes in this application I've got a queue route which is just going to give us a little dashboard which I'll show you in a second I've got a dispatcher out which is going to dispatch some jobs onto the queue it's going to create sort of a payment eloquent model just do like I some dummy work I think the process payment job sleeps for one second and then just deletes the payment out of the database so just like a really simple simulated queue job it's going to dispatch this payment received event which is going to be broadcast to the front end so we can see all the jobs coming in live all right so what this looks like is if I pull in let's go to this queue route let's see people are already messing with it because she I didn't have to configure any cue workers and as you can see it's handling all these cute jobs pretty quickly actually considering they sleep for one second this is all going to be dynamically scaling if you've got hundreds of jobs coming in no problem no sweat everything is going to run really quickly all right so that's really all there is to say about cubes because it's you just deploy and start using them there's not a lot of configuration that Vapor configures AWS it sets up eventsource mappings from sqs into your service application so that when a cute job comes in and invokes the application processes the job using all the normal laravel queue worker stuff and everything works basically exactly how it would work on any other server like a digitalocean server so really painless alright let's talk about the scheduler there's something else we haven't really talked about that's a nice piece of laravel so as you already saw if I come come into my console kernel I was logging out some information from that schedule command this log info scheduled function called every minute and we can see that was being written to the logs again this is all set up for you we set up cloud watch rules to invoke this every minute to call the scheduled run command and all of your stuff runs like normal just like it would on any other VPS server you don't have to do anything you don't add anything to your configuration file you just deploy with vapor start using the scheduler immediately no configuration at all custom domains so we've already been using a custom domain a little bit so I want to show it to you in the UI though there's actually a separate page for domains what's really cool is I can even purchase domains right here from vapor which will be on my AWS route 53 account alright so say secret project com it goes out and sees if that's available it's not unfortunately but it gives me some other recommendations for domains I can purchase if I purchase the domain right here from vapor we automatically create a wildcard certificate for it we automatically create a DNS zone for you all that's taken care of they all automatically renew of course for free and you're ready to go if you do not purchase your domain through vapor of course no problem you can just add a domain right here a domain you already own it doesn't even have to be on AWS it could be through some other registrar like hover comm once you add that domain we can drill into it here it's gonna give you the name servers you want can use again this is optional you can manage all of your DNS right from vapor so you have everything in one spot if you don't want to do that you just manage your DNS wherever your domain is registered and if you choose to do that you may have noticed in the deployment output we give you the cname records that you need to add to your registrar to point your domain to your server this application so this DNS the part of vapor is really cool but but an optional part of vapor if you don't want to use it okay so we can add DNS records we can manage DNS records and you can see some of these are grayed out these are records that vapors managing forests which we'll talk about in a little bit but it's managing that cname record to get my domain onto point into my service application it's doing some stuff with SES which we'll see in a second and whatever else and then we can see my certificates for that domain again we automatically make wild card certificates you can request a new certificate if for whatever reason you wanted to do this using dns validation which will be renewed automatically forever or using email validation which you have to do manually every two years but if whatever reason dns validation doesn't work for you you can do that but most of you will probably use dns validation and once that issued just takes a few minutes we already saw in my vapor configuration file that you just attach the domain to the environment using a domain key you deploy and you're done vapor will automatically add those cname records and if you're not using vapor for that you can add them to your registrar and you're ready to go all right so really easy to use or even purchase custom domains right from vapor and attach them to environments so mail we saw that vapor added some DNS records for SES when we're on that DNS screen and what that does is automatically set up the deccan validation for the domain it automatically validates that you own the domain it handles all that DNS stuff for you when you deploy so when you deploy we also inject the environment variables to send email through Amazon's SES service if you don't want to use that you just inject your own mail and variables to use something like postmarked or mailgun or whatever else but you're free to use Amazon SES and all you have to do is start sending a mail so I've got a route here for mail where I just send a test email say maybe a flight was updated and I don't have to configure any environment variables I don't to do any other configuration vapor does it all for me so that if I hit that route slash mail it will descend for me and that's really all I have to do don't have to do any other configuration file uploads kind of the last big piece I want to talk about so when you're used to working with sort of traditional server based PHP applications you have to you know interact with you may send your files straight to your own server and interact with sort of the files global super array or whatever but with serverless applications there's no that's not really recommended you can do it on Vapor applications but there's sort of limitations around serverless applications doing this for example you can only upload files that are ten megabytes are smaller and so on so what's really recommended is to send your file straight to s3 directly from the client side and this is really a good practice even if you have traditional server based PHP applications that way you're not bogging down your own web servers with files that people are uploading all the time all right so to make that happen we have to do a few things actually how do we securely do that how do we send a file from s3 or from our client straight to s3 in a secure way maybe only for authenticated users of our application so how you do that is Amazon s3 has a feature called pre signed URLs which are very similar to signed URLs and laravel where we can ask the Amazon SDK and PHP to give us a pre signed URL that allows us to upload a file on to s3 and then we can just push that file up using that secure URL which may be expires after a given time so there's kind of a little a few moving pieces to make this happen with to ask our back-end to create that pre signed URL we have to get that URL back on our client side and then we have to somehow make like a request to send the file to s3 using that and then we can ping our back-end and say hey we're done uploading the file so I thought that was like quite a bit of moving part so I wanted to try to get a little bit easier so I'm going to show you this little demo page I built to do this let's go ahead and login to this application all right so if I go to slash profile I built this sort of like little dummy profile page where you can just update your name and your profile image and so let me jump into the code for this real quick and because I didn't want you to really have to worry about pinging the back end to get the s3 URL bring it back sending the file blah blah blah I actually wrote a little JavaScript package that you can pull into your application that's out on NPM well let you do a really cool thing called vapor dot store so this is just a little view component where I have a file input when they click Save we're going to get the file input which has like a ref on it so I can access it in view and then I'm just gonna call vapor dot store and pass it the file what that's going to do is ping our back-end to a route provided by the vapor service provider in our application get that pre signed as 3rl get it back send the file to s3 it's going to give us the current upload progress to s3 so we can like show like a progress bar or whatever once it's done uploading it's going to give us the stored file object that gives us like a UUID the key of the file in s3 the bucket the file extension all that good stuff then we can ping our back-end and say hey they're done uploading their new avatar go ahead and and save this and so there was another situation I wanted to try to prevent where what if someone uploads the file to s3 on the client side and they sort of abandon the rest of the action they don't save the profile with the file to sit out there forever no so what we do with vapor is we create a temp directory within your storage bucket for the for the environment when you first call vapor store we send the file to that temp directory and any file that's in that temp directory for more than 24 hours we automatically purge out for you or we configure s3 to purge out for you and so then when you ping your back-end in this once this file is done uploading what you can do is just copy over from the temp directory into a more permanent directory like to say an avatars directory like I'm doing right here on lines 90 and 91 all right so that's kind of how that works and how we avoid that situation so basically if I come in here to my page I can just pick a new file young me or something hit save you can see we get the progress our it updates copies over to the permanent storage and s3 and we're good to go so really simple it did all that pre signed URL stuff for us all we had to do was really interact with vapor store and handed the file and it did the rest of the work so really easy [Applause] all right so how did vapor know to make an s3 bucket first to even do this again that's in my gamal file you can see I have this storage I can just attach this I don't have to create anything in the U I just add it to my configuration file with a name I want it to have and when I deploy it will crew make sure that buckets available it will configure the auto expiration of that temp directory and all of that all right so that's file storage so just a couple other tidbits to finish up so what about we've seen build steps that run on locally on this machine so like installing my composure dependencies and and so on but you can also have deployment steps so these are steps that run while the applications in the service environment so for example migrating the database I can't do that for my local machine so what I do is actually add a deploy key here PHP artisan migrate force let's say just like that and now when I deploy what that's gonna do is all those build steps ran locally but it's gonna run those deployment steps actually on the on the AWS side so we hop into vapor go to production let it update our code and then right here we're gonna see it run those deployment hooks and we'll be able to get the output for those deployment hooks to make sure it looks okay after they run so that's how you would kind of migrate your database or anything else you needed to do on the server or the serverless side so to speak let this guy finish all right so that runs and you can see my deployment hook there PHP artisan migrate force I can view the output right here of course we had nothing to migrate since we didn't generate any migrations I could also be the logs for that like if it failed to complete successfully and kind of review everything if one of these steps failed nothing really goes wrong with your application in production it's all atomic so as long as you know you don't get to this last step where we update the function alias to port to the new version you're still running the old version and this is just a failed deployment that never got activated so that's really nice one last thing I wanted to show you is so all the times I've been deploying I've been doing it from the command line on my local machine or right here in the vapor UI but you can also deploy from your CI pipeline if you want to do things that way so if we look at that test project we've been messing with in my composer Jason you can see that here in a dev dependency I've got the vapor CLI right here in my composer file so what that means is of course I can run vapor commands from wherever so in this example like I'm using a chipper CI which is a new laravel based CI tool that Chris Fadal and David Hemphill are building let me zoom this in a little bit so let's pretend we're using this for our CI platform for this application I'm gonna jump into that vapor layer con project C go to my build steps you can see I'm just running my tests all that stuff and I'm going to comment this last deploy step where we can just call into our composer vendor directory PHP vendor Ben vapor deploy production I'm gonna save this deployment pipeline let's go out here and let's go ahead and get commit updated at Larry Khan and we should be able to push all right so you can see this bill that's pending out here and this is actually really nice because then you just get that push to deploy functionality that you may be used to you can just bake it right into your CI platform just gonna run through this pretty quick I think all right and that's going to deploy let's go out onto vapor production it's probably building our projects pretty soon we should see a new deployment there it is you can see this was all triggered from the CI platform so this is a really nice way to do things in production you can have a CI platform run your test and then when you're done run your vapor deployment so everything's right there and your continuous integration platform all right so really nice [Applause] all right so what about testing your application locally so we actually included a command in the vapor CLI called vapor tests and what this does is run your tests in a docker container with the exact build of PHP that's running on vapor as it also gives you my sequel and Redis available to you and all you have to do is run our tests it spins up that container runs PHP unit and you're good to go you've tested against the actual literal identical PHP build that's running on the production vapor installation now we've done a lot of stuff in the UI we've created databases we've created caches if we look at this vapor CLI tool everything I did on stage today you can do straight from the command line create databases scale databases scale caches it's really nice so like if I do vapor database foo should it be publicly accessible let's say no I want to fix size general-purpose can fix pick the size all that good stuff all right so I'll just cancel out of that we can even get metrics for the application right here on my command line last 24 hours once my stats look like how much does that cost me on lambda the cool thing about server lists is when you're not your application is not in use AWS is not charging you for that use so overnight if you're if your application is very kind of it's really busy during the day but it's really dead at night when people go home you're not really being billed at night for that application and then it's scaling during the day totally automatically as much as you need really nice all right so that's kind of what I have today laravel 6.0 laravel vapor robust serverless deployment platform for laravel really nothing totally robust like this exists for any language in any ecosystem so I'm really happy to get this out there for laravel and kind of try to lead the pack and just sort of an auto-scaling serverless future for laravel and PHP with automatic asset handling database scaling database restoration cache scaling domain certificate management cloud front management all done really easily for you with a nice UI [Music] [Applause] we'll probably be shipping this out in a few weeks for everyone to use for right now after this talk I'll ship out this page out to be live in production at vapor don't laravel not build you can get your name on an early access list so we can get some more beta testers in there the price thing will be really simple it's the same price as the business tier Forge one monthly price unlimited projects unlimited deployments unlimited team members [Applause] so I think you'll really like it I actually I didn't know what to think about this talk as I was preparing it because I felt like vapor when I'm using it feels deceptively simple in terms of what's happening behind the scenes for I spent nine months poring over eight of the u.s. Docs and worrying about subnets and security groups and V pcs and routing tables but I tried to do all that to give you a really nice seamless experience so you can never think about scaling or servers again hopefully for a long time alright so stick around for the after party
Info
Channel: StreamACon Streaming Conferences
Views: 47,893
Rating: undefined out of 5
Keywords: Laravel, Laracon, PHP, Laravel Vapor, Taylor Otwell
Id: XsPeWjKAUt0
Channel Id: undefined
Length: 64min 20sec (3860 seconds)
Published: Wed Jul 24 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.