Setup a Raspberry Pi Web Server with Your Own .COM Using Google Domains

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone in this video I'm going to show how to set up a web server with a raspberry pi I happen to be using an older Raspberry Pi but that's just because I have a bunch of full-size SD cards around but it's exactly the same for the newer Raspberry Pi 3 or the 2 or any other version really in this video I'm going to cover how to set up obviously Linux Apache MySQL PHP we're going to use SSH to get access to the raspberry pi I'm also going to show how to set up your own domain name like your own comm and how to connect that to your Raspberry Pi and also how to use a dynamic DNS service which will let you use your Raspberry Pi on a typical residential internet connection where you don't have a static IP right is a similar video before but it didn't cover the domain name part or the dynamic DNS part so that's why I'm making this video again anyway so gather all your stuff you're going to need a Raspberry Pi a SD or micro SD card micro USB cable and a Ethernet cable we'll start by taking the SD card or micro SD to your normal computer not the Raspberry Pi but your your desktop or laptop and we'll set up the card ok so back at the computer I'm going to go ahead and connect or plug in my SD card and windows detected it so drive letter e ok so if you bring up a web browser search for Raspberry Pi downloads and click the first link we want raspbian and we want the minimal image all right so it's almost done downloading in case you're wondering why I went with the minimal image instead of the full desktop image because I'm going to use the Raspberry Pi only as a webserver we really don't need a graphical user interface and it'll just be more programs that need to be updated and could slow things down a little bit so that's why I'm with minimal you can do it with the full desktop version if you want that'll work just fine as well all right the file finished downloading we'll go ahead and open it and it looks like that would be disk image okay so we want to copy that and save it here so basically that was a zip file we're extracting the zip file I'm putting it in my downloads folder you can put it wherever you want okay so we have raspbian ready to go we need to we need to find a way to put it on the SD card so if you go to installation guide go down to windows click on the SourceForge link and then click on the download link open the file except create a desktop icon and go ahead and launch it so I've noticed that this happens sometimes you'll get an error and it will say that the requested operation requires elevation what that means is you need to run it as administrator so if we go to the desktop icon right click it run as administrator and then the error goes away so you need to tell it where your image is so you click on the folder icon and I save mine in my downloads folder but wherever you put it find it and then you need to tell it the drive letter of your SD card and if you go to file explorer this pc online it happens to be drive letter e on yours obviously it'll be different or it could be different so I'll pick drive letter E and then click write and confirm and I'm using a very old very slow SD card so this in take a while all right so it finished right into the SD card click OK click exit and we can go ahead and eject the card and now we'll go ahead and take the card back to the Raspberry Pi so we got the card that's all set up go ahead and plug it in plug in your Ethernet cable the other end is already plugged into the back of my router and plug in your microSD cable for power C the lights come on and now we'll go back to the PC and configure everything through the network so we don't have to plug in a monitor or a keyboard or a mouse okay so back at our regular computer what we need to do now is we need to figure a pin there there we go okay we need to figure out the IP address of the Raspberry Pi an IP address is like a telephone number for a computer and the way you can figure that out is by login into your router typically that'll be 192 192.168.1.1 okay so I've logged into my router yours is probably going to be different because it'll the interface will be different for different brands different model numbers that's the model number I have so you might need to do some research to figure out how to make it work with your particular router but on mine if we go to clients and we go to wired we have 192.168.1 the reason why it has that host name is because I've actually used this Raspberry Pi before and it knows by the MAC address the old host name but it'll probably say Raspberry Pi so on my particular network with my particular Raspberry Pi it defaulted to 192.168.1.2 to 1 again it it'll most likely be different on your network and if you don't have this particular brand of router what you can do is figure out the model number of your router and search for that model number and then how to set a static IP so on mine if you click the computer icon next to the device you can click a padlock icon and that will lock that IP address to this device and you click OK alright and so then the router will reload its a page but we're all done with that for now now we need a way to talk to that Raspberry Pi and secure shell ssh is the way to do that it's a encrypted command-line interface to a linux computer and the program I use in Windows to do that it's called teraterm so te RA te RM and click on the first link and click on download and we want the newest version which is 4.90 we want the Exe and there it is downloading go ahead and open the file I guess I didn't open the file um all right go to downloads open the file all right so accept all the defaults should be fine yeah that's fine pick whatever language you want and we'll go ahead and launch teraterm okay so when it opens up you'll see it looks like a daus window behind it and then a little pop-up window they'll let you tell it what you want to do so make sure SSH secure shell is selected the default port number of 22 is fine all these are fine the host will be that IP address I think it was two to one oh that's why I didn't pop up earlier okay what was the IP address two to one yeah so again on yours it'll probably be different but on mine it's 1 9 2 1 6 8 1 2 2 1 so you type in whatever you are IP addresses type it in here click OK and it will say well okay it'll the first time you connect it will bring up this confirmation and click continue and then let's say authorization or authentication required username by default is PI P I all lowercase and the password by default is raspberry all lowercase and click OK and there we go so this is basically a view into the Raspberry Pi this window is your raspberry pi we're logged in user name is PI the device name is raspberry pi and what we can do now is we want to run the rads PI config program as the administrator so sudo su do is Super User do which means run it as administrator and then R as pi dash config is the name of the program press Enter all right so the first option expand file system we want to do that that'll make it so that your partition will take up your entire SD card which is what you want so press ENTER and it'll tell you that it has resized and that it will go into effect after the next reboot so okay change user password you probably want to do that so press Enter you'll be asked for new password press Enter so enter your new UNIX password obviously want to pick something that's kind of a secret but for this demo I'm just going to pick a password of password so don't do that but password for now press Center type in your password again and it will tell you that it has changed it go down to Boot Options and we want be one console basically the other ones would be for a typical like desktop computer but for a server you really don't need any of that stuff running in the background so b1 is fine press Enter internationalization options we can change the locale and we'll scroll down by default it'll have en-gb which is the version of English used in Great Britain and I happen to be in the US so I'm going to switch it to en-us so the star indicates that it has been selected and you can unselect it by pressing space and we'll go down to en-us utf-8 and press space and then tab and that'll bring it about a movie over to okay press Enter and pick en-us utf-8 press Enter alright go back again to internationalization options pick your time zone and I happen to be in California so I'm going to go to USC it was specific I don't remember let me go back oh okay go to America not us go to America and then I'm going to go down to Los Angeles alright everything else is fine we don't need to change anything else so if you use the right arrow you can go to finish and it will say would you like to reboot and yes we do because we want that expanded file system to go into effect so press ENTER and in a second teraterm will close that's what happens if it loses a connection so if you ever are doing something and all of a sudden the window closes you lost your network connection anyway so we're going to go and wait a couple minutes for it to finish starting back up and then we'll open tear a term and connect again go ahead and open up terror term again and again make sure you use your IP address for the raspberry pi and username is going to be PI the password will now be whatever you set earlier so again I used password which is a bad choice but it's only for this demo and then click OK and again we have our connection to the Raspberry Pi so we want to do now is download all the updates so that we have a reasonably secure system sudo apt-get update so again sudo is Super User do which means run this as an administrator apt-get is the tool that will let you interface with the package manager it's a kind of like the app store if you want for Linux kind of and then update tells it to get a list of all the updates so press Enter okay and now and install all of the updates that it might have found so sudo apt-get upgrade so update will get the list of updates an upgrade will actually apply those changes and so it will give us a list of lunch packages that it has found updates for and that's in my case that has been 32 updates and it'll be a download almost 30 or almost 24 megabytes and it's asking us to continue yes or no press enter to yes or to choose yes just press enter you so we have all those it's installed now we can actually go about installing the webserver okay so like before as an administrator we want to install apache2 PHP 5 and then the server and client for MySQL which is a database and we see there is a whole bunch of packages that will be installed and again we are asked to power to confirm and press ENTER ok so it's going to ask you to create a password for the MySQL root user MySQL again is the database program which I will not be showing how to use in this particular video but I plan to in future videos and when you connect to MySQL you use a username and password and the root user is is the administrator it's the one that has all the power so give it a reasonably secure password again for this demo I'm just going to choose a password of password but pick something a little better than that and type it in again and then the rest of the packages will continue to install all right so we've finished stalling the web server and related packages let's verify there it is actually running so on the not on the Raspberry Pi not here but on your actual normal computer go back to your web browser and type in the IP address of your Raspberry Pi so again mine happens to be 1 9 2 1 6 8 1 2 2 1 but yours will probably be different so don't just blindly type that in make sure you use the correct one anyway and so you can see here yeah it works this is the default page and then there is some kind of basic guides right here that explain things okay but that's great now we want to put our web pages here now I mean you could do it all through the command line but that'll get really annoying really quick um there's a program called swish s WI SH and it'll ok on swish SFTP and then it will let you kind of see your Raspberry Pi hard drive from within windows and so we'll download it click download and open the file and accept and finish so now if we go to file explorer and go to this PC we see there is a switch device or drive in this area double-click on it and up here click Add SFTP connection we'll give it a label I'm going to call it web server the host would be the IP address of your Raspberry Pi again type in the one for your Raspberry Pi not just what I typed in user name is going to be PI and the path will be slash home slash PI which is the it's the home directory of a user in Linux which is kind of like like where documents would be click create and so we have a option here and if you double click on it the first time you connect it will tell you that it has identified itself with a host key that it has not seen before and so you want to tell that you trust that key to store it and go ahead and connect and then we'll ask for the password which is the password for the user pi so again in this demo my password was password but type in your password and then we see that the folder is empty and if we go up okay check for updates fine let's see is the folder empty oh it is okay good for a second I thought we had a promulgate so um LS is the Linux equivalent of dir for das which will list all the files in a directory and there's nothing there what we need to do is we need to create a link in that home directory to where the webpage is restored and they happen to be stored in VAR w w HTML and that index.html is this so we want to replace this eventually so what we want to do is well first of all let's make it so that the user PI has full read and write access to that directory which means you don't need to login as an administrator when you want to copy over files and you can do CH own which is change owner the new owner is the username PI and then the path and oh you need to do sudo first because you need to you need to be the administrator to change owners and oh in case you're not aware I'm using the up arrow key to bring up the previous command you can you can use up and down to to look through your history and now we'll do a similar command but chgrp is change group which is another part of Linux missions okay so now the user PI has control over that directory and we're going to create a link to that directory in the users home directory so Ln - s which is make a link and ask this for symbolic which is the type of link which is the kind you're probably thinking of it's just a regular link and then the source which is a VAR w w HTML and then the destination which will be home PI and yeah we'll call it HTML all right so now if we go back to windows if we refresh we see we have that folder so and there's this is the webpage that we saw in chrome now let's go ahead and delete that and if we go back to Chrome if we refresh the page you'll see everything's gone because well everything's gone if you just want a web server that'll host you know random files you can drag and drop them over so if we go back to the web browser and we refresh we'll see we now have that file and if you click on it it will load the file in case you're wondering this is just a photo of the inside of a calculator a old version of the ti-83 plus but anyway that's irrelevant okay um we could delete that and let's create a really simple web page so on your on your desktop right click go to new text document and call it in stop HTML and I wonder if I think we in Windows we need to show the file extensions because I think that's index.html and there's a hidden dot txt um I believe yeah okay so if you go to your final explorer go to organize go to change folder and search options go to view and then uncheck hide extensions yeah so that's the problem that I was hinting after it's the dot txt we need to remove that so we're gonna go ahead and rename and click yes okay so that's what we need because Apache it's going to look for a index.html file it is not going to look for an index.html txt anyway so now we have an empty text file and we want to open it with notepad so right click open with choose another app and more apps notepad and check always use the app ok so I'll make a really simple really crude web page okay so really really simple again we're just going to show a string of text in the web browser hello from my Raspberry Pi file save and go ahead and drag it over alright so now if we go back to our web browser and we refresh great so we have confirmed that we do have a web server it's running and it's serving what we want it to serve okay but right now you can only access your server from within your own personal Network it is not accessible on the Internet there's a couple things we need to do now so that people on the internet can see your raspberry pi the first thing we should do is tell our router that if it ever receives a request for a webpage that it should pass it on to the Raspberry Pi and you do that with a I guess technology called port forwarding and I'll go ahead and log back into my router alright so again this part will vary depending on which model of router you have so you'll need to do some research if you have a different model just search for your model number and then port forwarding so on my particular router if you go to when W a n which is wide area network and you go to virtual server port 40 so it'll kind of explain it in these in this paragraph what you do is enable port forward it needs to be yes and then down here we we set it up so a service name can be whatever you want to call it I'm going to call it web server and port range will be 18 so well okay it's not sure I'm knowing it you know there's HTTP colon slash slash HTTP is by default port 80 so that's why it's port 80 and then your local IP will be the Raspberry Pi which review for me 192 168 1 2 2 1 again that'll be different for you so pick the correct IP and the local port will also be port 80 and the protocol is TCP and then you click Add all right so just to reiterate we give it a name this does not even matter you can call it whatever you want on the internet if somebody makes your request to port 80 using the TCP protocol our router is going to connect that request to the Raspberry Pi on its port 80 and of course that will be with the TCP protocol so click apply ok great so right now if somebody wanted to access my server they would need to know my IP address which would not be this one but it'd be my public IP address and there's a couple problems of that one is it'd be a lot more convenient if you had a.com or.net or whatever your own domain name and to the majority of residential connections residential internet connections have a dynamic IP and what that means is your IP address changes over time usually it's not very often maybe once a week once a month but but it can change so what we need to do is why did I did Chrome close ok that's weird whatever if you don't have a domain name you can buy one and I'll show you how to do that so domains Don google.com so there's many they call them registrar's but there's many registrar's and one of them is dum domains google.com and they charge about twelve dollars a year and it's really simple and straightforward you know it's Google they keep things you know fairly easy to understand and I'll log in to my account and show you how that works so if you don't have a domain you could you could go here and then you just follow the step so you can buy your own calm but I already have them a few of them so I'm going to go to manage my domains and I'll go ahead and login so after you buy a domain it'll be listed here and what you can do is for the domain that you want to set it up with which for this demo is going to be CG artwork calm if you go over to DNS and click on that and make sure that you're using Google's domain name servers scroll down to synthetic records choose dynamic DNS and ww4 the yeah WWE GRE comm and then you click Add and then hidden here you need to click this arrow and I'll go to view credentials so before anyone mentions yes I know I just showed you the username and password for that particular DNS configuration thing but before I even edit this video I'm going to reset that if you click need help setting this up I'm going to open that up in a new tab so they explain it all here and it's good to read through it but basically they show you how to do it with a DD client and this one that I've never heard of before I've used DD client before but I've had issues with it and to be honest it might have been my fault I don't know but I I'd rather just do something more simple and if you go down to here click on using the API the easiest thing you can do is if you access this web page from anywhere on your home network in this case I'll have the raspberry pie access that Google will know that this is your current IP address and it will update its records and so you replace user name and password with the credentials that are right here and you replace sub-domain yourdomain.com with your domain so in my example that'll be WWC gr were calm but again I'll be different for you so if you try to use that you'll get an error so keep that in mind whatever domain name you buy that's the one you put here www whatever your domain is calm and then they list here the and by IP equals in but you don't need to put that that's optional they also tell you down here it's optional anyway so what we can do is we'll go back to the raspberry pi I'm going to go ahead and create a script which is really just one line but it'll be a shell script that will query that web page so Nano which is a very small basic text editor for Linux and then the file name I guess I could call it DNS update script dot sh-sh is the extension for a shell script press enter all right so we're now in our text editor and we can create this file and then save it and a program in Linux for downloading a file is W get and we're not actually downloading much of anything from them but they will respond with I don't know ten or twenty characters to let you know if it succeeded or not so you're basically doing it download and then let's copy and paste this so that we don't have to type it all in so I copied that if we go back to teraterm there is a neat little shortcut don't do ctrl V it it isn't going to work it'll it'll do that it'll go down one line if you right-click with your mouse it will paste and it's kind of gone off the screen let's make that a bit wider okay there we go so now we need to edit this line we need to replace user name with the username which will be this one and copy that right click to paste and change the password copy that right click to paste and then change this last part so again for this demo it's WWC GRE comm but that isn't going to work for you so make sure you put in your domain name all right so that will attempt to download that file what we want to do is we want to save that to a text file and there is an option which is a do a hyphen and then a capital o not zero but a capital o for output and then we can tell it what file you want to save that adds I'm going to call it DNS update results dot txt and then we'll create actually will be a two line script the last line I'm going to append the current date and time to that file and I'll show you why at the end don't worry okay so that's the entire script let me review what we're doing again so we're calling the W get command which will let you download a file from the internet in this case the file is really just a web page the web pages address is this long string of text and the first part is the username and then we have a colon password then at domains google.com slash nick / update question mark host may host name equals and then your domain so make sure you put your domain not not this one all right and then - capital oh not zero but capital oh four output we specify where we want that file to be saved to so I'm choosing the name DNS update results dot txt you can call it whatever you want after it executes stat command the echo command down here is going to append a line of text to the end of that file and it'll say last run and then date is a program in Linux and it will print out the current date and time these weird-looking quotes right here those are not single quotes they are I think they're called a back tick it's the key to the left of the one on your keyboard so if you look at the number one you go to the left or if you look at your tab key go up one it'll be that weird kind of diagonal quote I think it's an accent in some languages but anyway that's what Linux uses to say you know execute this command but then in place of date run date and then whatever it does put it here and I'll show you what this does so we want to save the file and if we look down here it'll say control o that symbol means control so control o for right out so control o and it will say file name - right and that's what we want so press ENTER and we can exit it'll tell you down here control X for exit so control X alright so if we list the contents of the directory again with LS we have that link to our web page directory and then we have our script now I'm going to go ahead and the script right now so we can see what it does if you do dot slash DNS and oh I almost forgot because it's a script it's basically an executable file and you need to adjust the file permissions to make that file executable so chmod is change I think modification Joe plus X is add executable permissions and then the file name press ENTER and now we can do dot slash DNS I'm pressing tab by the way tab will autocomplete a file name alright so it it did that and then we see here that it hopefully saved it to our text file you can use the program cap which is short for concatenate a really interesting name but um it'll basically show you the contents of that file so cat DNS update results dot txt press Enter we can see here Google responded with good and then my public IP address and then this is the part that second line last run and then this was the this is what date printed out and it printed it in the file so basically we have our status here whether or not updating our DNS record succeeded or failed and then we have the date and time here so that we can if we look at this file we know you know hey was this run like an hour ago a year ago you know what happened and again this will be visible in Windows so if we go back to swish and to the web server we have it here so if you ever won I look and make sure that you're updating Google this is how you do it okay but we want to execute this script periodically because your IP address can change it'd be a good idea to run the script once an hour um your IP so we're not going to change nearly that fast but once an hour it's probably a good option it isn't too frequent that you're going to be annoying Google and it'll still update your records pretty quickly if your IP changes in linux there is a chrome tab which is a chronological it's a a program that will run things on a chronological basis so if you type in crontab - II which is edit the first time you run this program it will ask you to pick a text editor and I want to use Nano because it's simple and so right here we have two bin Nano so type in the number two press Enter okay so we have this text file this is going to configure the chrome tab and you go ahead read these paragraphs but I'm going to go ahead and scroll down and get right to it so how it works well here I'll just go ahead and do it first okay so first of all you probably wondering what these mean and they kind of hint at it over here your base come on I think my computer is freaking out because I have it running in a VM and my computer is getting kind of hot with the screen recording software and everything anyway okay so the first value is the minute and what I want is I want to run this at the start of every hour so basically on the on the zeroth minute on me on the first minute and then H is per hour so I'm the zeroth minute of any hour any day of month do M is day of month any month any day of week did I put too many IP let's see minute hour day of month month day but yeah okay so I put I have an extra star okay there we go zero minutes of any hour of any day of the month of any month of any day of the week and then the command is our script file home PI DNS update script so basically at you know like it twelve o'clock or one o'clock or two o'clock every every time your minute is it zero for any any any other any hour it'll run that script anyway so again we control zero to write that file press ENTER and then control X to exit the text editor and you'll see here that it installed the new crontab so right now it's 154 and in about 6 minutes it should run that program and if we check the contents of this file it should it'll probably say something like no update or whatever the abbreviation for that is and then it should say here it should say 0 to 0 0 0 0 and if you're curious about what all of the possible responses are they're down here so we had good oh this is what I meant earlier so no chg no change we'll probably see that when it runs in about 5 minutes because my IP is probably not going to change in the time and then there's all these possible errors but yeah general you're going to see they're good or no change alright so in theory everything works now and we'll give it a shot I don't know how quickly the because I just created this dynamic DNS option I don't how quickly that's going to work but let's go ahead and give it a shot so I'm going to create a new tab and if you remember correctly my domain name for this demo is CG artwork calm and let's see if it works your name not resolved ok so yeah the DNS system has not been updated quite yet it'll probably take a little while I'm going to go ahead and pause this video and maybe in about half an hour or an hour I'll try it again and all I'll show you what happens okay well actually just right after I pause this video it it worked so I'll create a new tab and we'll go there again and there you can see it works and this will work from anywhere on the internet um come on wide it's quite as Chrome keep crashing that's really annoying okay so that'll works many we're on the Internet not just my home network www CGR comm and that is actually in real life serving it from my Raspberry Pi and you so basically that's all this video is I hope you enjoy it to summarize we got a Raspberry Pi we prepared an SD card we setup raspbian on it after we set up raspbian we went ahead and downloaded all of the updates after that we installed a patchy PHP and MySQL after that we set up swish in Windows so that we can access the raspberry PI's hard drive from within windows and then I showed you how to well I kind of painted out how to buy a.com through Google domains and I show you how to set up one that I'd already bought with dynamic DNS service that Google provides at no additional charge and that's that's really all there is to it it's very simple I know it's kind of a long video but I was trying to explain things as I went I hope you enjoyed the video if you have any questions or comments please leave them down below if you like the video please share with anybody that that might benefit from it if I have time I've been kind of short on time recently but if I have time I plan to do a bunch more videos on how to have an Arduino talk to the Raspberry Pi and also how to set up a VPN server with the Raspberry Pi which can be a really helpful tool if you ever have to travel that's the end of the video I hope you enjoyed it
Info
Channel: upgrdman
Views: 1,214,847
Rating: undefined out of 5
Keywords: Raspberry Pi, Web Server, Apache, PHP, MySQL, SQL, Google Domains, Dynamic DNS, Dynamic IP, TeraTerm, Swish SFTP, SFTP, SSH, Raspbian, Windows 10, Ethernet
Id: vzojwG7OB7c
Channel Id: undefined
Length: 55min 44sec (3344 seconds)
Published: Sun May 01 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.