How To Upload A PHP Website To Heroku and Setup a Remote MySQL Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this video we're going to be looking at deploying our registration application on Heroku and also setting up a remote MySQL database before I go any further I think it's worth stating that my machine actually crashed so the machine that was being used for all of the tutorials upon it at this point actually died sometime this week and so I had to recover another machine and also all of the code that was being done in the previous tutorials and thankfully github rescued me so I was able to go and get up flow in the database sorry the files back to my machine and provision a new machine with all of the code and all of the tools that were being used and so this is the new machine that we're on so if there was never a compelling reason for you to use source control then let that guide the advantages to using it now in this video we're going to be on Heroku so if you don't have an Heroku account you can always check my earlier video setting up a free Heroku account and then that should get you up to speed with getting a Haruko account and then you can follow the rest of the steps as we go along for those of you who already have a Heroku accounts this would be a return trip to your Heroku and you would notice here that there are some Z signs which indicates sleeping beside my previously deployed deployed apps and you probably have them also so the thing is when an app because we're on the free plan and app tends to go to sleep Heroku puts them to sleep because were they're free and they weren't necessarily in use so if I attempt to navigate to my PHP - primer - rev up it's going to take a while to come up and that's because it was asleep so what had to happen is the Dino itself had to really can end when i refresh the page you notice that it's no awake alright so that's going to happen if you realize that you're trying to navigate to your app and it takes a while that's because because there's limited to no traffic coming to that application all of the Dinos get kind of deep revision until they're requested and then they would awaken and serve the content all right so I'm just letting you guys know that that is why you would see those pizzettes anyhow our mission today is to deploy our new applications go to new create a new app and then we're calling this one attendance - register now remember you don't have to you can't have the same name as me and here is an example already have attendance - register as an app on Heroku so they're telling me I can't do this one so I'm going to call this one PHP - attendance I bet nobody has that name out there there we go so you can always copy this name and just put something else in there to make it unique to your situation and then once you're done with that you can go ahead and click create app now with our app created we can go ahead and scroll down to deployment method where we can just click connect the github I'm already logged into github in my browser so it's knows it's me if not then you might need to put in your github credentials and then once that is done and you're connected you can just go ahead and search for the repo and I believe that my repo was called attendance I'll search and there we go and then I'll connect and then once I connect I no have the option to automatically deploy or manually deploy someone to choose manual deployment and I think I explained the reasons for that in a previous video and so I go ahead and click deploy branch and then give it a few moments while it runs it's magic and once that is done we will see something coming up deploy to Heroku with a green tick and then I can go ahead and click view which will then load my page but then look at this if you do recall our index page should have a form and our view attendee should have a table of all the persons who have filled out that form neither is loading and the reason for that is if we go back to our code in Visual Studio if we look at our index page we see that it is calling Khan and if we look inside of our Khan file Khan is actually trying to connect to our local host database on our machine well this IP really means local to whatever machine it's on so that means if I put it on your machine and you didn't have this database then it would have been an error so likewise there is no database local to Heroku that houses any of the connection details being outlined here so what we need to do is set up a database that Heroku can see across the internet and can quell these problems so Heroku actually allows you to add a database a database server of sorts you can go to configure add-ons and look for clear DB my SQL the downsides are clear DB my SQL is that even though it says free here you have to provide your credit card information and then actually provisioning the database isn't really free the database hosting itself is not free so we're not going to take that route but instead we're going to look for an alternative and I actually found a website recently and it is remote my SQL comm and they actually offer free MySQL hosting so of course free comes with limitations but for the purpose of getting through this video and showing you how you deploy a fully functional data-driven application to the Internet and specifically Heroku then we will use it if we're doing it's a cPanel it would be a much easier ordeal but because of Heroku and the cost constraints I just want to keep this video has cost free and effective as possible of course if you were going to production then you could proceed with clear DB keep everything more homogeneous and more stable by just having everything inside Heroku so on remote MySQL comm we can go ahead and click login which of course will ask you to create an account or login so you can go ahead and fill out this basic data and create an account another tool you're probably going to want is MySQL workbench which is it's a desktop application that allows you to manage remote MySQL databases and the relevance of my using the word remote is that PHP my admin manages the local databases that are local to your zamp installation when you have workbench you can connect to that one or you can connect to one across the room or across the internet and considering that we're actually going to be setting up this remote MySQL that which is across the internet and we need a tool that can actually connect across the Internet and so MySQL workbench is a wonderful tool for that so you can go ahead and go follow this URL which is in the resources for this video and you can just navigate there and click download and have that installed on your machine so having created our remote my SQL database account what we want to do is go over to databases in this dashboard view and then well we can just navigate through all these our participants and go ahead and click create new database click OK they will then show some information so you notice both are created database the user name the database user name the database name sorry the password the server and the port so with that information we can go over to our workbench and I'm sure you've installed it by the time you get here and then we can click this plus button now I have two cards here because I had workbench installed before but if you didn't then you probably end up with one card and that's fine but then we want to create another one so we want to go to the plus sign and then we can call this one remote SQL so that's just the connection name so that when we see it we know what it is for and then the host name would be what they call the server so we see remote MySQL comm which we can just copy from the website and paste inside of workbench of course we don't want any species to come up so we can just remove any species at a space before my R and then we go back and the username is this block of text so I'm going to copy that go over and I'm going to paste that's in the username and then our password is that block of text so I'm just going to go ahead and repeat that procedure but for password we have to say store in vault give it the password click OK and and the final act would be the database name which is that name we copy that pace it default schema we can test the connection and having done that when we see this message saying successfully made MySQL connection that we know that we're actually connecting to a remote MySQL not because it's called remote MySQL but remote means it's not on your machine it's not local to you so it's on the internet and we're connecting to it successfully so I'll click OK and then click OK and then I see my remote SQL connection here I can double click it and then this will grant me access to their servers now when you're connected then you see the database to the left and you see an empty query window and then you may see this Mitchell message tables could not be fetched I'm not entirely sure why but if you refresh you see that it remains connected and they try to fetch and they say it can't be fetched but that's fine that's of little consequence what we're about to do now what we want to do is migrate our database so we had our database on our development machine I know we need to put it over into the production machine so what we need to do is find our database and we know that we built it using my sorry PHP myadmin so we go ahead and go to local host PHP my admin and then you will see attendee DB I remember I had to rebuild my database so I won't have the data that you guys have so when I migrated mine it's still going to be an empty database you guys are going to have your data but it's the same set of steps next we after clicking the DB we go to export this will then launch up with window asking us a bunch of stuff about templates we don't have to go through all of that we can just go ahead and click format so under the format you see SQL so we can leave that because what we want to do is export our tables and their contents to an SQL file so I can go ahead and click go and then that will actually give me an SQL file which I can open up in any editor so I went to my downloads folder by default I'm just going to right-click it and open it up in notepad plus plus because I don't want to open it up in any heavy software so once it's in notepad plus plus I can just copy it select all ctrl C to copy and then I go into workbench and in this empty query window I paste and then once I've pasted I can actually now just click the execute which is this lightning bolt looking icon here in the toolbar and then this will run a set of commands so like I said I have no data in mind so I your your query your query file that is generated is going to look a bit differently from mine but essentially the net effect should be the same and then once that has run and you only see green ticks below in that that well I have a few error files here error lines here but that's fine those are related to the fact that the tables could not be fetched but once i refresh the schema or to this right hand left hand side then I see my two tables lifted so even though it says tables could not be fetched I still get my tables and if you had contents than you would have gotten contents so that's step one now that we have replicated our database or remote my SQL server what we want to do is go back to or visual studio code and open up our con dot PHP file and actually change all these values relative to this new database so what I'm going to do is take a copy of all of this since that has all the connection data I'm going to comment out the development part and I'm going to put a notice in development connection and then I'm going to put in another comment down here and see remote it Obi's connection alright so that means whenever I'm ready to work on my local machine I can just uncomment this and comment this part and vice versa so in this situation because we want to work remotely we want to deploy it remotely I'm going to change out these values so host would be and we can just go back to remote my SQL comm and reuse these values so server is the same as host so it's remote MySQL not this IP address anymore but remotes MySQL comm database would be this block of text no longer tendance DB the user name would be that block of text and our password so note we have a password this time first we didn't have a password and I said that I would be fine for our development but for security purposes they always give us a password when we're going remote now another cool thing about this is that no that says set up a remote database and I have it here on my local development you know in my local development file I can actually collaborate even easy more easily with my colleagues because the database is no longer isolated to my machine so I did say the remote database would be on a machine that is not your computer because if all of you are working on this project then it would be hard for everybody to be able to pitch in for database changes if the database is only on your computer however if it is at a remote or central place that everybody has equal opportunity to connect to then it's easier for everybody to work with the database so by deploying your database to some remote server whether it's across the internet or maybe it's on a network where you are at your school or your workplace if it's on a networked machine there the fact is that everybody can use these connection details and have visibility on this same database the same data that everybody is seeing and work even more lystie now just to drive for my point I'm actually going to navigate to my local host application so I'm just going to go over to my browser go to local host and go to it is attendance and when this index file loads properly realize that the connections are working everything is in order you notice I don't have any area of expertise because my database is empty alright but remember that we had set up this drop-down list to actually read from the database so I need to go back into my database and refill this table with the different areas of expertise that are available for selection and then we'd see them but the point is now we're connecting to our database if I view attendees there is nothing there but that's because once again my database is empty if you did this and you have you migrated all of your data and all of the objects then you're going to be having an entirely different experience from me and you will be seeing all of your attendees so I'm quickly going to quickly just put in all of the specialties so workbench allows me to just click on the table and you know this icon that launches a select query from the database and then they give me an editor so I'm going to put in web administrator and database administrator and I'm sorry I'm not remembering the other ones so I'm just going to put networking engineer and I believe the other one was other know that I've entered all of those values I can just go ahead and click apply to the lower right corner and that would actually generate an insert into statement per value which I can click apply and that gets executed and all of these I know in my specialty's tables so when I go back to my form and I refresh and it connects to this database then you will see that all of what I just put in including the new one networking engineer all of them are now being put so it is successfully connecting from my local host to the remote server that we just set up and so expectation is that once I deployed this to Heroku it will be looking at the same database that I just set up in my local development so we're going to go ahead and redeploy so I'm going to go to github and I'm going to push the changes and hear all the changes get to be showing us all of the changes that we just made in our con file so I'm going to come into masa and I'm going to see added remote MySQL connection details and then I'm going to commit that to master and then push and once that push has been deemed successful I can go back to my app in Heroku go to overview no sorry deploy my bad and then go ahead and deploy branch once that branch is deployed successfully then I will click view and the expectation is that our farm loads and we can see that a query is being done successfully and I'm going to put in the first attendee so this is my actual up here on the internet so this would have been you know presented to the user for the first registrant so I'm going to register first for my IT conference and my date of birth is actually the 28th but then the year is wrong well we leave the year and then I am a web administrator more or less my email address is indeed that and my contact number is not fully accurate but we'll work with that and then I click Submit and then we are seeing that the operation has been completed and those are my details if I go to view attendees and we remember that we did a select query to get back these details so it's reading directly from my database and if I go back to workbench just to verify if I look in the attendee table and I click this icon here that will launch all the data in there and the Select query then I see that my application is really talking to my remote database somewhere in the internet and that is how you would go about deploying an application two or more database and to Heroku now once again it is ideal in real production situation that we keep everything inside of Heroku it's easier to maintain it's easy to manage and it's easier to well everything does connects better but then we see here that we're hosting in Heroku hosting our code in Heroku both hosting our database on remote MySQL comm and this concept could have been applied basically with any remote hosting agency so everything doesn't have to be one place the database can be one place and the code another place but we know how to connect them once we have the correct connection details all right so I am challenging you just repeat these steps deploy your application and if you run into any difficulty along the way feel free to let me know and I'll be glad to help thanks for watching
Info
Channel: Trevoir Williams
Views: 18,060
Rating: undefined out of 5
Keywords: jamaica, php, development, package management, web, programming, xampp, wamp, server, open source, git, github, source control, community, free, hosting, mysql, apache, perl, pdo, bootstrap, edit, dynamic, heroku, How To
Id: I4Ra-80O3R4
Channel Id: undefined
Length: 20min 39sec (1239 seconds)
Published: Sat Oct 12 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.