Deploying PHP websites on Heroku | Chris Worfolk | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Deploying PHP websites on Heroku

teacher avatar Chris Worfolk

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

35 Lessons (1h 15m)
    • 1. Introduction

      0:38
    • 2. What is Heroku?

      5:44
    • 3. Example code

      1:00
    • 4. Creating a Heroku account

      1:02
    • 5. Installing the CLI

      1:27
    • 6. Installing Git on Windows

      5:52
    • 7. Installing Heroku CLI on Windows

      1:03
    • 8. Using Git Bash on Windows

      0:42
    • 9. Creating a simple app

      2:37
    • 10. Adding PHP code

      1:22
    • 11. Creating a Procfile

      1:25
    • 12. Committing to git

      1:49
    • 13. Pushing to Heroku

      3:20
    • 14. What are config vars?

      2:44
    • 15. Adding a local config var

      3:01
    • 16. Using variables locally

      1:06
    • 17. Deploying our changes

      1:39
    • 18. Using variables in production

      2:33
    • 19. What are addons?

      2:33
    • 20. Using addons

      3:00
    • 21. Addon dashboards

      0:58
    • 22. Adding the variable locally

      1:59
    • 23. Connecting to MySQL

      3:01
    • 24. MySQL in the cloud

      1:08
    • 25. Breaking the app

      2:41
    • 26. Finding out what went wrong

      1:03
    • 27. Rolling back

      0:52
    • 28. Provisioning Rollbar

      2:37
    • 29. Installing the client library

      2:27
    • 30. Rollbar dashboard

      1:18
    • 31. Configuring domain names

      3:27
    • 32. Configuring Apache's web root

      2:57
    • 33. Enabling PHP extensions

      3:36
    • 34. Switching to nginx

      2:21
    • 35. Conclusion

      0:18
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

50

Students

--

Projects

About This Class

1843112d

In this course, you will deploy your first website to Heroku's cloud platform. Heroku is a Platform-as-a-Service (PaaS) that allows you to easily deploy and scale web applications using a simple git push. You'll follow me step-by-step as we go through the process of:

  • Deploy your first web application to the cloud
  • Use add-ons such as MySQL databases and performance tracking
  • Troubleshoot errors using the Heroku CLI
  • Configure and customise your virtual server

Meet Your Teacher

Chris Worfolk is a psychologist and software consultant. He is the author of How To Exit VIM and Do More, Worry Less.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction: his Grace and welcome to this skill share class on using PHP in the Roku Cloud. It was part of the class hours part your project. We're going Teoh, create a basic Web application, and then we're going to gradually build it up with more features like being in contact vase resources, Some of the more advanced features on Arocha. I've been a software consultant for over 10 years now, looking forward to sharing all of this knowledge Review will start with a quick introduction to the road. Could black form in case you know of it, and then we'll dive straight into write code, so let's get started. 2. What is Heroku?: just before we dive in. I think we should quickly just go over what is her Roku. You might be familiar with it already, in which case you'll skip this lesson, but I think it provides a good overview just to make sure we're all on the same level in terms of what we know about Hirooka. So it's a hosting in the cloud, essentially alright, platform as a service. That means that instead of us having to manage the server and configure everything Hiroko does, the old forwards or we do is push the code up to it hand. It magically works, and it does feel like magic a lot of the time, and it's built on top of AWS. Not particular important, but it is interesting that this whole entire companies just built on the novel aggravated with us. How does it work? Well, absolutely on what's called Dino's, which is that's hurricanes word for it but basic in the adjuncts containers. So if you've done anything with Doctor, it's not the same, but it's kind of similar, Andi. So as developers, we store all our code in and get repo on. We were when we want to do a deployment. All we do is we do a get push on. We push it up to Hiroko on it deploys Andi Hiroko really does do everything. After that, you write your code, you push it up and you're done. The few things you need in your get repost such a crock file, and we'll talk about that in the course on. Also, you wanna make sure that your composer file is have certain for you things in again. We'll cover that on the course, But those two files essentially do everything, and everything is composed, controlled via the composer dot Jason file. So hopefully using composer, because we will need it. Andi, you also easily scale your application. So if you've got bigger one, you can scale it across multiple Dino's or you can have bigger. Dino's is a lot of options scaling, So advantages for the main one is Roku manages all the infrastructure, so you don't have to do all the provisioning and maintaining of service. Andi. Things like if you want to upgrade your version of PHP, then Egypt specified different version of the PHP in a conflict file, and you push it up to Roku and Hiroko just changes. Provision a new container with the update Very frumpy, a tree on distant feed if we leave it to scale because it's in the cloud. And in fact, you can even auto scale to based on loads over here after performances dipping you can get it to scale automatically on. It's really easy to do deployments because it's just get push on. It's really easy to do rollbacks as well. So if something goes wrong, you can roll back really fast. I think it's fair that we cover the disadvantages of Broca's Well, one is Thea ephemeral file system. So every time you actually start, such as you do it deployment or dates from the conflict, everything gets wiped and goes back to starts. You can't use it to save files, so normally you know you might save up loads or logs or anything like that. All that needs to go to an external service, so put you in your log somewhere else, putting your uploads maybe in s free or something like that. You can't have them on the heroic a file system because it just gets destroyed on a regular basis. It relies on heroic you supporting your platform. What I mean by this is obviously it's a PHP costs thank you probably appeared to be on, and we could do support that. But things like PHP extensions heroically needs to have them in order for you to be able to use them. And if it doesn't, if you've got any custom extensions, there's air not going to be available. The other thing, I would say, is that Hiroko premium support is really expensive. We're talking $1000 a month, which, compared to you, can pay $100. Probably last Teoh get a really good virtual seven from from like power VPs or servant on that comes with phenomenal support. You can phone them up, you can email them, they're on it within minutes. Hiroko, unless you pay for the really premium stuff, you pay for the really premium stuff and it's still like a one hour response on on the non premium version, which ah lot of you were gonna be on if you're not a business throwing some cash in this than it's like a one working day response. Now have hard one outage on her Roku on. They got to it in pretty quick. It was a system wide issue and it was fixed within about half an hour. Maybe, but you don't have that level of premium support that you would get from some hosting companies unless you really willing to pay. But in general, it's been a really reliable platform for me. That one outages e only when we've had so in summary. Developers really love her. Okay? And I'm sure you will, too, when you dive into it, because it just makes our lives so much easier on businesses. Love it as well, because it's very cost effective. You don't have to have a massive server farm and a team of engineers to maintain them so you can move your infrastructure over to Roku and decommission or service on. Get your team of engineers working on something more interesting than just constantly upgrading her vision of Web server. So I think that covers what we need to know. Let's just dive in now and write some goed 3. Example code: Hey, guys, just a quick word on where you can get the example code from everything we're doing here, so you don't follow along with the videos. But if anything goes wrong, you want to check your code against code I'm writing. You can get it. Form the my Get Hub Repo. Just get hope dot com slash x m e l t r UT slash hero Cooper appeared to be a bit of a mouthful to remember, but I will link to this in the resources so that you can grab it really easily on each one of the lessons generally has a folder there. Pretty, I hope they're intuitively named said that it's not necessarily tied to a module because some modules have several different lessons in them. But hopefully you can figure it out on in the E. T. C folder there some help with the Apache conflict as well. So check now that if you've got any problems, just reach out on the course is Q and A board, and I'll do my best to help 4. Creating a Heroku account: Let's get started building our first hero coup application. To do that, we're gonna need a Hiroko account. So if you visit Hiroko dot com aunt, click on Sign Up, you can sign up. It's totally free to sign up, and you don't even need to put your credit card details in. That said, you might want to put your credit card details in because by default you get 500 hours of their basic app free. We have just a standard account when you input your credit card details. That goes up to 1000 hours to get twice as much free stuff for having your credit card details in there. But it's not necessary if you don't want to. It's a pretty straightforward form, said Jets. Hit Sign Up for, like this form hit. Create free account. That might be an email verification to do. But if you go for that, get your hair oco accounts up and then we'll continue in the next lesson. 5. Installing the CLI: so by this point, hopefully you've got your Hirko counts up on you being able to access it. Andi, you should get something like the heroic a dashboard like I've got in front of me. But you won't have any APS yet if you just create it such great. That's step one over thing. We need to get up one morning with her. Hoku is the Roku cli toolkit on the easiest way to find this is just Google it. Hiroko Seelye. Andi, What this will do is install the command line tools. So when we go over to the command line, I can run her Roku command. Easiest way to install if you have a Mac is to just grab this installer, save it somewhere and run it. You can also do via homebrew if you use homebrew or if you've got Windows machine grab. You probably want a 64 bit installer. If you've got a reasonably modern machine on again, plenty of options if you're running a linear system as well. So I will leave this stuff up to you because it will depend on your specific system, how it's gonna work. But if you have any questions, juts Any problems just reach out via the Q and A board on the course, and I'll do my best to help but get the command line tools installed on. That's all of a sudden we need and we can move on to actually creating our first Roku app. 6. Installing Git on Windows: Hey, guys, I just wanted to throw in this additional lesson toe help Windows users get set up because I know one or two off. The students on the course of had a bit of problems with that. So the easiest way to do it is first off, you probably already using git. But if you know we want to go on download, get this lesson might take a while because everything on Windows is a bit slow. If we go toe these downloads on, wait this page to load, you're probably on a 64 bit machine. I'm on a 32 here, so I'll just go ahead and grab this foot. Tube it. It's already downloading. Cancel that one. I want you. It's wait for this to download. There it is no nearly going down those folder when it is still downloading. No, that's cancel out a moat strike and still downloading, but so let's hope that's happened there. I was going to do that. While we're doing that will also go find that heroic. Ooh, command line interface. Now, there we go. It's finished downloading now. Great. So we can install s just by finding in our downloads folder on double clicking it. It's like, Yes, there. Watch its wait for the Gittins dollar to open. There we go. Those options are fine, you know. Here, I would recommend probably going for tech ises commit is is that's fine. All of that's fine clicking store on. Well, let me just do its thing. So while after winning, we also want her Roku cli We get to download and install again. I'm going to get the 32 bit. You're probably on the 64 bit. Okay, great nuts. Downloading on and get is installing in the background as well. Okay, great. Hiroko is finished downloading. So if you already got get installed and you're already using get which I presume you are, you won't need to do this step. But if you haven't, then this is a good way to g o. It's going to take a bit of time for this to do its thing so we'll just leave this to spend on will pick it up again in the next lesson. 7. Installing Heroku CLI on Windows: So it's finally finished installing Onda. We don't need to release now so we can take that and click finish on then. Next thing we'll do is go to this hair. Okay, installer and install as well. Missile Install the actual who? Oecussi. Ally, If you get this window, stop smart screen message If you click. Okay, nothing will happen. So you want to go to more info and click ruined anyway on click? Yes. And this will open up the Hiroko installer when all of those things that profits fine. And then this will start installing as well. So this is the actual tool that Roque who provide that will plug into our command line on again. This is just going to spend a while spinning. So I will pause the video here and we can pick this up when this is finished in the next lesson. 8. Using Git Bash on Windows: Once the Roku in stores finished, we can hit close. And then if we go down to start on good, our ups scroll across. We can now open get bash, which you may have already heard. Or it may be new if you just installed it for the first time, we still like that. This will allow us to an R get commands in here. But also importantly, it will now allow us to win the Roku commands as well. So that we got the hair. Oecussi Alliance told us. Well, so you can use this. Get cash for both you get and her Roku commands when you working on windows. 9. Creating a simple app: who we are. We've got our Roku account set up. You've got the command line tool set up and how we're finally ready to start writing some code and creating this first app on just to show you what's going on here, I'm just going to create simple app using a micro framework, specifically flight. You could use a different one if you want. But if you wanna follow along, that's what we're going to do. We're gonna bring flight in, just create a really simple hello world app on Pushed up to Roku. And then after that, we'll move on to do things a bit more exciting. So the first step is we want to start by writing our composer file Andi, some interesting stuff going on here that we'll talk through. But that's good from the base six off how we push things up. So obviously we want a requirement on. The first thing we're gonna do is specify that we would like PHP, and that's obviously part like composer standard. But it's particularly important for Hiroko because when we push it up, we are going to tell her Rocca, which version of PHP we want and just By changing our composer file, we can tell hair Okay, that we want a different version of PHP. So I'm going to use PHP 5.6, which is quite an old version of PHP now. But I think it we good Chauvet backward compatibility. Feel free to use. Ah, more modern version. I'm just gonna bring in that framework we want as well. That all looks good to me. So let's save this on. Just just create this demo folder, even create a folder. Where've you want? Wants to be? Somewhere. You can access it via your local host, so just save that in there. I will hold over to the command line and we'll do a composer installed that's going to chug away for oil. Yours will, too. So there we go. Actually, it's done, Andi. So if we just get a local host now, Andi put up. Nothing is gonna happen. We don't create any BHP files yet, but we've got our composer. We've got our composer that Locke, and we've got a vendor directory, so let you ruin your composer foil. Andi, your composer installed, and then we'll move on to creating some code in PHP. 10. Adding PHP code: Let's write some PHP code that start baj. It's great in our index file on bond we can now require even we can now require in our composer auto load so that world boots droppers on. Then we can start accessing flights a p I. So we'll just scrap basic basic root in the home director here on, and we'll use a closure on it. You do this and inside just gonna do the classic hello world. And finally we're gonna tell Flight to start. We save that as index dot PHP in our demo root directory. It save. So we're bringing in the auto load, redefining the route and then were running the microphone work nothing heroically specific . Here's just standard PHP. And if we give upto a browser now on, just refresh we've got low World. Okay, Brilliant. So that's a basic PHP up that we've now written on. We now need to look at how we pushed up to Roku, which we will start with in the next lesson. 11. Creating a Procfile: We've created our basic Web application now. So the question is, how do we tell the Roku platform what we want to do when we push it up there on the answer ? If we use what's called a Prock file, which is just some Hiroko magic that lets us tell you what to do. So in this case, we're creating a Web application on Do we want it to run on Apache now? You could also use Engine X. There's a lot of different options for Roku, but I'm going to stick with Apache because that's probably what most people are using Andi . To make that work, we just need to enter the path that heroically specific path for where we want that on its This is Web colon vendor slash bin slash Roku dash PHP Dash factory to Andi. There's no kind of secret to that. It's just some hurricane magic, shall we say on. We want to save this as product file. That's it. No extension, just in the root of our project. It save on that Andi. So when we push it's up, Hiroko will use this file toe, identify what? How it's bootstrapping the application. So we now get everything in place and we can start looking about pushing it up 12. Committing to git: got a where but built on. We're ready to push it up to Roku. But how do we physically do that? Well, the answer is everything in her Roku happened. Get on. If you want to push new code, you just do a get push. So how do we get this first? Things we need to get this into get right. That's that step warned to the process. So first off, let's start by creating I get ignore file, which will tell, get not to save the stuff in vendor. Because when we push it up to Hiroko, Roku will do all the stuff in the cloud. So we'll tell it to ignore vendor. OK, I get ignore file. Great on, then. If we go over to the command line, will create a new you get repo on, then we can add the files we need. So we need Prock file. We need composer dot Jason on composer dot lock onda. We need indexed uppity on the we can just go ahead on commit that se initial commit Well, if we look at I get status and I missed to get ignore file. So that's odd. Get ignore file and commit that as well. Get sick? No, aka ambulance. So all our stuff is now in the get repo on. We're ready to push it up to her. Okay, which we will do in the next lesson. 13. Pushing to Heroku: let's push our application up to Roku. So hopefully as we talked about before, you have the Hiroko command line tools with you. Andi, whatever version you got is fine. And if this is the first time you've done it, you'll need to run the Eroica Logging Command, which is just Hiroko. Log in and out, prompt you to enter your email and password. You only need to do that once I've already done it, so I don't need to do that. But if you're just getting started, you will need to do that. And then we're down to our application specific stuff. The first thing we want to do is tell her, Roku, that we're creating a new web application on that say, its jets heroic, who create that sets up this up ready for us, and we can now push them code to it. So the way we do that is we do get push, just like a get push anywhere else, except we're going to specify the targets. Heroic. Ooh, Master digits from our local master branch up to the Hiroki Master Onda. We will let they took away on Once we've done that, we'll go back and we'll look through some of the things that Hiroko is telling us is going on here so we can see that her Roku detected it. Wasa PHP up on began bootstrapping it. It gave us the PHP version that we asked for giving us both Apache and Engine X. You can use Eva on. Then it went about installing. The dependence is that we asked it to get so it ran through our composer file. And it'll do that without any Dev dependencies. And it'll do that automatically doing the quick auto load. So all the things you would expect for production of automatically run when Hiroko does that on DSO. We've got a code on the system now, so two more things to do. First of all, we need to give it a process because away Hiroko works is you push your code up on each up can have multiple instances. If you've got a big approval of the load, you probably want to put loads of basically virtual Web servers behind it. We just need to tell her, Roku that we want one basic Web server on the way we do. That is, we just say Roku process scale to Piast scale. And also we would like one Web server, please. That's all we're doing here is saying we'd like one virtual Web server for this instance. Yeah, says that's from running. It's just on the free tier, which is great on then. Finally, last command. You don't need desperate its chips a quick shortcut. If you type Hiroko open, it will open a browser. We have the current app. Do that. Now on. There we go. This is a hello world at running on her. Okay? We just got our first app for morning, so that's great. We've seen how the basics work in this lefton. We've been able to push an app up to Hiroko, and now we can start doing things that are a little more interesting in future modules. 14. What are config vars?: in this module, we're going to look at conflict bars. But first we should probably ask what, what our conflict ours on the best would explain. That, I think, is to look at the old way the way we used to do things in Petri applications. On that something like this, right? We have a big if statement on, depending on what environment it's set. Then we set a different confit variables, different database names, for example, using in this example Onda. We just got this massive if statement hidden somewhere in our PHP code that works at what environment is on. This isn't really great, right, because in terms of writing completely testable code, then we can only really test the where the environment equals test. We don't test all of our code on. We want to have maximum code coverage. So in order to make sure that we just have one set off pitch, be code 12 factor app. If you've seen this investigation came along and said right well, we need to store these conflicts in the environment because where its development tasked staging production that all of our PHP scripts Duke's wants a database name on It just needs to vary depending on the environment so we can store this stuff in the environment rather than in the code on the way that we would typically do that is by going into the APAC tree conflict. Andi on sending a virtual host level. That would be a typical way to do it from the lamp set up. But that's quite a Pfaff in Hiroko, and there's also much better way to do it on. That's just to set our Hiroko conflict bars, which are literally just variables, are environmental specific. So instead of using that big, clumsy if statement, we just saved the database name in ours, a conflict bar in her Roku on we could configure this in Apache in our virtual host on the local machine will be doing both of these in this module on then. Our code is really nice and simple because we just got one line. It gets the database name from the environment on its the same code across all of our platforms. So, in summary, conflict bars, aren't you. It's variables that we store in the environment, so you can use use one variable named different variable values across the different environments on this allows us to maintain one set of code about these big, old ugly if statements that we used to use. 15. Adding a local config var: let's start by adding a conflict variable in locally. So to do this, our project is going to need its own host name rather than using local host. Hopefully, you're familiar with setting up a basic kind of Apache virtual host. First thing you need to do is edit your host file on Mac. That's a slash e T C slash hosts or Windows. It's someone different, and if you click on the resources for this lesson, I will link to tutorials on how weather your host file. But this is the line you need to add. We're going to use. You can use any host name you want by Muse in Roku for PHP, and I'm pointing back at my local host 1 to 7 points there was over what? So we've got that the other thing will need to do is then create a virtual host in our Apache config. If you're using Engine X, then obviously you want to do something but different. Let's just scare it. It's now, so I'm just in my Apache conflict here, on on going to create I knew company file. So this is just a standard Apache conflict file here. That's all we're doing, um, and set the server name to the name we just defined in the Accept your host file. Fitch P said. A document root, too. We want to point this at the demo doctor we create earlier. And then here's the more interesting, But we want to set on environment. Variable on. We're going to call this project name Onda. We call It's her Roku for PHP Dev Unknown will close close up. So that's just like any of Apache configuration. You can use environmental variables in any other context as well. There's nothing Hiroko specific about this, so we will save that on. Then let's restart Apache again. This will depend how you've installed it. I use Mac warts. So that's the Commander Mak ports. But however you configured your Apache, you'll need to do the restart. Andi. So now hopefully we get our browser. We have heard of bit be giving us our demo. Hello World application. Such wonderful stuff. Now let's take the environmental variable would just created and use it in the application 16. Using variables locally: in the last lesson, we created an environmental variable within our Web server on DSO. Now we want to modify our PHP code. Teoh, use it. So instead of hello world, we're going to say Welcome to after this We're going to use Pia trees. Get him function, which is just a standard built in function. Onda, we called our environmental aerial project Underscore name, if you remember. So which is gonna do welcome to and then output that environmental variable which I I think we called Roku Fitri deaf. So what we should get is welcome to her. Okay. For PHP, Dev, when we run this in, the web browser will go back to our browser and refresh. Yes, Now we have it. So we've got Welcome to Syracuse BHP, Dev, and this string is being pulled out of our environmental variables. Why we're doing this will become really clear. What we start modifying on the heroic Ooh platform 17. Deploying our changes: got our PHP code of the morning now, So let's push that up to Roku across to do that. First of all, we need to commit it till I get Repo so we can see that we've got one file index of pitch fee and we will want that should be staged on. Then do you get commit? So, hunting, um, environmental variable will say, Gotta get status. It's in there is good. So now we can do and get push Hiroki Master, which remember, is a way that we push the code we've currently got in the get repo up to Roku so you can make local changes without them getting pushed to Roku as long as you don't commit them. Once I committed the next time you do to get push, they'll go on to your hero coup platform. So let's run this now and again. It's not gonna take too long because it's quite quick on. There's a bit of cashing on there as well. We'll take a bit of time to chug along there. Okay, great on then. If we do hair OK, open to open in a web browser where you get the app on it just welcome to Blank. Why is it doing that? Because we haven't created an environmental variable on Hiroko. Yeah, so there's nothing to show up there. So in the next lesson, we're going Teoh, look at how we create these environmental variables on Roku. 18. Using variables in production: in the last lesson. We pushed our code up her Roco, but because there was no environmental variable set on her Roku and it didn't say anything . And so we need to create that. So in this lesson will go through how to do that. And on her Roku, they're called conflict vase on. You can add them via the command line, or you can do with the dashboard. This is true for almost everything that you can do on Hiroko, and so far we don't everything via the command line itself. What would go into the Web dashboard instead and show you had to do it this way? But if you want to do the command line, you can as well. So we're going to the dashboard on. We see our list off APS on. This is the one we create earlier you can see appear were using Warm Temple that's like that on. You've got an array of options here on. We want to go over to settings on the fire right on, reveal conflict bars. And of course, we haven't set me up yet. So at the moment, Egypt says there are no convict bars, but this up yet Learn more about them in the Dev Center. But we do have when we want to use on, we can just put the name and here. So it's project name. That's what we use locally. Andi, we're gonna call it her Agu for pitch Be alive to remember in the local version, we called it Eurocup. It be Dev here. We're calling it Hiroko for PHP Live on. We will add that on that will update straight away. Might take a second for the app to restart because every time you modify these, Hiroko will restart the app so worth considering If you've got any state based stuff in Europe, probably shouldn't on her. OK, but if you do on there we go so refreshed it would have changed any of the code or we've done it is got it to read the environmental very well, which now exists on now it says Welcome to cuckoo for PHP life and of course on Dev. Same Curt Hood heroic of pitch P Dev on on Live Why is this useful? It's because if we have, for example, logging levels want to be different on production. Andi Development, you're probably connecting to a deaf database in development on a live database in production. So all of these changes where you want different things happening in different places we achieved through conflict vase. 19. What are addons?: in this lesson. We are going to look at Adam specifically what our guns on then, later in this module, we're going to go ahead Newsome so we can see them working in the real world. So we've got our nice Rocca platform. It's brilliant. We couldn't close of to it. But, you know, any kind of application is going to use more and from stuff, right? We're gonna want to connect to services, especially on the A federal file system that Roku has on a heroic who does come with some built in services and managed by them. So, for example, they've got readiness and they've got post crests on. They've got Apache Kafka on those available easily to spin up. But what about the other services you might want? For example, we might offer database platforms like my SQL a mongo DB. We might want to use some elasticsearch. We want to use men. Cash won't be sending e mails or something like send grid. We want when we doing some application performance monitoring with things like the whole bar in new relic. On the good news is, all these are available on. They all come in her Roku's Adam section. Andi. They're all managed by third parties who provide them, but the very tightly integrated. So if you want a nice well, incense, for example house work in a demo Later in, go to someone like Jaws DB, who is 1/3 party company that provides this mice well, Adam for you, Roku. They're tightly integrated into the raku, so you can activate them from the command line and get rid of them. And they typically have a free layer. So most of them have paid planted well, that everything we're gonna be doing here, which it's gonna be using that free tier on there also self configuring. And what I mean by that is that they'll normally inject some confident the environment. So, for example, if you spend on Permai SQL database, then they will be my school conficker automatically inserted into your brokers application so you can just read from that conflict variable and Connectors airbase. Similarly, if you're using one of the application performance monitoring things that a new probably need a client key and again that's normally just automatically inserted. So it makes it really easy to aunt some of these third party services into our Hiroko application on. We'll look at just how easy is in the rest of this module. 20. Using addons: during this module. We're looking at resources on add ons. Andi really common scenario with PHP Web applications is that you want to access a my SQL database. So post heroically does have some support for post grass but doesn't support my SQL. So if we want to get my school, we need to go to 1/3 pipe provider. Onda Cero. Coup has this really awesome kind of community off add ons that you can use provided by third parties. They all integrate really well. The Hiroko platform on one of those is called Jaws DB, which provides a MySQL database. They also do Maria, if you prefer that an easy way to do this is just going to your web up. Go to resources appear on this will list you the dino's, which is a kind of Web servers that you're running on and also any add ons. In select a new ad on Andi, it'll give you the price plans. We've probably want to start with the cheap one, the free one. Even eso you could do that. Fear the web interface. But you can also do this via the command line on. I'm gonna show you how to do that. So we're in our demo folder and what we're gonna do is we're gonna say you're okay. Aunt Organs were gonna ask it to create a Jaws db on this is exactly the same as doing it for the weapon faces just nice. Inconvenient because it's on the command line. So that will go off. And it will create this My ask your database in the cloud. But what it will also do is had a conflict variable into our Hiroko application to tell us where the database is in. It takes a couple of minutes to set up, so this might know produce anything yet. But if we do a Roku com fig on, we say get and it creates one called jaws db underscore. U r l specific to each add on. So you have to look at the ad on documentation for each one using that for George C B Jaws DVD and scare. You are l on the other. We have. So if we look at this, we've got their here. That's I use the name. That's our password. This is our host name. It's all stored on AWS on. That's our database name as well. That's a live credentials. I'm going to have destroyed this database by the time this lesson goes out. So they won't be live credentials for the time you watch this. But right now for this demo, this is the actual string that you can use to connect to your destiny is to work from anywhere. Doesn't necessarily have to be within the heroic application. So let's take this string on, let plug it into our application. 21. Addon dashboards: once your day basis set up, one of things you might want to do is have a look at the status and get a bit more details on it. Onda we can do that using the Hiroko Avon's commanders. Well, we do, Eriko. And on on this time we want to open. And it's kind of like when we did the heroic open to open our application in the Web browser. We do that and we use open jaws DB. This will then open a Web browser that has all databases and so we can see the connection string. Here we can see all the host names and user name or password here. You also reset your password if you want. And then there's also some starts on the server and how that's doing on some documentation down at the bottom. Generally, each had on will pass you over to the third pipe provider so you can get more details on what is going on 22. Adding the variable locally: we've got around on Andi. Now we want to make use of this new my SQL database. The first thing we want to do is take this connection string Theis jaws D b u r l That's the conflict violence being created in her Roku on. We want a mirror that locally. Now, if you ah, running a Devon production environment, you'd have separate database details for local and production. But for the purpose of this demo, we're just going to use the same database. So to start off with, we just want to grab hold of that database you Earl on. And that's because I am in the wrong folder. You're right, one. Here we are. This is what we need. Soldiers. Take that and I will copy it to the clipboard on. Then we'll come over here. Teoh, What we have our Apache config on will go back into this. So it's just said it. This this is our virtual host file for Apache again, he's a ninja. Next, it's gonna be different, but we've got this September we set project name on, and let's just set one to mirror the heroic environment. Says Jules D B U R l and then we'll paste in this connection strength. So now on both local and her Roku When we try and access if yours db and the school your oral environment, we're going to get the same string. Let's save that on again. Let's restart our local Apache Set it up That works. So we've now got this Jaws DVU rental available in our conflict on We can now go into our PHP on start using it. 23. Connecting to MySQL: now going to change our application to accept this new variable that we've created for this . We can get rid of this you've ever called DB and we're gonna use the past u R l past your AL function which is just built into PHP. And the reason we're going to do this is because if we look at the variable that were given , then it looks like you around different like you are also, for this instance, the past year old functions could be really useful. And we used to get em function to call the environmental variable. So this will take the environmental burial Pass it like a girl into DB, which is just available we've created on. Then we're going to use my SQL improved my school. I on Of course, normally you would probably use are higher level lively like something like doctrinal propel or something different than my skewer I. But I think for this would just get down to the basics on the right. It in ah, straightforward a manner as possible. So going to create this my SQL I instance on, we're going to use the variables that we've pulled out off are you are well into this DVD function. So we're gonna pass it in the host and fasten the user. We're gonna pass it in the password on. Then finally, we're going to do something a bit more complicated with the dead rest name. Because if you remember the structure of the U. R. L, we get the host name and then slash the database name in the big variable. We got that here. Yes, when we parse this will get the user name and the password, the host name and they'll give us slash Database. Name is the path. Obviously, we don't want that slash start, so this str of place right here will take that out. So connecting to mask you'll database using all the variables that this jobs to be had passed into its hundreds to check. It's working. We'll go ahead on. We will just write out the client info so will connect to the database and then lies. No, it's been successful by telling us down here. Let's say that on then. If we go back to our browser on refresh. Yes, it's worked. So we have asked status. I should have sounded so surprised. Obviously I knew was gonna work because I think this before, but this gives is our stars shows that were connected to the database. Andi again, we can push this code up to her. Roku. Andi, it will just read the your variable affair. Okay, which in this case is the same? 24. MySQL in the cloud: we've got, ah applications in locally connecting to the database. If we go to the Web version that's still showing the last thing we pushed up there, bigot. So let's go and correct that now. Very look, kid, I get status. We can see we've modified Index, don't pick trees. Let's at that. Let's commit it. Say my SQL connection in the commit message. Great. Look today, there. And finally we'll push this up to here. OK? You then get push here. Okay, master, as we always do on. So just take a second to chug along, not using any special libraries again. So should be fairly quick. Here we go. And now if we go back to our live her conversion and do refresh and then we go, we've got the same thing. So again, it's reading that environmental variable this time from the Hiroko platform on using it to connect to the database 25. Breaking the app: in this module. We're going to learn about how to handle Evers that we might find pop up on Roku because it's not our simplest. Just looking at an hour like Well, it is, but it's a bit different. So what we're going to do to start with is jets deliberately creating era. So first off, let's take out this their base connection code on Let's just manually throw a new exception saying this app is broken on. Something else we need to do is well, because if we just look at this by default, now we get this error message. But this here is actually from flight the microphone, what we're using So it's not going to the normal several 100 flight is handling this internally on just producing this nice takes their mouth. So we don't want that because we want to troubleshoot a real era. So what we want to do is in here also, we want to set the flight config so that it doesn't handle areas, and it just leaves it to the built in error handler. So Winterset flight dot handles got hers to false on that well, tell flight to ignore it just let me hair above. Look now, if we dio, we get the more standard PHP error handler. So normally you'd in this case and be able to troubleshoot locally. But let's imagine that the era isn't occurring locally, but it is occurring on Roku. So at this point, we think the code is fine. Andi, Look, I get status we need on commit that Andi was breaking app. We know we're doing it for demo purposes. Soldiers put that Onda will push up to heroic Ooh, just give that a second to run again. It's pretty quick because we're using really, like, way up here so naff we re fresh. Zero Q is configured to be production like, so it doesn't give us the era. Egypt's gives us this 500 our page, saying the APP isn't working. How do we trouble you? This. If we can't see what it's doing, how do we work out what's going on? Well, that's what we're going to look at in the next lesson. 26. Finding out what went wrong: So we've pushed this code up. Teoh Roku on. We can see that it's broken. What do we do about it? How do we troubleshoot it? And the answer is to use the parochial logs, which can be accessed from the command line. Let's use heroic. Ooh, logs is a command we need on if we want to tail the logs we can at dash dash tail, too. So this will just give us the last bit of logs. And we can actually see there that we're seeing the exception if we're tailing the logs. So Aziz. Well, if we just give them a bit of space and re fresh, we'll see that here again. It's popped up on. We can see one car exception exception with the messages up is broken in APP Index Line eight, which is indeed the line that we threw the exception. So we can then use this to identify where the APP is broken. What do we do? Wouldn't we found the source of our problems? Well, we probably want to fix it as soon as possible on that's what we'll look at in the next lesson. 27. Rolling back: we've rolled out up on its broken and we're panicking and we need to fix it as soon as possible on likley. That's really easy with Roku because it's all get based. We've got full log of all the changes were made. So if we want to roll back to the earlier version is literally just simple asked typing Roku! Rollback! Andi! Hit that on. Hiroko will do all the work for hours on here. We can see that rolling back to Version 10 from version 12. Happy with that now? If we go back to our Web application and refresh, it rolled back to the earlier version. Now we can fix our code and then redeploy, and hopefully it'll work the second time. 28. Provisioning Rollbar: never really good way to troubleshoot errors, but particularly when you live on your no actively testing and monitoring all the traffic going on is to use what's called Roll Bar, which is it's at monitoring software, just like if you use new relic. It's similar to that. It's really nice has both for a client, Java script monitoring and back end libraries. Andi, What's great is they've got free tier for Hiroko, so that's perfect. So in this module we're gonna look at had a use roll bar on how to get see your heresy, a dashboard and had a configure it. It's an an add on, like when we create the mask your database. So for stars, which it's going to do, an adamant Also, we're going to stay here. Okay, on dawns on, we're gonna ask it to create one on its roll bar, and we want the free plan so creating add on robe are free on Let's run that perfect. So it's created for us. It's also created this variable called Roll Bar access token, which is every time when you create your robe, are instance in your code, you need the access token on we can easily access that using the Hurricane Con Fig and we'll say, Get we would like the roll bar access token, please. And then we are That's that's my live access token won't be live by the time this video goes up, but there it is, So we'll copy that to the clipboard on. The reason why we need to do that is because again, we are going to mirror our live convict on our local conflict in Apache. So it's going to go into my virtual hosts here at a new line and set and roll bar access token on, then just paste in that value they've given us. So that's automatically create on her. Okay, what we need to create locally here create locally Let's restart factory again on now we're ready to go in on install the client library in its a service side library, but it's kind of like a client library in our PHP coat 29. Installing the client library: So in the first lesson in this module, we looked at how to provision roll bars. Now, dawn on. Now we're going to install it into our project. First thing we need to do is grab the actual library, which will do with Composer. So we want robots. Flash roll bar on. Any version is fine, Andi. Now we could go to the command line and when a composer update, that will bring in the role by library. So just take minute to two sugar over. So the way you install library roll bar in a pitch P application is to bring in the library with composer. They'll make a little suggestions, but it will also work for you, Andi. Then you need to include in your pitch be good itself. So let's do this right at the top so that if you put it at the bottom, then you might get in the error before World Wars initialize. So we want to do this as far up the top is possible. Obviously, we need the composer water loads in there on here, which is going to say robot flash roll bark is named spaced on. We're going to initialize it Couple of variables we need to pass into here. So first we need to give it the access token on. We were used to get em function, pull out the roll bar access token that we saved earlier. Next thing we need to give it is on environment here. Typically, you would also read that from a conflict variable so you'd set on, Hiroki Aide said. The environment to live heeds to development so you've got to. But for the purposes of this demo, we can just say it's all in development and that will boots to our robot bootstrapped roll bar so that when we get an error, it will send it so free. Refreshes locally now got ever and now online. Six. Let's quickly clean. Not up on that. We're back to our classic exception, but also now roll bore should be logging this, So let's explore the robot console and see what's going on 30. Rollbar dashboard: we've got error. We've got roll bar logging it on. Now we wanna take a look around to see what's going on so we can do that with the Adams command. We're gonna do her at ons on. We would like it to open the robot on on a zip by magic. Here we are in the role by dashboard that's created for this application. Every city we've got our top items in last 24 hours. I've only had one error, which is the exceptional Emmanuel through. But on a live environment, we having a lot of areas. You could see a lot more of these. And if we go into this, you've got grafts. Is that how it's occurring? Some more descriptions of it here as well. On here, you can see a full stuck trace off the era. So this point you can just hide the error on the phone. And you would be doing that normally anyway, on then. But all your errors will still be locked to roll bar. So when you need to troubleshoot you come into the role by dashboard. See your full stack traces on debugging production. From there 31. Configuring domain names: in this module. I want to look at how you can do some real world configuration on your heroic WAP on day. One of those examples is that you probably want to add your own domain name, right, because on our demo out, we've got this nice warm dash Temple Dash 35784 doctorow co app dot com and you could use that. But chances are you want to use you actually own domain name and set up is no that straightforward but will go through. It's a two step process. First of all, you want to go to your hurricane dashboard, select your app on go hit settings, and if we scroll down, we can see the domain name and we can add a custom domain if you want. Now I've got this domain at war Photo lk Just my name with a dot in the middle. And so let's say on other I'm going to use a sub domain of that. So say Herro Kudat War photo L K. That's That's my domain and this is new sub domain. I'm creen. We could just save changes there, so assisted here, and it's given us this DNs. Target on what we need to do is go over to the DNs on our domain name. Andi, create this as what's called a C name. So how you do this will depend on who your domain name is registered with. How much DNs control They give you one option if you can't work and have do this cause some hosts just don't support it is use someone like Cloudflare. They provide you with free some three website protection, but also DNS management. So you can point your domain to Cloudflare of them pointed to Roku, which is a bit cumbersome, but it works on. So I'm on my management page on Cloudflare here. I've got my domain name. Andi. I want to get see name record on. I'm just gonna Dimon's heroic Ooh on were pointing it at this domain that we've been given Turn off enough Cloudflare protection could we don't need that here or jets hit and record . Andi, that's great that there we go. If you wanted to point your root domain name So instead of it being Hiroko, don't war Foda. Okay, if I just wanted to point war folk that okay at Roku That's fine to Andi on on here. It's the same in my domain name. I just put the root domain in on on Cloudflare here on name. I just put an at symbol on. Then I put whatever value it gave me and again so that that's gonna is gonna take a while toe work. I don't think it will start working straight away. Let's try it. It's going to take a lot of time to propagate it up through cloud for systems and through the Internet. But that is how you would sell for custom domain on again. We get any problems, just hit the Q. And A board asked me a question, but that's the basic process for doing so. 32. Configuring Apache's web root: Okay, so let's look at a really common way. You want it configure Apache, and that's to use a public directory. That's not the root directory. Because of all the security problems you might get there. So let's go ahead and create directory called Public There, which we've now got here on. We wanna move index file into there. So, Dix, move that into public. Great. So it's now in this subdirectory. We need to alter this slightly, of course, as well. On then, if we try and refresh in a Web server, suddenly it's gone because we've moved into the subdirectory. Let's start by cleaning this up locally on to do that, we will edit Ah, factually conflict file. Here we are here. Now we're saying we're using public. We'll save that. Andi, we will restart Apache. Great. So now if we do this, it's working again. Great for about here. Okay, how do we reconfigured up? And the good news is it's really simple. We just get into our Prock file on that the end. It will just right public and other slash and that's it. So we get back to our terminal way, have look, we'll stage that kid. Public status? Yep. So modified one we've moved the over happy with that are doing a public directory. And finally, let's push all these changes up to record. So when he goes live on her, Okay, we shouldn't see any difference, right? Because we moved the files into the public directory and then we've set the Webroot for our application to public. So hopefully when we refresh this, we will still see Hello world. And we do so brilliant. We've now created a subdirectory on we've configured. We've configured her Roku on Apache to look at that public directory to get the Webroot. 33. Enabling PHP extensions: Let's say you need a period to be extension on Hiroko. How do you do that? Well, let's give an example. First of all, let's take get rid of this on. Get rid of this error on. So we're gonna use the We need the image Magic library. So perfectly normal. Their new I magic. We looked locally and which fine? Because I have image magic installed locally, so that looks find to May. The next thing we would do is what had all these files composers changed because of when I installed robots. Alerts do that, I say, adding image Manchek on. Then we will push up to hurricane. So I've got image magic installed locally. But the question is, is it automatically available on Roku? Uh, so push that up. Will now get a heroic A refresh takes a bit of time because the restart and the answer is no. Right. This is the same code. Suddenly it stopped working on. If we do the log so heroic, you logs Dasha tail. Let's try and work out what the problem is here. Class image magic not found. The answer's No, we don't have access to a range magic How do we tell her? Roca. We need it. The answer lies in our composer Jason File. We're told it won't PHP but nothing about image magic. And where we do that is the standard composer way. We just say We want image magic Onda According to the composer documentation, I've gotten email from Pearl Baffling. We've broken it. We should just see that star for the version whenever we're requesting an extension, because it's really tricky of wise. So we update our composer file. Let's go back here on. Do we need to run a composer update? Why do we need to run an update? Because when we deploy to Roku, it uses it composer dot lock file to install everything. So it's important that we get in there so that next time we push it, it will work. So again at these files on to get commit, saying, including image, magic and our composer file on once again give up into space, we will push up to here. Okay. Boom. Now for your back onto broke. You on refresh. Fine. Let's take a quick look at the logs. First seven. Pick anything up there, see? Installing platform packages we can now see we've loaded this image magic extension as well as PHP and our Web server on If we go back to the APP, we're now getting the blank page, just as we were locally. So that's how to configure PHP extensions in her Roku. There's a list that they of extensions they do and don't support a link to the only resources on some of them. You can have some of them you can't have depends what they've got available. 34. Switching to nginx: what happens if we want to use Engine X instead off Apache? Well, let's do that now. First of all, let's look at what we're running in the moment. So let's just echo out the service software MKS kid. We see running Apache 2.2 locally again, a little out of date. What's and that Just label. It's just service software. So we've got echoing the server software we've committed up to get on. Now we're gonna push that Teoh work you off, it goes large. It's take a second to run that we could take. You mean to magic hour if you want it. So here we are in her Roku Jets reload. This takes a second because every time we've pushed the application up, it has to do with that black form stuff on there. We just get a factory nice and simple. Okay, so we're running a factory. What happens if we want to switch sister engine? Except the answer is, we just do in the prak file. So we will take away factory to on replace that with engine X. Very simple, straightforward. Go back to a command line. We could see the product files change that. Commit on, we're gonna say switching to and Jax on a finally will push this up. Can we always get both Web servers here, anyway? Seems to have finished. Great on that. If we go back on, refresh on Hiro kun and just give that second to reload. We see when are running engine X on? It literally. Is that simple to swap between the web servers? 35. Conclusion: Congratulations on making it to the end of this class on her. Okay. I can't. Great to see all your projects and see what you come up with. Ways that use that Roku Cloud. You have enjoyed this class and please follow and review on. I will see you soon.