Host a Laravel App on AWS with CI/CD, SSH, DB, Crons, Email, Logs, Domain, and SSL

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Hey guys,

A few months back, I made a tutorial about how to host a Laravel app on AWS Elastic Beanstsalk. I received a lot of questions and so I updated the video to include pretty much everything you would need to get a Laravel app up and running on EB, including CI/CD with CodeCommit and CodePipeline, SSH key generation and IAM connection, DB connection, migrations, and daily backups, logs saved to CloudWatch, email setup, domain registration from a third party, SSL certificate creation and forced HTTPS. I initially had some trouble doing some of these things and saw that there wasn't that much material out there to help. So, I hope this helps someone out there! Of course, if you have any tips or tricks on how to improve the video, or would like to see other content, let me know :)

Thanks!

👍︎︎ 1 👤︎︎ u/brada1703 📅︎︎ Oct 05 2020 🗫︎ replies
Captions
[Music] hello and welcome everybody today we'll be talking about everything you need to get a larval application up and running on aws after this tutorial all you'll need to do is build the application if you are interested in learning more about building a larval application particularly with the newly released level 8 and livewire leave me a message in the comments section below i'm thinking about creating an open source project if this is something that you would like to see built then i can do a series on that as well so today in addition to using continuous integration and continuous deployment on elastic beamstock i will be connecting to the server via ssh connecting migrating and backing up a database we'll then host our logs on s3 via cloudwatch set up an email address register a domain that we have purchased from a third party and add an ssl certificate and force https that is a lot but it should be everything that you could possibly need to run your laravel application on aws just a quick reminder i will be showing you guys these access keys and passwords because they are examples i will have already deleted them prior to you see in this video so they are completely worthless at that point however if you expose your actual keys to anyone these real keys that you are currently using then whoever has these keys will have access to use whatever permissions you have given them so please please please be sure to keep your keys private and secure and do not show them to anyone all right now let's go ahead and install ladavel8 alright let's open up terminal so we can create a new logical project so a lot of our new tests and since this is lateral 8 we'll be using the jet stream scaffolding which includes login registration email verification two-factor authentication session management api support and optionally team management so it adds a lot of different options here for us all right so here we will be using livewire do we want teams no all right now that that has been installed correctly let's change the directory into our application and then run npm install and vm run then we'll go ahead and open it in our favorite code editor now let's host the application on aws elastic beanstalk for this video i am assuming that you already have an aws account and make sure that you are in the right region so for me that is eu west one which is ireland okay so go to the elastic beanstalk console uh click on create application enter the name of your application again as i was mentioning before this is just going to be a test for me so i will put the names as test as well feel free to put any tags if you would like i'll just leave that blank of course laravel is run on php so we'll leave that and for this video i'll actually use php 7.4 linux 2 and we'll allow it to create a sample application so let's go ahead and click create application now we will create our ssh keys you'll need to go to the identity and access management console let's go to users and then we'll click add user here at the top and we will create a user all right then we want the video list management console access then click next for permissions go to attach existing policies directly and we will search for aws code commit power users we want this power user we don't want full access we want the power user to next yeah go ahead if you want to add tags you can do that here we won't need that for this example we'll click review and then finally create user all right now let's go ahead and create the ssh key pair you can follow this tutorial here i'll put this full link in the comment section below you can check it out yourself but i'll just be following this information all right so now we'll have to go into the ssh folder these are the instructions if you are in on a mac then you will run ssh dash keygen so you should enter your the the file name in here again i'll keep it as test delete i won't enter a passphrase in here and the reason i won't is that if you do then every time you push the repository you'll have to enter the passphrase again if that's something that you want then go ahead and do that otherwise i'll just hit enter alright so i have a few ssh keys in this folder and i do not want to show them to you so let's just filter these results and i will show you what has been added all right so you can see here that we have the test delete stop pop so this is our public key this is our private key so we will want to copy the contents of the public key and we can simply do that with cat so let's go back to the im console and click on our user now we need to go to security credentials and upload ssh public key paste in our public key and then upload it all right there's one last thing that we need to do is copy this ssh key id right here and let's go back to our project all right so we'll have to change our configuration within the ssh folder on our computer i'll just go ahead and use vim you can't open this in in any other text editor that you want i'll just use vim since it's easy enough uh and if you're not familiar with fim in order to write anything in here you have to hit i to go into insert mode all right and i have already copied this information here so what i'm doing is saying for the host of git commits for anything at amazon a device.com the user will be this that is the ssh key id right here and then our identity file so what we will compare that to is in the ssh folder and then test delete and the test delete was the name of the private key so now that we are still in insert mode we'll have to hit escape colon wq so write and then quit and then that has been saved finally we need to change the mode of the config file to read and write but only for the user in the ssh config so let's do chmod 600 config now let's initialize a repository on code commit all right so go to the code commit console click on create repository here at the top right and then we'll enter our repository name i'll go with the same theme that i've been using before feel free to write in a description but we won't be needing that click create let's go up here to ssh for me i am on a mac and you can see here this is actually what we've already done right we've created and registered the ssh public key and then we have edited our local ssh configuration so if you are lost in the last little bit you can also copy this information from here note that you will have to change these two names so here we have our endpoint and actually this is the only thing that i wanted here and now let's go back to vs code let's start get so get init hit remote add origin and we'll paste in that point you add everything hit commit m initial commit and then get push u origin master and everything seems to be working and if we refresh all right you can see our application is up and on there and one thing maybe that we should note is that let's just go to the git ignore flop file for a second and so you can see that we have env that is in git ignore for a good reason and so what we will be doing in a little bit is putting all of these environment variables onto the server itself so that we can avoid putting the env file on the repository and this will just make our application that much more secure now let's connect our repository that we just created to elastic bean stock through code pipeline all right so let's go to the code pipeline console go here to pipeline getting started and then we'll create a pipeline uh pipeline name same thing it's just going to be a test yeah let's go next our source is going to be from aws code commit note that you can actually do it from s3 bitbucket github there are a lot of others but uh for us we'll just be doing code commit repository name is test delete and we'll go under master go next we won't be needing any sort of build stage we'll just skip this for now we can come back later on and add it if need be and finally for our deploy we will be deploying our application to elastic beanstalk so let's find that and actually if you don't find your application name make sure you have your region correct because if i change this well then i have nothing here right so let me find ireland again there we go all right so that's all set up let's go next and we can review everything here looks great so let's create our pipeline now let's configure elastic bean stock for our larval application okay so go to the elastic bean stock console and here on the left-hand side click on configuration and we'll have to click on software under document root since everything in latvial is in the public folder right and so it's all in the public folder we have this index that starts out right here we'll have to change that so we'll change the document route to public and then we'll click apply okay now that that is done you're probably thinking well why do i still have this error i have this 500 server error and that is because the emv file was not uploaded from the repository to the servers remember that anything that you are ignoring within the repository will not be put onto the server so let's go back into configuration back into software edit and what we'll have to do here is add some of our environment properties the first thing being the app key so we have our app key right up here [Music] and then let's go ahead and save that while that is saving let's see where exactly this is used so you can see that it's being used in the config app.php and it's being used right here so what we'll have to do is tell our application to first look at the environment variables that we have on the server and if you do not find these then use the environment variable that you found that you find in the dot env file so this will allow us to use the application both in production and in development so what i simply did here was so if the array key exists on the server and the key's name is app key then use that otherwise use the app key from the environment so let's go ahead and commit this to our repository so git add all git commit and our message will be add server environment variable [Music] i'll push that to the server now let's connect to aws's relational database service within the elastic bean stock console go back to the configuration on the left hand sidebar then let's go to the bottom to database down here and we'll click edit here we'll leave it as the tb t2 micro for now if you think your application will need more power then of course you can change it as you wish but remember that more power comes a higher bill then we'll have to go to uh we'll insert our username and password all right make sure that your username and password our secure and save this information.env file as we'll need that later so we can go ahead and click apply yeah note for some reason uh okay they wanted to start with a letter i hated how they they limit the username and password i like to have my usernames and passwords to be very very secure but for some reason they limit special characters in the password and you have to start the username with a letter so just keep that in mind all right now let's try this out so while that is configuring let's just go ahead and save our username uh and password here in our emv file that was my username [Music] and here's my password would have rather something more secure than this but well that's what we got that's done let's go back to the configuration and get the rest of the database information so actually we'll just click right here on the endpoint maybe one thing you need to remember here is that this endpoint if you have several databases if you have one that's fine but if you have several just remember a3 and a3 tn okay so is this one that we're looking at let's go in here okay first things first we have the endpoints so let's go ahead and copy that and the endpoint will actually be the db host [Music] and if we go back we can see the port is 3306 and yeah that's the same right here and the database name is a little bit hard to find i'll tell you the truth it's always eb db as in elastic bean stock database but i'll show you where they put that where is it right here go to configuration and then db name is just eb db but if you do this several times you know it's it's always there all right so let's put all the information here in sql pro as well i will save the changes and then we will try to connect and do you think it'll work well we don't have to wait for this i i'll tell you the truth it won't work okay so be sure that the address is correct and that you have the necessary privileges and that we do not have so back here in the rds console we'll have to do go back to connectivity and security go down here to the security group rules uh to be honest you can click on either one of these it'll bring you to the same place but we'll want to change the inbound security group so we'll just click on the top one all right so we have this selected let's go to actions and we'll edit the inbound rules so you can see that it's only connected to elastic beam stock but what we want is to allow our ip to connect as well so what we want to do is for type it is mysql aurora protocol is tcp port range also 306 but the source will be my ip uh also note that it has this dash 32 or rather forward slash 32 here at the end all right then for description i always think it's good to add some sort of description note that it won't let you add any uh apostrophes uh so this will be grammatically incorrect which bothers me but we'll just put it at that let's say bat sauce all right done save and let's go back to sql pro and connect and voila we are in notice we haven't migrated anything so not really much to see here but let's go back into our code list all right we're back in visual studio code let's do php ryzen migrate so we can migrate the database [Music] now let's go back to sql pro refresh it and you can see there we go all right and the last thing we need to do is go back here to elastic beanstalk and add our environment variables here to the configuration so let's go here to software click edit all right now that we have them all in there let's go ahead and apply it and let's go back to the code and we'll have to change how we are looking for the environment variables here as well so we'll have to go to config database all right so here in config database we'll go down here to mysql and change all of these so that it looks for the server's environment variables before it looks for the env environment variables now we have all these in place let's go ahead and push to get so get add get commit i will push that so now that the pipeline has finished let's go back to the environment you can see that health is okay so it should be up and working and there we go now we have our application online now let's set up nginx so you may think everything is running smoothly and if we go to the home page it looks like it is however let's try to log in and uh-oh so we've got ourselves an error but why well we have a clue in here uh and that is engine x well if you remember from my last video larval comes set up out of the box with apache or rather it is set up for apache we can tell this because of the htaccess file in the public folder and if you remember from my last video amazon's linux 2 runs with nginx and so engine x will not read this htaccess file so what can we do your initial reaction is probably that we should ssh into the server and do our setup directly on the server trust me i've done that it's a bad idea why well every time that the server reboots or if we need to switch servers then we lose this setup so it will just be erased leaving us with a broken application instead we should write a script that will always run this configuration that we want even if we need to reboot the server well if you're wondering what code that is you are in luck i will actually just add this to a repo so that you can copy it if you want but what we will need is a dot platform folder uh within that ninjin x folder and then we have our engine engine x configuration and i'll need to give credit where credit is due uh there was a decent size post on stack overflow that went through a few different viewpoints on this topic uh again check it out in the description below if you want more information about that then the last thing i wanted to talk about in this particular section is how extensions are set up here is a great outline how you should set them up in your project note that later on we will be adding the eb extensions right here that will be running our cron jobs all right so after we've pushed our changes uh to the repository let's refresh and well it is working um you notice the styling is off that's simply because there is a mixed content error right so we're trying to pull in our css and well since it's hosted over http it will not be loaded so that's maybe a smaller problem and we'll fix that a little bit later on but we can tell that our links rather are now working and yeah so we have everything set up in terms of nginx now let's connect to cloudwatch so because we're in the cloud we could potentially have several servers going in this case the logs would be on each of these different servers and that would be a complete mess to try to get all of that data at once in addition to this one of the benefits of the cloud is its flexibility if we want a bigger server we can just migrate to a bigger one but in this case we would lose that data that was stored on the server in both cases it's much better to put these logs on aws so that no matter what happens to the server we still have these logs in order to do this we'll need to install a package from our friend max banton called aws cloudwatch logs handler let's go into terminal and pull this in then following the documentation we'll need to create an iam account with programmatic access and permissions to create a log group create log stream put log events put retention policy describe log streams and describe log groups so let's go to the iam console click on users click add a user let's name our user uh test cloud watch delete give it programmatic access within permissions let's go to attach existing policies directly we will search for cloud watch for access select it go to tags add any tags if you want otherwise go to next review and this is what we want click create user here you'll be giving an access key id and a secret access key be sure to copy these and save them in your local.env file i'll also change the region here as for me the default region should be eu west one note that you will not be given a second chance to see the secret access so if you lose it you'll simply have to create another user now that is done now let's go back to aws now that we have created a user with access to our logs let's go back to our application and follow these instructions for ladavel we'll first need to adjust our env file here instead of stack we will use cloudwatch as our login channel let's go to config blogging.php here we'll have to add the cloud watch driver that we can see in the docs i'll put it here at the bottom of the channels array we can see here that there are two more environment variables we have the cloud watch log retention which is usually set to seven days i set it to 30 days to just give us one month of logs then we have the cloudwatch log level uh it's currently set at error but i'll change that to info now let's create a factory class in app login cloudwatch loggerfactory.php and we'll simply copy in the boilerplate code that he has here as well all right note that the only thing that i changed here was the stream name okay now that we have everything set up locally let's try this out so let's go to routes web.php and let's add a log function to the index let's just say log info then let's start the local server and it should show us this in the logs [Music] to see that go to the cloud watch console then go over here and click on log groups we'll see that our lateral local group there this comes from the group name as it was defined in the cloudwatch logger factory then inside of it we have the laravel stream this again was defined in the cloudwatch logger factory and finally we see our message great now that it's working locally let's set up the environment variables on the server to make sure that it works well in production go back to the elastic beanstalk console go to your environment click on configuration under software click edit go to the bottom and here we'll need to add aws access key id secret access key default region as well as log channel let's go ahead and do that now all right then go ahead and click apply well as loading let's go back to config logging dot and you can actually see here that i've already set this up to work both on the server as well as locally so now we're all set let's commit these changes to a repo within the config login.php make sure that the default is for the log channel on the server first and if so take that one otherwise use emv all right i'll go ahead and push these changes to the server all right the last thing i forgot to mention sorry about this guys go to config app.php and in here we'll have to look for our server environment variables for dot for the emv as well as debug and maybe one thing i wanted to note for debug is that from the aws environment variables they are always a string and if you didn't note the string of false is actually true so it took me a while to figure out why this was turning up true but that is why because it it will end up passing you the string and not the boolean so here i just made it idiot proof so if it is the string false then return false otherwise return true and if it doesn't exist on the server then take it from the emv file now once you have put this within the app config file then make sure you have this within the environment properties within your configuration and remember your debug in production should always be false and in production well the environment is production all right so once you have done that let's go back to our application and refresh and then we'll go back to cloudwatch and there we go so we have level production so we can see that uh the logs are working in production as well now let's set up our domain name server as you have probably already noticed with elastic being stock you kind of get a domain already well kind of it's just probably not the domain you want so you can buy a domain from aws itself or from another domain registrar i'll show you how to do it from namecheap but it should be pretty much the same with any registrar let's first go into route 53 console and click on hosted zone click create hosted zone so enter your domain here within domain name and leave the type as a public hosted zone and then go ahead and click create here you will be given a series of four name server records we'll need these in a second all right now go to your namecheap account or the account of whatever domain registrar that is click on manage for this domain then under the domain go ahead and find name servers for us we'll be doing a custom dns and we'll have to enter the four name servers that we got from route 53 then save all your changes now let's add an ssl certificate so go to the certificate manager console and then go click on request a certificate select request public certificate and here was let's enter our domain name and we can add a card here as well so imagine if i wanted www or any sort of sub domain so we can have the asterisk followed by dots and then your domain name so i'll just have asterisk let's go ahead and click next we'll select our dns validation click next feel free to add any tags if you want i don't really need that click next and then let's go ahead and confirm our request so we have some information here for rather we have the cnames for our dns configuration i really need to do is click on this little arrow here and click create record in route 53 and create and it will create it for you so that's fast enough this one as well great all right and that's done so you know we could do this manually we could copy this and put it back here into route 53 but just by clicking on these buttons to create the record uh you can see that this has come up and in fact uh these two are actually the same uh so we just need to do it once all right let's go ahead and click continue all right now this the certificate has been issued let's go back to elastic bean stock go to go to configuration and then under load balancer click edit and here at the top under listeners let's go ahead and add a listener and here for the port at 443 which is the protocol for https and they'll ask you for your certificates and then we'll go ahead and click add all right then go ahead and click apply now that it's done loading let's go ahead and force the redirect so we'll have to go up here to our ec2 console the left-hand sidebar we'll click on load balancers all right so we'll click on our load balancer go to the listeners tab and then click uh view edit rules all right so when you go here click on edit here on the top and then edit here again uh and so it's redirecting see that's right yeah we want to redirect it to https the original host uh through one permanently yes this is what we want and that's actually what was there all right so remember this name maybe we'll go back here uh copy the name of the load balancer then go back to route 53. let's create a record set this time it'll be an a record uh we'll want to choose alias and here it should actually be under the application load balancer uh here we go just pasted that one in it'll be a simple routing let's go ahead and click create wait a few minutes let's check it out now and there we go now i have ssl certification uh here as well we can see it's been issued by amazon add an email address with amazon's simple email service first go to the ses console and go here on the left and click on smtp settings then what we'll do is copy the server name and the port into our env file in your env file note that the mail host was that server name and the port is 587 which is the default port for smtp so we can go ahead and leave the mail mailer as smtp the mail encryption will be tls back in the ses console let's go ahead and click on create my smtp credentials for the iame username in my case since this is all a test and i will delete this afterwards i'll give myself a note and just call it ses test delete to make that exceedingly clear and then i'll go ahead and click create at this point be sure to click on show user smtp security credentials because you will need to save these note that the smtp username is our mail username and the smtp password is our mail password for the from email address let's go ahead and put it at maybe at me at yeah that bike right so it should have that same domain and then then they from name maybe i'll just put my name here as well now we're back in the ses console go ahead and click domain make sure the domain from which you want to send the email is in that list if it is not click here to verify a domain go ahead and write in your domain here and make sure that generate dkim settings is checked then click on verify this domain you will receive the dns settings to add to route 53. if you click on use route 53 then aws will insert these dns settings for you and note that i will not be receiving emails to this domain uh so i can go ahead and leave this unchecked and click create record sets it could take a few minutes for this to be enabled for sending so for me it took really just about a minute for this verification status to come verified now let's go back to our code and create an email back in the terminal let's run the rsn command to create an email so that's php artisan make mail i'll just call it test mail since again i will be deleting that later on then let's go in here into resources views and we'll create a mail view so let's just call it [Music] males testosterone.php and here i'll return simple html and say hey then let's go back to the mail class it will be here within app mail test mail and let's go ahead and return this view so it will be uh males.test right here all right finally let's throw an email into the router uh just to give this a test and i'll go ahead and throw in a fake melinda email if you're not familiar with melinator uh it simply is a temporary email box that you can use so here uh actually i won't need to bring in i can bring in mail if i want um but as it is an alias it has already been loaded into the service controller so you don't actually need to do that but i'll go ahead and do that here and make sure to load your test mail right here as well and now that i'm using send just to send it out at the moment in a production environment i would more likely use q uh since that would let the page load faster and it will just cue up the email to be sent out at a later time so let's go ahead and save this and start up a local server now let's go to the index you can see it's taking a while to load that's because it was probably sending the email and writing a log so let's go into melon editor and check our email if you've never used melonator just go to mainlander.com and you can enter whatever email you want and yep you can see here is the email right so from me test mail and what does it say all right hey brad so we can see that it did in fact work and it's coming from me at yadah bike so there we go now we have the email well at least locally so now let's change the variables so that this will work online we're back in our environment within our project within elastic bean stock again let's go ahead and click on configuration here at the top we have software let's edit that so we can edit our environment properties now that we have our environment variables here on the server let's go ahead and click apply then back here in the config mail.php file remember that we need to change our or how we are looking for these environment variables right so if it exists on the server let's take it out from the server if not then let's take it from the local env file so make sure you have all this set up and then let's just go ahead and push that to get we'll get add git commit sure set up email actually maybe one last thing that we'll do before we test this out maybe we'll say hey brad from production all right so when that has loaded then let's go ahead and go back to yada bike right so our home page you can tell again it took a little bit of time to load so that probably sent out the email hopefully everything's good uh then let's go to melinator again there we go so hey brad from production now let's back up our database on s3 now that we have our database connected let's set up a daily backup just in case we do something stupid all right so to help us create the safety net we're going to have to use a package for our good friends over at spazia called lateral backup so right here we have our composer installation so let's go back to our code back to the terminal and let's install this package all right i ran into an error here and actually i sometimes run into this and i wanted to point this out so i have a php fatal error a loud memory size of whatever bytes has been exhausted and so apparently this package needs a lot of memory okay fine so to overwrite that just in case you get this problem as well just do composer underscore memory underscore limit equals negative one so negative one is essentially infinite so just whatever composer you use the memory you want just give me this package all right so we'll go that then again composer require uh level backup now it should work all right now that that has been downloaded let's go back and take a look at the instructions and back in the instructions we can see that we need to publish a config file so let's go ahead and copy this command then back in the terminal let's go ahead and publish this vendor file all right so we have everything running let's just try it out locally see what we get and actually if you're wondering what did this last command do all i did was create this config file this backup config file and we'll go ahead and edit this uh in a second but maybe before we do let's just go ahead and try it out so it's actually just php artisan backup run and actually before i run any sort of new command maybe i'm not familiar with it i'll use the help flag and then we can check it out from there so it's normally just backup run and then yeah if you only want the database then it can do only db or if you have the name of the database uh and actually you can do multiple databases you can do that you can backup just the files etc let's just try it out plain uh and see what we get so php artisan backup run let's run that all right so what is it saying it says it dumped database ebdb okay so it connected to aws that's good it zipped the files but it's taking files and directories we'll take a look at that later and it put it on a disk named local so where is that that is within storage app laudable and then you see the zip file let's just go ahead and open that up see what we have there all right so this is the file that we get let's go ahead and go inside see we have all right so we have this uh the database dump right there that is actually what we do want i can see we have users me whatever all right so it's actually taking our whole or making a copy of our entire project okay maybe this is useful for some people for us it isn't because we're always backing everything up on git i don't really see the use of this perhaps for somebody else this is useful but for us it is not so what i will do instead is do only db let's try that again and see if we can just get the database so we'll do php artisan backup run this time the only db flag and let's see what that does so yeah it dumped ebdb that's what we wanted and then it has a zip file all right so this is maybe the the most important reason so if you look at beforehand it was 1.79 megabytes which isn't too much but remember this is a pretty much boilerplate project so there's really nothing on it this can grow in size and imagine if we do this every day then our expenses on s3 while they are cheap in general this can grow kind of out of control whereas if we're just doing the database dumping it is a lot lighter so we just have 115 kilobytes not too bad and let's go ahead and take a look at that zip file as well all right so let's check out that zip file and as you can see it's just the the database dump and right here you have the sql dump all right so the next package we have to install uh is this fly system aws s3 so let's go ahead copy this and just go ahead and download that and this package is to connect to s3 and the reason we want to do that is that imagine if we don't imagine if we have all of these files so the database backups on ec2 so on our server and not on s3 well then if something happens to our server then we have just lost all of our backups so it's a good idea to store them separately in this case we'll save it on s3 and so this package will help us with that and we can see we ran into the same problem as we had before so we'll just do composer memory limit equals negative one uh and then we'll just run it again all right so we've downloaded that package let's go back to the iam console we'll need to create a user that has access to s3 so we can actually use the same user that we created for ses just a second ago we'll just have to add some permissions so click on permissions then go to attach existing policies directly and we'll search for amazon s3 full access there you go first one at the top make sure to check that then click review add permissions and there we go so we have uh access to it okay now we need to go to the s3 console all right now that we're in the s3 console let's go ahead and click create a bucket since i'm going to delete this i'll just give myself this message uh to delete it all right now let's go ahead and click next configure options here you might want to go down to default encryption and give it some sort of encryption then let's go ahead and click next we definitely want to block all public access this is just for us don't want anybody else to read this at all because it may have sensitive information on there all right let's go ahead and click next see the permissions yeah sounds good create the bucket now let's go into that bucket all right then we just need to copy our bucket name and go back to our env file within our emv file we have this key here aws bucket let's go ahead and write our bucket name right here and again since we have already created uh the user it will have the same access key id and secret access key as before and since we're using uh eust1 the default region will stay as is so all we really needed to do since we are using the same user as we used for ses is just change the bucket name all right and one last thing that we need to do here to test it out locally is go to config backup.php and then right here on the destination uh for the disks uh we don't want it to be local but we'll type in s3 here that is all we needed for the local configuration all right now let's run php artisan backup run only db all right great so it says i successfully copied zip to disk named s3 let's go back into our s3 and see if it is there all right let's go ahead and refresh there we have it we have uh the folder the zip file let's just go ahead and download that and there you have it we have the db dumps 3 which has that sql dump so now it is working locally yeah now all we have to do is put all the environment variables on elastic beanstalk so let's go back to the elastic beanstalk console click on configuration for software go ahead and click edit down here at the bottom and put in the name of the adlis bucket and click apply and the last thing we need to change here is with config file systems uh go down here to s3 and we'll have to change all of these so that it accepts the server variable environment variables first and then accepts the env file as well now that those have been copied over we can go ahead and push this to git so we can add so we are backing up the database but we have nothing to say hey do it every day at some sort of intervals so we're going to have to create a cron and on aws it's a little bit interesting how they do that so let's go over it so as we talked about before in order to extend our applications we'll need to create this folder the dot eb extensions in other words in dot elastic bean stock extensions and then we'll go ahead and have a config file in there all right so here let's go ahead and create the the folder dot eb extensions uh and then inside of it we'll create the new new file which will i'll just call it cron job dot config uh it's important that it's dot config cron job can be whatever you want and i've already done this um won't really explain too much uh but it essentially just looks for the cron job uh every minute so you can see here um that'll be every minute it'll go to the root and then run the scheduler command so now we can create cron jobs as we would normally within a lot of our application and if you're wondering how do we normally run these cron jobs in latville well all you'd have to do is go to app console and then go into the kernel in there and then here is our scheduler it gives you an example right here so you can schedule the command in this case it's inspire it's an inspirational quote and it would just push that out hourly in our case we want to do schedule command remember it was backup run right but we have the only db flag because we only want the database uh and then let's just do it daily at and i like it to be at a time when i don't have many users on the site because i will be taking up uh a little bit of memory in the server it shouldn't really affect anything but we'll leave it at that so 4am i'm assuming nobody's on there and let me just fix that typo so there we go schedule and let's just push that to the server and we'll push that all right now we are done uh if you've made it this far in the video pat yourself on the back because that was a lot of work but now you essentially have everything you need to run your lateral application in aws with all of these different services already installed so all you really have to do at this point is build your application well that's it for me for today if you have any comments or questions please feel free to write them down in the comment section below and of course if you like these videos please be sure to subscribe and if you have any particular topics you'd like me to talk about write those down in the comments below as well all right thanks a lot everybody [Music]
Info
Channel: Bradley Ahrens
Views: 16,720
Rating: undefined out of 5
Keywords: Laravel, AWS, ElasticBeanstalk, PHP, Cloud, CI/CD, SES, CertificateManager, SSL, SSH, RDS
Id: KtpiF3SUCkA
Channel Id: undefined
Length: 47min 40sec (2860 seconds)
Published: Sun Oct 04 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.