Deploying Laravel Project on Shared Hosting | Laravel RESTful API

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone this is bilal khan and you are watching simplified coding we have finally finished our api project using laravel and now in this video i will show you how you can deploy the project to a live server and here i am going to use a shared hosting now you may ask why a shared hosting the main reason is it is cheap and for learning purpose you do not want to spend too much so that is why i selected a shared hosting here and i have purchased a shared hosting from hostgator india so hostgator is available worldwide so wherever you are from you can buy a shared hosting plan from hostgator and it is very cheap so i have already purchased the hostgator shared hosting plan and i have the welcome email for my hosting so whenever you purchase a plan from hostgator or any other hosting provider you will get a welcome email that contains the information about your server and here in the welcome email i have the username and password for my server and using these i can access my server actually access my cpanel and do whatever i want in my server so now i will show you how we can host our laravel project and thus shared hosting so this is my welcome email here you can see and i have all the details about my server and this is the user name and this is the password and sorry i cannot show you my password so what i will do is i will login to my server using this username and password so first i will go to simplified coding.tech that is my domain name and if you will buy this hosting for one year you will get a free domain name as well so you can buy it it is very cheap and affordable so i will go to simplifiedcoding.tech and then i will open cpanel now it will open the login page and here i can put the username and password that i got and my welcome email and i can easily login so this is my cpanel and here using this file manager we can upload all our project files here and with the help of this mysql databases we can create the database but this process is easy but it is you know not recommended way of doing it because every time you need some changes in your project you again need to upload the file using this file manager whenever there is a change so for example you changed one line and one file then again what you need to do you need to open this file manager go to that particular file and change the content so this method is very lengthy and complicated not actually complicated but you know you need to do the same thing again and again and that is why i post my code to github so we won't be using this file manager but we will pull the code from the get so whenever you will do some changes in your project you will push it to get and when you want to make your project live in your server you will pull all the updates from git only and this way you just need to run one command that is get pull origin master so this is how it is easy to deploy the project and that is why i added git in my project so let's do it so the first thing that we need to do is this is we need to do actually we need to create a database for our project and by clicking on this button that is mysql databases you can create a database so i will create a database named my api project you can put any name actually i will just put api project and then i will create the database so database is created now what i will do is i will assign a user to this database that we created so i have only one user if you do not have any user in your cpanel then first you need to create a user and you can create it from here only so i have already a user here and i will add this user to my database that we just created so let's add it and i will give all the privileges so let's make the changes and the user is added to the database now we will go back to cpanel and we can open phpmyadmin from here so you can simply search phpmyadmin and it is here and if you go to phpmyadmin then you can see your database that is api project so we have our database now we can pull our laravel project and to pull the laravel project from kit you need to access your server from ssh so what i will do is i will simply open my terminal now if you're using windows you can use putty or you can install the windows subsystem of linux and you can access the terminal there so i'm using a mac so i already have a terminal where i can run the ssh command directly so what i will do here is i will write ssh then my username that is s-i-m-p-l-t-o-z at and the ip of my server so it is 162 241 85 and 240 and i will hit enter now it will ask me for the password and the password is and my welcome email so i already copied the password so here i will paste it and then hit enter and now i am inside my server you can see now here i will run the command ls to see all the directories and i need to go inside public underscore html in case of shared hosting so i will go to this directory so i will write cd public and underscore html now inside this directory we will pull our project and to pull the project i will open github and we need to pull this project so i will simply copy the url the get url and here i will write the command get clone and i will paste the project repository get url and i will hit enter and it will clone the project so you can see the project is cloned to my server if you go to the file manager go to public html and here you can see we have laravel login api now i will rename the folder because it is a little bit complicated laravel hyphen login hyphen api so what i will do is i will rename the folder so i will rename laravel login api with what my api project or we can simply write my web app or you can rename it to whatever you want so i renamed the folder you can see here it is renamed now if we reload so it is my web app now now i will go inside my web app so we are inside my web app i will clear the terminal to make it more visible now we have my web app here and we are inside the same directory so if you will open my web app then here you will see a file oh it doesn't shows file without names so what i will do simply is i will rename the file that does i will show it here so we have a file that is env.example so i will rename this file to only env so again we will run the mv command mv.env.example and we will rename it to dot env only now we will open env so we will write nano enb and here we need to define some values the first thing that we will define as we will define our project url so it is simplified coding dot tech and then my web app and then public so this is our application url now we will come below and here we will define the database that we created so this is the database that we created so let's write the database name here so we have simple toc underscore api project like this so make sure the spelling is correct or else it won't work the db username again we need to give the tb username that is different in my server's case so to know the user name i can go to my sql databases and we can see the user here so we have one user that does this simple toes underscore admin so i will define the username here that is simpl then to z underscore admin and then we need to define our database password so in this case my password is bill all at the rate one two three four so you need to give your database password correct now we will exit all the configurations are done we will exit and we will save our file now we will generate our application key and to do this we will run the command php artisan key colon generate and the key is generated now we will run the command composer install to update all the dependencies and everything is installed now we need to migrate our database but before migrating the database one thing we need to do or else it will give us an error that is the specified key is too long so what i will do is i will go inside app so we will go inside app and then we will go inside provider so we have cd providers and then inside providers we have our app service provider dot php so we need to edit this file so we will write nano and app service appserviceprovider.php now inside this file we will import our schema so here we will import this thing that is illuminate support vacates and then schema and then inside our boot function we will call schema and default string length and we will set it to 190. now exit and save the file and now go back so i will write cd double dot then one more time and now i am inside my project directory now here i will run the command php artisan my create and you can see the database tables are migrated successfully and here you will see all the tables are created so this is a very good feature of laravel you do not need to manually create the databases so now we will run the command php artisan passport colon install and it will generate the api keys and you can see the client the access client and grant client is generated successfully and the encryption key was already set so we can run this command force to override the encryption key but i don't think that is needed so everything is done from the terminal side if i will go to simplified coding.tech and then my web app and then public then it should open the home page and we are getting an error that is no application encryption key has been specified so what i need to do is i need to run the command php artisan key and then generate i ran this command but i think some issue was there so you can see application key is set successfully and this time the key was set last time we didn't get this message that that's why it was not working so now the application key is set and if we reload the page we are getting our laravel home page and we can register a new user i think so let's register myself so i will register myself bilal khan email address is this and i will put any password let's say one two three four five six and then let's click on register our password must be eight characters so i will write one two three four five six seven eight and one two three four five six seven eight let's register and we are logged in and if you will go to the database then we can see the user here so it is working absolutely fine and our apis should work as well so let's try i will open postman so now if i request this hello world so let's try as you can see we are getting unauthenticated and if i request the url that is oauth and then login and if i send a post request we are getting the proper message so our apis are working absolutely fine and these apis are live in this url but it won't be live for a long time because i am not going to renew this hosting okay i only purchased this hosting for this video and i am not going to renew it so it will be expired after some time so what you need to do is you need to buy a hosting for yourself you can get the link in the description where to buy the hosting and you can buy a shared hosting and if you will buy for one year you will get the domain for free so if you want to use some other service provider you can use it but for this tutorial i used hostgator so you can buy a hosting from hostgator by going to the link that is given in the description of this video so we finally deployed our project and it is working absolutely fine and whenever we will do some changes we will commit our changes to get we will push all the codes to get then we will go to our server and we will pull all the codes but using a shared hosting has a problem i will show you so what is the problem if i open this url we will see all the files now we can easily fix it by using htaccess and you can do it just google it how to do it but still if you want to remove this public from your url then you need to contact to your hosting provider because in shared hostings we are not allowed to change the root of our hosting directly and it can be done in shared hosting but you need to contact your hosting provider and i have not contacted hostgator people because this is just a sample and i am doing it for teaching purpose only so security here is not very important but yeah this needs to be fixed there should not be a public in your url but it's fine for now and i think that's all for this video friends in case you have any problem or confusion while deploying your project to your hosting you can leave your comments below and i will try to help you out so if you like this video then please give me a thumbs up subscribe to this channel and share this video with all your friends and i will see you in the next video so thanks for watching everyone this is bilal khan now signing off bye bye [Music]
Info
Channel: Simplified Coding
Views: 19,209
Rating: undefined out of 5
Keywords: laravel restful api, deploy laravel on shared hosting, deploy laravel 7 on shared hosting, deploy laravel project, laravel shared hosting, laravel api passport, laravel oauth2
Id: X4KElZcUi-g
Channel Id: undefined
Length: 18min 12sec (1092 seconds)
Published: Tue Aug 11 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.