Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
PHP is a popular, reliable programming language at the foundation of many smart, data-driven websites. This comprehensive course from Kevin Skoglund helps developers learn the basics of PHP (including variables, logical expressions, loops, and functions), understand how to connect PHP to a MySQL database, and gain experience developing a complete web application with site navigation, form validation, and a password-protected admin area. Kevin also covers the basic CRUD routines for updating a database, debugging techniques, and usable user interfaces. Along the way, he provides practical advice, offers examples of best practices, and demonstrates refactoring techniques to improve existing code.
In this movie, we're going to configure PHP to the settings that we like and we need for this tutorial. Three things that we're going to be looking at, error reporting, output buffering, and timezone. Those are the three areas that we want to address. In the last movie, I showed you how to get the PHP info page. You do that from your WAMPSERVER menu, and you choose local host and that will take you to the main WAMPSERVER page, and then phpinfo is a link down here that will actually take you to it. So once you're on that page, this has all the information about the way in which php is configured.
So you can always come here if you want to see what is php running right now. What are its configuration options that it's using? This will tell you. The most important one of those is this one. Loaded configuration file. That tells us where the configuration file for PHP lives. It's called php.ini. Now WAMP also gives you a short cut so that you don't actually have to go directly there. You can just go to the WAMP menu and then under PHP you'll see there's an option for php.ini. Lets open that up now. Now it opens up in your default text editor.
For me right now, that's just Notepad that's built into Windows. And these are all the configuration options. Every line with a semi colon in front of it is a comment line. That means that it's not actually being processed. What's actually being processed are the lines that don't have semicolon the directives that are a little further down. So here, y2k_compliance equals on for example. Precision equals 14 for significant digits displayed at floating point numbers, and so on. Let's find the ones that we're interested in. I'll just do a search, and I can do that from the Edit and then I have Find or Control F you'll see also is what tells me will do it.
And then the first thing I want to find is display_ errors. And find the next occurrence to that. Now that's a commented outline, I'm not interested in that. Let's find the real one, and here it is down here. display_errors equals on. Now it also gives you some information on how to set this. And it typically gives you a development value and a production value. Development is what we're going to be doing on this computer locally. Production is when we actually deploy to a web server for the whole world to see and use. So we want to have different settings for those two things. For example with displaying errors, we want the errors to be on for us, so that we can see every single thing that goes wrong while we're building it. But when we put it in production, we don't want to to expose all of that data to our public.
We don't want to to tell them gobs and gobs of information about our code and about our set-up. So instead, we'll turn it off in that case. So you'll want to make sure that it's turned on for you and it should be. Now that's not the only setting related to errors, there are a couple more. The next one is error reporting, you can either search for it if you can't find it. For me, it's right above it here and let's just scroll up a little bit. Find out some of the information about that, and that tells you what all these different things are. And, why you would use them and gives you some common combinations that you might use.
Mine is set to report all errors. Now up until I think PHP 5.4. This said E_ALL and E_STRICT, which is what you can see is what it recommends up here. That E_STRICT is now included in E_ALL, so you don't have to do that anymore, but if you do, it's fine, it's just backwards compatible for older versions of PHP. Now when we're in production of course, we want to tell it not to do these and you put the little twiddle in front of it, the little tilde. So E_ALL and not the deprecations. Deprecations are code that's going to stop working in future versions. It works just fine right now, so there's no reason to bother the production server with it.
But as a developer, it's very important to see those deprecation, because it says hey, you're using something that's about to go out of date. You might want to think about a replacement for this soon, so make sure that you have either E_ALL or that you have E_ALL and this upright bar E_STRICT. Now if you're wondering, what is this weird E_ALL. It's actually a constant that represents a number. And if we just shoot back over here to our phpinfo page. Let's just do a find here real quick, for error reporting, and there it is.
And this is the number that it comes up with. But instead of trying to work with all the different numbers that correspond to these different things, those are settings of different bits. Instead we just use E_ALL. It's a lot more convenient. The next one I want us to look for in this same document is HTML errors. HTML errors, and here it is. You want to make sure that this is turned on. You would turn it off for production. But it basically says, when you create an error, do you want me to just give you text, or do you want me to put some HTML around the error as well? And It'll look better with the HTML around it, I think it looks a little nicer.
So, let's go ahead and do that. It also allows it to include HTML links in those errors, which can be handy. So that's it for errors. Now let's look at output buffering. That's a concept that we'll talk about later on. For now, I'll just try and find output_buffering. It says it can't find it, but I need to search up. It's probably up above. that's not the one I want. There it is. So, let's go up a little bit more. Now, my default setting is just to have it turned on. It says here that you can also provide a number that's the amount of bytes that it will allow to buffer, 4,096 is a default value.
That's what more people use. So, you could also just have 4,096 in here. However, we're going to alternate off right now. Alpha buffering is a desirable feature. It's something we're going to talk about, and we're going to learn why you would want to use it, but until you know about it, I want us to have it off. And then you'll appreciate it and understand oh that's what it does and that's why I need to use it. So, for now let's all make sure that alpha buffering is turned off. And then the next thing that we want to look at is the timezone. So again, let's do a search. We'll do search for timezone.
There it is right there, date.timezone equals and you might have empty quotes here, it might be commented out, or like me you might have UTC. UTC is Greenwich Mean Time. You can leave it at UTC and it'll work just fine. But you do need to set it to something and that's because if you don't set it then PHP is going to start giving you some errors from time to time saying hey, you're doing something that's related to date and time but you don't have a default time zone set.
That's not a good idea. So let's avoid those warnings by having some times zones set. Now I'm not in UTC so I'm going to go ahead and give it my time zone. On the php.net website, you can find the list of those, php.net/manual/en/timeszones.php. And then I'm in America, so I'll click on America and you can scan down and you can find cities that are close to you. So maybe you're somewhere close to Denver, or you're close to Louisville, I'm actually going to be close to New York. So here it is for me. America, New_York.
So that's what I need to put in as my value. Has to be exactly like that. And I'm going to put it in quotes. It's going to be America/New_York. So that's going to be my timezone. And it will then use that as a default when it's working with dates. And most importantly, it'll get PHP to stop giving us warnings about it. So once you're done, you'll want to go to File and Save to save your changes, then you can close it. And then let's go back to WAMP. And let's Restart All Services. So that'll get all of those changes take effect.
It'll turn yellow briefly, red, yellow and then back to green. Now it's back online. Now if we go back here to our phpinfo page, scroll up to the top and reload the page. And then we can look for some of those changes to see if they took effect. The one that I'm most interested in is going to be Output Buffering. So let's see just see if we find that. Output and it has no value right now for it, which means that it's turned off. Let me look for my timezone, timezone. And you can see my default timezone now says America and New York.
So those are the three key configurations that you want to make sure that you set up before you start using PHP. There are plenty of other ones in there that you could set for yourself, but those are the ones that we really need to have before we move forward.
Find answers to the most frequently asked questions about PHP with MySQL Essential Training.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.