Deploy Laravel to DigitalOcean

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello in this tutorial i'm going to show you how to deploy a laravel application into a digitalocean server with nginx and mysql as a database so let's get started the first thing i'm going to show you is the application that i'm going to be deploying it's a very simple useless application and just type a message here it saves the string into the database and it fetches all the messages from the messages table so the first thing we need to do is uh sign up to the digital option or login if we have an account i'm gonna be leaving an affiliate link in the description that is gonna give you a hundred dollars to spend over a period of 60 days since i already have an account i'm just gonna log in and i'll come okay once you login or create an account we're gonna click click on the create button up here and then in droplets after that uh we're gonna select marketplace and we're gonna search search for limp which means linux nginx mysql and php so this is just an image that contains nginx mysql and php pre-installed so we don't have to do that ourselves and then i'm just going to select the smaller server you can select whichever makes more sense to you and i'm gonna just select a random region here i'm gonna click on monitoring because uh the monitoring tools are better if you click on this check early option option as well for the authentication you can you have two options the previous one is with ssh keys which i use personally if you don't have one added to your account you can click this button and then follow the steps here and paste the key here give it a name and then add key you can also skip the step and just create a root password so if you want to do that as well if you think it's easier but i'm gonna just select the ones that i already have in my account and here i'm just gonna change the hostname the one that makes more sense so i'm gonna set it to tutorial tutorial and not tags default project and that's it create droplet and that now is gonna create our server it's gonna take a little bit uh so i'll come back when it finishes okay so now that it finished i'm going to copy the the ap address from here and then i'm going to go into a terminal [Applause] and i'm going to ssh into the server so i just sh root add and then the ap address of the server yes so now what i'm gonna do is create a new user just because it's bad practice to use the root user so i'm gonna create a user and i'm gonna name it cosmetics just because that's my name you can name it whatever you want then we need to type a password so okay and then i'm not gonna fill any of the other information now i'm gonna add the permissions the permissions to the user so we can use the sudo command so user mod a g sudo cosmo after that we can change login to that user with sudo dash and the name of the user and we are in the user now we need to add our search key uh into our computer systems key into the user so we can asset directly to this user if i change to another terminal and try to login with the user it's not gonna let me so i need to create a directory which is mkdir and then that ssh and then change mode 700 to the same directory and then we're going to create a new file called authorized keys uh i'm going to use beam but uh you can use nano if you don't know how to use bim because it's a little more straightforward so here in this file we're gonna paste our computer's ssh key so she's gonna go into the computers terminal and then cut ssh id there's a proof and then i'm going to copy this and i'm gonna paste it here and then save and exit and now we if we try to ssh with the user we should be able to yes and then i'm just gonna exit this terminal since i don't need it anymore we're already logged in in this other terminal okay now now we need to computer configure the firewall uh to that we're gonna do sudo ut fw allo allow nginx http http uh now we can connect to the nginx server from the internet the firewall will allow these those parts to be open to the public now we we're gonna we're going to run the mysql secure installation script okay this uh valid pass validate password question is uh just to make if you want the password to follow certain rules like uh a characters numeric uh characters and that stuff uh i don't need it needed so i'm gonna say no and i'm gonna type the new root password for all the other questions i'm gonna just leave the default now i'm gonna log into mysql and uh create the database and a user for the [Music] for the application so i'm gonna do sudo my sql you root using password [Applause] and here i'm gonna create the user first so create user i'm gonna name it up at local host you can emit wherever you want just change this part and then e then fired by and then a password i'm gonna just tutorial pass this should be a password a secure password and then i'm gonna hit enter we also need to do another similar command with alter and then i'm gonna copy this language we're gonna change with and then here mysql native password just because some uh mysql clients use this protocol i know what is called uh do login to the mysql server so if we for some reason need to look from a remote environment we can do this without problems okay so now i'm going to create the database create database i'm gonna name it laravel but uh you can name it whatever you want just make sure to use the same name on the m file that i'm gonna be showing you in a little bit um and now we need to give our app user permissions to read and write to that database so i'm gonna keep grant all on laravel that to up at local host okay host and that's it i'm gonna leave in the description below all these queries and the bash commands so you can just copy them and modify them uh accordingly and so it'll be easy for you to to follow this tutorial now i'm gonna close the privileges and uh that's it i'm just gonna exit mysql after that we need to install the php extensions that laravel uses first we're gonna but first we need to update the system so sudo fd date okay so now that it finished um we can install the extension so sudo fd install and then we're going to install trins to extensions uh which is php bc math bcmat and then php mb string php xml then yes okay so now it finished uh so everything should be okay now we will continue to installing composer before we install composer though we need to install the unzip package so slow empty install on zip okay so the package is installed now now we're gonna now we're gonna download composer with this command and uh it's just getting the composer installing and then run it we need it with php so okay so it says that it was installed to the home directory which is this one what i'm gonna do is uh move this file to the bin directory so we can access access globally sudo nv composer do user local bin composer and now we can use composer v and we have composer installed so the next thing we need to do is uh clone our application i'm gonna clone it from github i have i have this repository with the uh with the application i'll show you at the beginning so i'm just gonna make sure this https selected here and then copy if you have a private repo it's going to ask you for the password and email when you clone the repo so first i'm going to cd into the bar www and then here i'm gonna do git clone and then paste the url that i copied from the repo this is saying that i don't have the permissions to create a directory so i'm gonna change this directory owner to my user so it's changed on and then call me then this and that should be it now if i clone the repository everything is fine so i'm going to see the entity repository and now here we have all the files so what we're gonna do next is install the composer packages so composer install okay now that it finished installing the packages uh we're gonna move into creating the m-file so what we're gonna do is copy the example and file and then we're gonna generate the the key this is used for passwords and stuff like that so it's needed and then i'm gonna update open the m file but i'm gonna use beam again if you again if you don't know how to use bin just use nano instead uh so i'm gonna use beam that amp here i'm gonna change a couple of things so the first one is i'm gonna change it to change the environment to production and then here we have the app key that you shouldn't be making public i'm not going to use this application so it's fine for me but never sure this key and then i'm gonna send this to false senses production we shouldn't be in the book mode then this we need to change it to either the house name or the ip address if you don't have a hostname just use the ip address like i'm gonna do i'm gonna copy the ip address from here and then paste it here so that should be fine and then here we need to change the database name the username and the password the database name is the same as the one i created so i'm not going to change it but if you created one with a different name you change it here then the username was up for me and the password was tutorial up now material pause third pass so i'm just gonna save and quit and i i'm gonna run the migrations now so i'm gonna do php artisan my great and then since we're we are in a production environment i'm gonna pass the force flag so now all the migrations were run successfully so that means our tables were created and let's go into the next step which is configuring nginx so we need to create a new file in etc nginx sites available and then here you just create that with whichever partner makes more sense i'm gonna set it to tutorial and here i'm gonna paste paste the configuration that that i already have i'm gonna leave i'm gonna leave it in the description below so you can copy it as well okay so this is the file that i pasted here so the first thing we need to you need to change is this which is the [Music] ip address you should set the ip address for your server and then the path to the public folder this should be the name of the folder that was created when you clone the repo so this is mine just change that and then we change and quit that file we save it and now we need to create a symbolic link to the site's enable folder so i'm going to do sudo symbol the link to etc engine x sites available tutorial and then i'm gonna create the link to etc engine x sites enable tutorial and we're gonna test the configuration with engine ng next dash d and everything looks fine so now we should need to restart engine exo sudo service engine x to restart okay so the last thing we need to do is we need to change the owner of the storage folder and the bootstrap cache folder so to that we just do sudo change on r and then we set the new user which is the the user that nginx uses and then we just point to our storage folder and we do the same for our boost bootstrap cache folder and now that we have everything set up we should be able to visit our rpip address and we should see the application that i show you at the beginning let's see if it works and here it is if i type a type a message you see that um it gets saved into the data database is a retrieve and show to the user so that's it for this video thank you for watching and hope you have a great day
Info
Channel: Cosme Escobedo
Views: 2,396
Rating: undefined out of 5
Keywords:
Id: GhGDunq_OSw
Channel Id: undefined
Length: 19min 6sec (1146 seconds)
Published: Mon Sep 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.