Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
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 learn how to configure PHP. Specifically, there are three things that we're going to be looking for. And that's to configure the error reporting, the output buffering, and the default timezone. Let's see how to do those. So in the last movie, we saw how to use the phpinfo function in order to bring up the phpinfo information page. This shows all of our configuration. It's a great place to look and see how things are set at the moment. The most important part, though, are these lines right here. Configuration file for php.ini. That is where our configuration is going to be loaded. Loaded configuration file.
It's going to be inside usr/local/php5/lib. And the file itself is called php.ini for initialize. That's what the ini stands for. That's the file. The php.ini file is going to hold all of the configuration. It's all of the things that we see on this page. There's one other important thing that I want you to notice as well, which is the line below it, scan this directory for additional ini files. Now, this is not always the case with all PHP installations. But the one that we've downloaded, the one that I used from Liip, well, that is going to use that. It was created so that it will look in this php.d directory for additional ini files.
And that's going to be important. We want to remember that. So we actually have configuration stored in two places. And our main ini file and in these extra files that are inside this other directory. So let's start by just copying this path all the way to the ini file. Use Cmd+C see to do that. Switch back to my command line and I'll use nano to edit that file. So here it is. Here's my configuration. You can scroll through it and you can see all the different things that you can configure in PHP. But let's jump straight to the things that we're looking for.
I'm looking for display errors, first of all. So I'm going to use Ctrl+W to search and it'll ask me what I want to search for. Display_errors. That comes up with first a quick reference and basic settings. I don't want that so lets hit Ctrl+W again. I don't have to type it again. The default is to search for display errors again. I hit Return, and here it is. This is the real value. How do I know it's the real value? Because it doesn't have a semicolon in front of it. The semi colon's letting us know that these lines are comments.
Ones that don't have semicolons are the real active lines, the actual configurations going on. You can see that it actually gives me some helpful information. It tells me what the default value is, the development value, production value that you'd want to have. Now, for in development, we want to see our errors. We want to know what went wrong so we can fix it, we want as much information as possible. But when we actually deploy it to the real world, we are not going to want to give all sorts of server information to people so we are going to turn off the errors in that case. But you want to make sure that right now, display errors is on. The next one that I want us to check for is error reporting. So, Ctrl+W again, its time to search for error reporting. And let's do Ctrl+W again, a couple of times to get to this one. Error reporting is set to E_ALL.
This is a constant value. And this constant value actually represents a number. So if you look over here in the config file into the search for error reporting, you will see error reporting right here is 32767. That's what this value represents, right? So E_ALL gets translated into a number when it gets stored. It's a lot easier for us to work with it, though, being this constant, E_ALL. So this will report back all errors to us.
Now, before version 5.4 of PHP, if you wanted all errors, you also had to put the upright pipe, followed by E_STRICT. The strict errors were a separate category that were not included in all, and that's counter intuitive. All should include everything, right? So they did make that change, and strict got incorporated into all so it includes that as well. If you don't want something in there, like you don't want these strict ones. Well then, you use the & and then the curly squiggle followed by E_STRICT.
So that means all errors except for the STRICT errors. You can do the same thing for all the different kind of errors that there are. Notices, deprecations that's code that's going to be going away soon. And you can see that they tell you, when you're in production, it's good idea to not have it raise errors on depracated code strict usage of things. But when we're in development, go ahead and give us a warning about those kinds of usages. So you want to make sure that you have E_ALL or that you have E_ALL followed by E_STRICT if you happen to have an older version, that works as well. Okay, so now we have that.
The last one I want to check for on errors is HTML errors. So we'll do our search again, this time for html_errors, we want to make sure that this is turned on. This says that when we do see errors, let's give them to us in HTML format. Just looks a little nicer, and actually has some links that we can click on. So now we've got our errors set to show us all errors. Let's now take a look at output buffering. So Ctrl+W and let's look for output_buffering. Here's the actual directive. Now, this has a value of 4096, that's how much data it will buffer before it outputs.
We'll talk more about output buffering later. For now, turn it off. Now, when I'm developing, I often have it on. But I want us to have it off so that you can see what happens when it's off. It's going to be very instructive to understand this part of PHP. So let's turn it off then we'll talk about what it does, and why we would want it. And then we can go and turn it back on, and we'll be able to use output buffering as a feature because we'll be knowledgeable about it at that point. So to start with, we're going to turn it off. And then the last one we're going to do is the timezone.
So let's go Ctrl+W again, let's search for timezone, and here's the one we want. It is commented out. We're going to take away the semicolon at the beginning and then we're going to put inside quotes, our timezone. What timezone do we want to be using? Now, there's a very specific format that these timezones need to be in. And you can actually just do a search for php timezones and you'll find it, or php.net/manual/en/timezones.php. So this is a list of all the supported timezones.
I'm in America so I'm going to click that one. And here you see a list of all the American timezones. This is both North and South America... You can see some American cities that might be close to you. So there's Detroit and there's another one here for Los Angeles. I'm going to be close to New York, that's my time zone, so I'm going to putting in America/New_York. I'll just go ahead and copy that, Cmd+C. I'll switch back over here and inside those quotes, then I'll paste that in. So it's going to set my timezone to be America/New_York.
Now, you could also set other information, latitude, longitude, things like that. But those aren't important to us at this point. We just need to make sure we have the timezone set. And the reason why we want to take time to do this is because PHP now includes some warnings that will pop up while we're developing. It'll say hey, you're working with date. And you don't have a default timezone set. That's not very advisable. In order to avoid those warnings, we're going to go ahead and set a default timezone for ourselves now. It's also a good practice to be in. So let's save that. Save modified buffer? We want to say yes, and then hit Return to keep it in that file name. We need to restart Apache.
For our changes to take effect. It wants our password. That's our password we used to install software on our Mac. And then let's switch back to our phpinfo file. And let's go up to the very top and we'll reload the page. So now let's look for output_buffering, no value. So it turned off output_buffering for us. Where before it said 4096 there. Let's take a look at time zone. Now, wait a minute. This isn't the time zone that I put in. And here's another one down here. This isn't the time zone I put in. So what happened? Remember that i told you there are additional config files.
If you go look in this directory, user local php 5, slash, php.d -- copy that Let's just go into that directory using cd. Then if we take a look at what's in that directory, you'll see that there are more ini files. And the one that really matters is this one right here. That's the ini file that contains a timezone setting that going to cause us problems. So let's just edit that real quick. Nano And we'll open up that file, and here it is. You can see that it has set Europe Zurich as being the the time zone. We can just comment that out.
And our default one will take place. I'll comment it out there, latitude and longitude as well. Or, we could change it here. We could change that value to be the same time zone that we had in the other place. All the other settings that they've got here are fine, they're not offensive. Notice that they did set error reporting here. If we wanted ours to take effect, then you could go ahead and then take that out as well. Alright, so once we've done that, let's do the Ctrl+X, save our modified buffer, and we'll save that file once again. We need to restart Apache. I'm going to use my up arrow a couple of times to get back to the command and hit Return.
Now, that Apache's restarted, we'll come back here and reload our ini page, and let's search for time zone again. And here it is. America/New York. So it worked. It did set it to the correct value. Now we have the basic configuration that we need to start developing with PHP. And not only that, we have a little bit of an understanding of how we go about configuring PHP. That we make changes to that php.ini file, we restart Apache, and then we can come here and check those values to make sure they're correct. There are other things in that file you can change. There's maximum execution time, there request to auto run, there's the maximum file size that will be uploaded. There's where you want to store your error logs. There's all sorts of things in there that you can go through and customize and make PHP work exactly the way that you want.
But this is enough to get you started, so let's move on and get MySQL installed.
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.