Deploy Laravel to cPanel

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi in this video i'm going to go over how to deploy laravel to a shared cpanel server and the reason for this i've seen um recently i've seen quite a few questions from various people in various groups i'm in uh asking how to deploy laravel onto as well so cpanel really on a shared server so i'm going to go through those steps um a word of warning you do need ssh access to follow along with the steps i'm going to go through so i've got this um i've got this layer of application and it's just it's a quite simple application i'm not really yesterday uh so i'm going to go for the motions of actually deploying this onto our server so i've set up a new domain or it's a domain i've not been using so i've got this test site that's already been mapped to cpanel so i've just got an empty directory on there and we've got our cpanel ready to go so the first thing i want to do is i want to connect to the server and to do that we'll say ssh and then we put in the username so in my case this is dc first and then it's the domain name so dc host.dev but in your case that might be the ip address it might be you will definitely will be a different domain to this and then we put in the port number uh and then we need to put in the password to actually log in so that brings us into the account so if i do let's look at the files that's in this server i can see there's a public html folder and the publication folder we don't want we definitely do not want to deploy laravel into that folder because it would mean things like your env file will be publicly available and your vendor files that everything that's in your all the sensor files would be available and it's a really bad idea to put them inside the public hmm folder so definitely don't do that so instead what i like to do is install laravel into a folder above the document wrote so publication delete the publication all for well completely so i'm just going to do that now so it's the rm and i'm going to do hyphen rf uh be careful this command if you're not familiar with it is basically business recursively enforce uh the delete um so in this case i'm gonna say public html um basically it what comfort him as i saw just then and it will actually go ahead and just delete whatever you tell it to so you can be really careful that command so now i can see that there is no public html folder there so once i've actually installed laravel i'll be mapping laravel's public folder another simple what's called sim link in it with the public html folder so it will kind of actually exist so i'll go through those motions all right so if we come to we've got about our project and we'll copy the ssh connection details and i will try to deploy this is going to fail straight away which i'll go for the motions anywhere so i want to put it into folder called laravel and i'll go for the motions and it tells me that can't do that because just make sure they're quite fast yeah so we'll do that because we don't have access to it which is fine so what we need to do is well there's two ways about it now you can either deploy using https which means you have to log in every time you make a change which i don't recommend so instead you can generate an ssh key on your server add it to your deploy key on github and that way the two can communicate so that's what i'll do so all i need to do on the server is type ssh keygen if i can spell it correctly so it's asking me some options i'm just going to go the defaults because i'm happy which have it in the default path i don't want to pass phase that's freeze rather so this is the actual path where it put the public key because we won the public not the private so if i just say cat and paste in that path with the actual correct path then it gives me the full public key happy for you to see that because i'll be deleting that once i finish this video so now i need to do is go into my settings and go to deploy keys and add a new deploy key so i'm just going to call it server passing the key doesn't need root access now right access i'm going to leave that unticked and then click add key so that's now been added so now if i come back to the server i'm just going to clear this out and if i want to try run that command again this time it's authenticated so it actually runs uh so now if i do ls i can see i've got a laravel folder and i've cd into laravel and do ls again i can see the content of variable so we are up and running in that sense so i'm just going to go back to the room so what i'm going to do now is assembling the public folder with the actual document room and to do that we'll say ln hyphen s and then i need to give it the path so laravel public and then i don't need to give it the actual public html directory and that's that's create that symbolic link so now if i see the into public html and do ls it actually shows me the contents of the laravel public folder so it's quite convenient so again i'm going to go back to the root when you're installing the cpanel the file permissions nearly always are wrong so you always have to go through these extra steps to add them so i'm going to do is to shade mod which is like change the actual file permissions and say 775 on the laravel directory and i'm going to do the same for laravel public and also on the storage directory as well and now i need to i want to actually change the file permissions for the index file so i'm going to say laravel index.php of course i need to keep it public now we've got the correct place in there okay so now we've gone that through so i'm going to seed it into laravel and i'll do a composer install touch installer project so that's now now installed so the next thing i need to do is i need to generate the env file so i've i have got you can't quite see on here it doesn't show up basically i have got an env example file so if i do it on in cpanel and make it make it more obvious so if we go into the file manager and go into laravel and here we've got this dot env dot example and if you don't see these make sure any settings you've got picture hidden files or you will see anything that starts with a dot so we have got this inv example so we can copy that so that's wrong what i'm going to do now so in the root of the laravel folder i'm going to say cp for copy dot env dot example 2 dot env so that's that's now been generated and i will also need my a natural okay so i'll say php artisan generate key i cannot remember if this is what we're around or not i always get the wrong way around okay generate that's now being generated okay so now if we go to our project and we'll see what state it's in and now our project's actually loads up so it has as deployed so it means now we can make any changes on you know locally push up to get up and then we can come back to here any time and do a git pull to kind of pull down i'll see if i get paul at the moment nothing's going to happen um basically it sounds like it so it's already today so i'm going to try doing that again i must have liked to give me these these messages because it's brand new i've not actually set up the game complex stuff with it but this gets up today it's not actually going to pull down um so one thing i haven't done is i haven't actually connected this to a database so i can't actually use the application yet so i want to do is go into mysql so in mysql i've already got the database but let's just pretend that i haven't so i am going to just delete all of these just so we can start from from the beginning okay so the fact i want to do is i want i want to to database i'm going to call the database app and then i'm going to create a user or user called demo for lack of a better name and i'm just going to generate a new key get one they happy with and then click on use password and then click create user so what i want to do is i'm just going to go back into i'm going to edit using vim to edit the env file so i want to press i to go into edit mode and it's password i've copied i'm going to paste that that in and then come back so now i've created the database and the user i just need to map the two together so i'll go to section because i've already selected i can just click on add give it the default privileges so while we're here i'm just going to create add in the database name and then also the username i'm going to press escape and then i can then press call on right wn quit to write and quit the file that's now actually been saved so i can save these changes and we should be ready to deploy ready to migrate our database now so if i do php artisan migrate then it tells me you can't find the driver and that's probably because it hasn't got the driver enabled on my cpanel again it's another common thing so if i set for php versions so i'm using php 8 and generally used on early versions you you'll have a wikipedia underscore mysql there isn't one on here but instead we've got this nd video mysql so i'll tick that one i'll save the changes then i'll save so if i come back and just run the command again now then now it's actually being connected and it's created the databases tables so then i can go to application and i can hit register so i can put in my name email put in credentials and we're in our application so we are up and running very easily so that's basically being the run of connecting to your database one last thing i do want to touch on is i'll just come back up here and just log out clear this out so if i do my ssh connection again it's gonna ask me for my password every time and it kind of gets gets tedious doing that so instead it'd be really nice if it didn't ask for a password it just let me in because it knew i was authenticated on this device and i can do that by adding an sshk so in cpanel if we just search for as a search and then access and we want to manage access and we want to import and uk so the main ones i did earlier so i'm going to delete that just to make sure we're starting from refresh i guess i want to import an sshk and then on the mac what i want to do is get my ssh key which you can get from your ssh folder your id rsa pub so i'm going to copy this key come back i'm again i'm going to generate this key afterwards after after i finish this video so no worries about security so i'm not going to give it a nail so i'm happy with the default so let's say i'm going to leave and click on import so that's been that's got in but it's not been authorized yet so to offer has it you need to click on manage and then authorize so any once it's all for ours can you actually log in without your password so now if i click that again and now if i try an ssh in now it takes me straighted for what i'm having to put my password in every time so that's a much better way of doing it generally i think it's recommended for passwords logins as much as possible um yeah so that is quite a real wild case scenario of getting application and having it installed onto your cpanel
Info
Channel: DC Blog
Views: 4,152
Rating: undefined out of 5
Keywords: Deploy, GIT, GitHub, Laravel, SSH, cPanel
Id: GGzBhA1cY1s
Channel Id: undefined
Length: 14min 10sec (850 seconds)
Published: Mon May 17 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.