Deploy Laravel on VPS using ChatGPT #chatgpt

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to set up PHP working environment on Ubuntu virtual private server and install a lateral with custom domain and SSL certificates the most interesting part is that I'm going to use chat GPT and ask chat GPT to give me instructions how to do all the things if you don't know what is chat DPT that's a new generation artificial intelligence based chatbot powered by open AI which knows almost everything and answers your questions surprisingly and amazingly well there are more videos coming on this channel around chatgpt so if you're interested hit the Subscribe button and enable notifications so that don't miss any videos I already know the instructions I will need to set up everything install the working environment as well as install the project and SSL certificates but let's ask chatgpt how I can do all these things go to chat.openai.com and then you have to log in or sign up and then you will be redirected to the following page okay let's ask chargpt how to set up alarm stack on Ubuntu and insta lateral project I want to set up virtual host and install SSL certificates as well let's see what chatgpt can do and as we see it already started generating response until this generous response let me talk about today's sponsor which is hostinger we need some kind of Hosting to host our project on Virtual private server hostinger is my choice of Hosting provider I have been using customer services for about past two years even before we became Partners they provide shared hosting Cloud hosting VPS hosting their prices are really really affordable and their servers are pretty powerful let's see what churchibit is doing look at this so it generates all kind of steps what we need to do I'm really curious if we follow those steps if we can basically set up our working environment and insult Project without any errors speaking about the hostinger if you want to get started with hostinger and follow with me and set up your project in the Deploy on custom domain check the website or singer.com the code holic check their services check their prices and if you decide to take the hosting with them use the coupon code the code holic which will give you an additional 10 discount if you want to see a tutorial how to deploy lateral application on shared hosting which which has even lower price than VPS hosting then check the video which will be in the top right corner of the screen so here we have all the response from chat GPT that looks really nice everything starts with the upkit update with the sudo and then we install Apache 2 MySQL server PHP and lib apache2 mode PHP and phpmysql everything looks correct then we have to start Apache in MySQL then we configure the PHP then we set up the virtual hosts this is amazing this is exactly what I have in my head and what I basically plan to do on the server which I what I was planning to do before I say this okay that's amazing however we are not going to create new composer projects we're going to clone an existing project here's my hostinger H panel if you decide to take the hosting with the hostinger you will be when you sign up and just make a payment you will be redirected to the following age panel from here you can take your hosting manage your hosting manage your domains and everything basically you might need at the moment we're going to set up VPS so I have a VPS plane right here and let's click setup start now we're going to choose a location and we're going to choose location which is close to me and there's going to be Singapore in my case click continue right here we have a couple of options we can use an OS with a control panel or plain OS so this is for more experienced users where we need to run all the command line tools and I'm gonna we're gonna choose this select plane OS and I'm going to try to choose a different operating system I want the latest version of Ubuntu which is 22. click on select then continue at this point we're going to give the name to our virtual private server and I'm going to call the line of example.net that's going to be the server name as for the root password we're going to set something very very secure then we're going to need an SSH key if you don't know what's an SSH key you can skip that section this is an option I'm going to click save and continue and just like this I have the summary in a click finish setup okay so here is our server ready let's click manage server here's our VPS server we have the overall information we we can have a look at the server usage make snapshots and big Hops and we can even reset the operating system from this section we can get the IP address of the server from this place and if we want to access to the server and install everything and this is exactly what we want we need to use an SSH command for that I'm going to click copyright here to copy the SSH comment and I'm going to open Powershell if you are when Windows user you can use Powershell Powershell supports SSH so it's also in sh client if your Linux or Mac OS user your terminal basically will probably support SSH so we just need to type right here SSH root root is the user and we're going to connect to the following server and I'm going to hit enter right here if you are accessing this very first time it's going to probably ask you well we want to accept the fingerprint or not I'm going to type yes right here and then it will ask me the password of my server I'm going to type my password and hit the enter and now I am inside the Ubuntu Server first we have to update the server by executing sudo opt update if you install if you took the VPS server on hostinger quite probably it will already have Apache up and running we can check this by executing sudo service Apache to status and we have active and running but if you don't have if you don't see the screen active and running when to install Apache by executing sudo opt install Apache 2 and hit the enter we have to accept if it asks you yes or no and then we need to allow inside the firewall to access to the server on apache's Port so we need to execute sudo ufw Lo and inside quotes we need Apache full and hit enter if you get the following message ufw comma not found first we have to install ufw so we're going to execute sudo opt install ufw hit the enter and then we can execute sudo ufwlo Apache full and rules have been updated so now from outside we will be able to access to the server using IP because we have Apache already installed and also firewall rules are updated we can open the browser give the IP address open new tab and type the IP and we should see apache's default page now once they install PHP and let's have a look at the chat GPD what it gave us around installing installing the PHP so it gave us the following command which installs MySQL PHP and delete Apache 2 mod PHP but look at this so it only installs PHP and PHP MySQL extension it does not install anything else but quite probably your level application will need other PHP extensions such as PHP Dom or phpc URL maybe you use image processing as well and you need phpgd so we have to install those packages I'm going to now open Powershell instead of typing all these packages I'm going to copy and paste and explain right here so we're installing PHP lib Apache 2 mod PHP and the following extensions MP string GD XML CLI zip Json crl and Intel so I'm going to hit enter right here and then we have to accept this and it will install the following PHP packages now let's test if PHP is actually successfully inside I'm going to create test PHP under VAR www.html folder hit the enter and right here I'm just going to create PHP info I'm going to save this using Ctrl and O and Ctrl and X to quit basically and then let's open the server open our URL and just type test dot PHP right here okay so we have the PHP version right here which proves that we have PHP up and running now we need to install MySQL let's bring up the Powershell or any kind of SSH terminal and I'm going to type sudo opt install MySQL Dash server hit the enter while this is installing if we have a look in the chat GPD what it suggested regarding MySQL so it has actually told us the exact same thing to install the MySQL server however it did not give us instruction to install to apply MySQL secure installation which is something in my opinion very necessary to do and if we would ask like further more questions like I want MySQL secure installation or something like this it would probably give us the whole instructions what we need to do but again if I if you know what to do I think there's no need to ask to share GPT but definitely if you know how to ask it can help you it can help you a lot first I'm going to set the root password and then I'm going to run MySQL secure installation to set the root password we need to access MySQL I'm going to type sudo MySQL and hit the enter now we are inside MySQL and instead of typing the alter user I'm just gonna copy and paste the following command alter user root at log house so I want to change the following user and identified with the MySQL native password and then right here I'm going to set my password you should set your password to be something very secure but for Simplicity I'm going to set something from one to six at the moment and then I'm going to exit from here and now I'm going to run sudo MySQL secure installation now I have to enter the password for the current root user this is from one to six in my case and then it asks me if I want to validate if I want to enable my password validation plugin I'm going to set this no I don't want that now it asks me if I want to change the password for the root user I'm going to type no right here as well by default my SQL installation has an anonymous user and it asks me if I want to keep or remove it and I want to remove the anonymous user and the next question is if we want to disable remote login for the root user for security reasons this is something you must do you don't want someone else to access to your data database using root server from somewhere else so disable root logging remotely the answer is yes and the next question is if we want to remove the test database and access to that and I'm going to type yes right here as well and I guess the final question is if we want to reload privileges table right now the answer is yes again and all is done now we have MySQL installed securely on our server now I want to create database and then I can use the database in my larval application here's what I did I asked chatgpt create MySQL user create mySQL database and Grant user access to the database and it started the explanation how to connect to the MySQL how to create the user and how then then I stopped it okay just give me code no explanations and then here's what it gave me and this is amazing it understands everything where I ask and gives me the proper answers so in this case I just want to create database I don't even need to create the user and give the Privileges to the user however if you plan to install multiple websites on the same server then you should probably do it like this because root user has access to everything in one website if it's hacked it might access to something else right and in this case like creating multiple users and multiple databases uh does make sense but in our case we have only one site on our server and I'm going to just basically access to the server using root and just create one database I'm going to open Powershell and type sudo MySQL and I'm going to specify right here password as well we already have some root password and I'm in the MySQL and I'm going to run create database and let's call this lateral example this is the very basic card to create laravel example database but we can specify character set as well and I ask chargpt to create mySQL database create database with the utf-8mb4 chart set and here's what it gave me this is exactly what I wanted create database the database name and with the character set the following thing and again all the explanation as well what the character set is actually doing and how you can also create new user and Grant the Privileges I think it's amazing okay I'm just going to copy this part because I already have this create database let's copy open Powershell and I'm going to paste this right here and then hit the enter okay the database created laravel example now whenever we install laravel project we can already access to the larval example database with the root user and the root password we gave now let's clone the project and set up virtual hosts let's navigate into VAR www folder here on my GitHub repository I have the most amazing viral project actually it's the same Laurel project you can create on your own I have only one comment right here it's amazing and I'm gonna just take the https URL of this following project and go in my Powershell Angel is going to run git clone and paste this URL if you want to specify a different folder right here we can just type laravel example maybe without dish I'll win the folder without Dash so I'm going to hit enter right here oops we don't have git installed let's clear up everything and I'm going to run sudo opt install it now let's rerun git clone and here we go it cloned the project in the VAR www folder now we need to install composer the best way to install the composer is go to the getcomposer.org download and I'm going to grab the following code go in the Powershell and just paste it right here and we hit the enter it actually downloaded the composer far locally and it can be used in the following way PHP composer far but if we want to make the composer comment globally available we need to run the following comment we need to move this composer far into user local bin composer so I'm going to grab that and paste this right here and hit the enter now if I type composer I have the composer comment available however because I'm logged in with the root user composer does not actually recommend to run the composer with the root user because well actually if you have again a multiple websites deployed on the same server and you use composer with the root user you will definitely have permission issues okay but in this this case because only we have only one project and we're gonna anyway change the permissions of this folder I'm going to allow this and type yes right here okay and here's the composer available now let's navigate into the folder we just cloned laravel example and I'm going to run composer install we have to type yes and it downloaded all the dependencies of the project now we need to create dot en file and configure the connection to the database so inside the project folder we have dot en example we need to copy run CP and copy this.inf example into dot Eno now let's clear up everything and I'm going to use Nano to open this EnV and we need to find the DB place and we need to adjust right here the database as well as the username the database what we called is laravel underscore example I think this is what we called if I make a mistake I can fix that the password of the root user is from one to six now I can save this using Ctrl o Ctrl X and now let's try to apply migrations if the connection to the database is made successfully then immigrations will run otherwise they will fail PHP Artisan migrate hit the enter okay I think we missed one very important thing which was not missed by charge GPT look at this chargpt recommended to install PHP MySQL but I think we missed it I personally missed that phpmysql extension and that's why we don't have the driver to access to mySQL so we need to run sudo apt install PHP Dash MySQL and hit the enter now let's execute PHP art design migrate it tells us that the database larval example does not exist on the MySQL connection would you like to create it actually I'm going to type no because I think I have created the database I'm going to use that database let's clear up everything and try to access to the MySQL and inside MySQL I'm going to execute show databases okay so my database name is without underscore laravel example let's exit from here open.en file adjust the database name Ctrl o Ctrl X clear up and rerun PHP Artisan migrate now migrations we are successfully applied now let's apply correct group correct owner of the folder as well as the correct uh permission to the folder so that make sure that the Apache reads and writes the information from this lateral example right now if we just type ls-la we see that the root is the owner of these files and folders We need to change the owner as well as well as the permissions so I'm going to just write sudo change group CH grp Dash R which means recursively www data and the folder name in this case will be VAR www.laravelle example hit the enter now if I type ls-la I see that the group is www data let's clear up everything and now I'm going to change the permissions by executing sudo CH mode Dash r775 and then again we have to specify right here the folder name in this case we have to specify the storage folder name so I'm going to type larval example storage hit the enter so permissions on the storage have been set successfully and now we need to create virtual config file so for this let's navigate into Etc apache2 sites available folder and right here I'm going to create virtual host config file I'm going to execute sudo Nano let's call this laravel example.net dot oops Dot conf must be the extension of this configuration file so here we have this empty file and I'm going to actually copy and paste few things and modify I'm going to put the link of the following default config file in the video description and make sure it is available if you don't find that let me know in the comment section down below right here we have a server name and the server name in our case will be laravel example.net we can leave the server admin as it is it's it's dummy at the moment and let's adjust the folder of our Laurel project and that's going to be laravel example slash public we have to do the same thing under directory tag lateral example in this case we just need a laravel example and I'm going to save this using Ctrl o Ctrl X and now we need to disable the default config and it's going to be the zero zero zero config if we just just type LS La we see right here zero zero zero default config so we have to disable this by executing sudo A2 this side this side 0 0 default hit the enter and now we have to enable our config file sudo A2 inside lateral example.net.com so we have disabled the default enabled our config file and now let's make sure we have the rewrite module enabled by executing sudo A2 in mode rewrite I see the enter okay rewrite has been enabled and now the only thing is to restart Apache sudo service Apache to restart let's hit the enter now let's check in our browser what happened if we access our server using IP address we see lateral error so this means that our application is actually successfully deployed it has connection to the database but we haven't set the encryption key yet let's say that I don't know how to run this command to set the encryption key I'm going to open chatgpt I'm just going to paste the error and specify in laravel let's hit the enter and wait what it does okay here's what it gave us okay again it gives us like a very very comprehensive and overall information right here but what we just need is PHP Artisan key generate however it didn't mention that we have to specify right here date dash dash a and Si I think it's not mass but it's something we should specify so I'm going to open now Powershell and just type PHP Artisan e colon generate dash dash ANSI application key is set successfully now let's go in the browser reload the page and we see our lateral application up and running but we see this on our IP address we have not mapped it to our domain yet it's time to get the domain and connect the domain to the server if you purchase the domain with the hostinger stick with me you have to claim your domain and configure and setup and then we need to redirect it to our VPS so I have the domain on hostinger actually I'm going to claim my domain on hostinger and let me actually search for laravel example.net I want the domain so I'm going to choose.net right here and click check availability okay so this is available laravel example.net I'm going to claim this domain right here I have to provide some details about me this is necessary for the domain registration and click the Finish registration it will take a couple of minutes until your domain is activated as I see right now the status of my domain is already active in fact let me actually grab the domain and open a new tab and by paste there and as we see we have the domain already working and that shows the hostinger's default page for the domain now let's connect this domain to our server okay if you grab the domain hostinger stick with me you just need to do the exact same thing what I'm going to do if you have a domain somewhere else you need to do something similar but in your domain provider okay so here's my domain information I'm going to click this DNS in name servers I'm going to also open VPS server on a new tab right here and I'm going to grab the server IP address and I'm going to put this in the DNS so here's my VPS server learnable example.com this is the name I gave so I'm going to copy this IP address now let's go in the DNS scroll down below we're going to add a record and we're going to add cname record so a record maps to the IP address but there already exists a record which maps to a different IP and because of this a record when we type larval example.net in the browser we see this hostinger page so we're going to delete the following a record which goes on the following AP address I'm going to click delete right here and I'm going to also delete cname record which is in www.alias of laravel example.net in fact we can actually leave this but the main thing is that we need to map our domain to the different IP address so right here we have this our VPS server I'm going to grab the IP address from of my VPS server and go in the DNS and right here paste my IP address so I'm creating an A type record the name is ADD symbol and then this points to the following IP click add record this might be a valid IP address I think I have white space in front of it so I'm going to delete that and click add record DNS record created successfully now let's grab the domain and open in the browser in a new tab and have a look this still opens the hosting or default page probably this is the cache let's open in Incognito paste this and hit the enter and voila we see our low level application I'm going to check if the rewrite module Works successfully in our Apache installation for this I'm going to open my project and create one additional route I'm going to do this directly on my GitHub I'm going to go under roads web I'm going to click edit right here let's scroll down below and I'm going to add one additional road which will be for example test and that should return the exact same output we just ensure that when we access test it doesn't return not found but it actually Returns the same type of Welcome then I'm going to scroll down below ADD test wrote will be a comment message and click ok now let's open Powershell navigate into your project folder and we have to pull the latest changes and whenever basically whenever you make some changes in your repository you have to update that on your server as well right so you're going to run git pull origin main okay here are the changes inside where PHP pulled now let's open a laravel example.net when we open this we see the welcome page and now let's try to access test let's hit the enter okay we don't see not found which means our routing actually works I'm going to install node.js as well because we have to run npm run build to use divide and to build the asset files what is required by lateral go to the website nodejs.org click downloads in the menu let's scroll down below we're going to find the link to our operating system installing node.js via package manager scroll down below and I'm going to find Ubuntu right here Debian and ubuntu-based Linux distributions and click on the following link node.js binary distributions if you scroll down below we're going to find this installation instructions section and this is what we need to run but let's run the latest LTS version which is 18 point at the moment while I'm recording this tutorial so I'm going to copy this part open no more my Powershell and paste the comment and hit the enter okay node.js has been installed and we are also in the laravel example folder so we just need to run ampm in cell well actually this is a dummy project it's a like a welcome project and this project doesn't use assets but in a real project the your real project will probably use assets that's why we have to run npm install and then npm run and build and this will build assets uh using white and those assets will be used in your lateral project they are probably already used just make sure you install node.js and then run npm install and npm run build okay now we need to install SSL certificate now let's have a look at the word chat GPT gave us regarding installing SSL certificates here we have the following instructions and in fact this is actually correct so first we need to install searchbot and Python 3 search for the Apache package and then we need to run search but command with the Apache flag I'm going to grab the First Command first and let's open now Powershell and paste this right here and hit the enter that was installed now let's run sudo searchboard Apache if you're running this very first time you might need to provide right here an email address then you need to accept the terms then basically you need to choose if you want to subscribe to some kind of newsletter or not now it asks which name we would like to activate https for I'm going to hit the enter Because this means all and now it's already requesting certificate for laravel example.net and right here we see congratulations you have successfully enabled https on laravel example.net and the rest thing is to just grab copy that and open in the browser and check we have our domain under SSL certificates up and running we have rooting activated successfully if we make some changes in our repository we know how to pull those changes on the server and we also installed node.js and we run build using byte all the asset files like JavaScript and CSS files our project is perfectly deployed on VPS server with custom domain and SSL certificates anything chatgpt helped us a lot alright guys that's it for this video and thanks for watching I hope you liked the video if so hit the like button if you're interested to see more videos on this channel hit the Subscribe button and let me know in the comment section which topics you want to see on this channel if you love my content and want to support the channel check my website thecodeholic.com thanks for watching and I will see you in the next time
Info
Channel: The Codeholic
Views: 9,212
Rating: undefined out of 5
Keywords: TheCodeholic, laravel, deploy laravel, deploy laravel project, laravel on vps, deploy laravel on vps, chatgpt, chat gpt, deploy laravel with chat gpt, deploy laravel on digitalocean, lamp stack, lamp stack on Ubuntu, Deploy laravel on Ubuntu, deploy laravel on custom domain, laravel on custom domain, laravel 9, laravel 9 deploy, Laravel deployment, deploy project with chat gpt, use chat gpt to deploy laravel, chatgpt and laravel
Id: V4ZTjaFpGRg
Channel Id: undefined
Length: 29min 19sec (1759 seconds)
Published: Fri Jan 20 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.