Securing your PHP installation
We won't talk about every single security option in PHP but we will talk about the most critical ones you want to be familiar with and how you can configure and change them.
Video Transcript
00:00Alright, welcome back. I'm not going to talk about every security configuration in the PHP.ini file, but I do want to talk about the
00:08Really critical ones that you want to notice and make a conscious decision about how they work. So let's get started
00:15Let's go right into that file again
00:16So I'm going to go into my PHP.ini file and really what I'm going to do is I just and I do recommend again
00:22Read this document. It's really not it is a bit long
00:25You don't have to read the whole document but read all the way through until about this file
00:30Get a familiarity about what the file is and then
00:34We're gonna work through right now the quick reference and what the quick quick reference is is a comparison between what what?
00:44PHP recommends to be your development
00:47Value versus your production value. Now when we say development value, that means it's not accessible on the web
00:54So if you created a server locally on your computer the computer, that's a development value
00:59Versus production value is a value of when it's up on the web and accessible to users
01:05Now I want to go through the properties a few of them not all of them
01:09So allow call time pass reference. We're going to not touch at all because it's been removed since
01:15PHP version 5.4. So we're going to skip this we're going to move to display errors
01:21Now display errors is basically a decision. Do you want to show or hide the errors to the user now?
01:27Although it's telling you that the default in production is on or is is is off and the default in
01:34Development is on
01:36Really as we saw and we tested out the errors are not displayed and default in this default
01:41Configuration that we have in this default production configuration that we have so we don't have to change anything
01:46but if we wanted to we could have
01:48Confirm that we're not showing these display errors because it's critical that we don't want to show the errors to the user
01:54Okay, so I'm going to move on but and by the way if I wanted to configure anything here
01:58I would just move into insert and I could delete that
02:03Comment out and just put here a value and then I could set the value to be on or off
02:08So if I want to display errors, I could set it to be on but we don't really want to change anything
02:13So I'm going to delete that and just leave it the way it was by default put that comma comment back in there
02:19So I'm just gonna get out of my insert mode and we'll continue moving on to the next topic
02:24Which is display startup errors now display startup errors and you can see again the default for production
02:29They're literally telling you what these configurations should be now
02:33Basically, this should only be used for debugging this happens when the PHP has has a fatal error as soon as it starts
02:40And you can't figure out what to do and then you go and you add temporarily to see those
02:45Values and we're gonna see how you could you temporary make changes without going into the config. I and I
02:51Okay
02:52Next step and we're gonna look at that later
02:54Especially once we go into a course on PHP
02:57So we're just gonna we're just like touches you understand how to play with your PHP configurations
03:02Obviously, this is a little bit more advanced
03:04but it's also it's very good to know about this and know that you're setting your
03:08configurations and making sure that your your you have the most secure server that you can now error
03:14Reporting we're not gonna get into right now
03:16But it's the level of errors and the type of errors that will propagate all the way up
03:21And be displayed if it's on the screen or if it's in the log
03:25So what type of errors are then being displayed which as you start developing in PHP
03:30You might want to get really detailed errors such as
03:34It's not a bug. It's not broken
03:36But PHP recommends you don't do it that way maybe because it's gonna be deprecated in another version or maybe because it's not the best
03:43Practice to do it in this way. So it basically creates a more robust
03:47Environment for you to get more detailed errors, which is always good while you're development
03:51Developing and learning how to develop in a certain language
03:54But it's definitely not something that you'd want to play around with in a production environment
03:59Okay, so let's move on to HTML errors and HTML errors is literally the default is it's on there's no reason to turn it off
04:07It's when you're getting those errors of PHP has a link to send you to then you'd want to go there now
04:11The only reason why you'd want to turn it off is if you're putting these errors all the way to the production
04:17But you never would because if these errors would be in production, then you'd have links going out to an external site
04:22That's not in your control, which is never a good thing bad for SEO bad for security bad for a million and one reason so
04:31But because we're not outputting the errors to the user by default
04:35It doesn't really matter that they're there because only us in the development environment would be able to see them
04:41Okay, let's move on to the next element and that's log errors
04:44Now the default is going to be turned off, but it's recommended in development to turn it on also in
04:51production and the reason is is you could separate the logging to be in a separate file because then you could look into the file and
04:58See the errors, which is probably the best way to see the errors instead of fetching them on your screen directly
05:04Okay, and this is again as you learn PHP as you work in PHP
05:08It's one of those stuff that you're gonna learn how to configure and play around with I just want you to be familiar with them
05:13Now I'm not gonna talk about the magic quotes because it's been deprecated
05:17I'm just gonna talk about one more which is the max input time, which basically is how
05:23What is the maximum amount of time that we're willing for a code to take to execute?
05:28Now if we leave it in the default value of minus one
05:31It means a code could take five years and it's fine and we won't stop it
05:35But because we have limited resources on every server
05:37We do want to limit the amount of time a user could it could and this is not its whole
05:42Duration on the site is basically a command if you're calling something in PHP
05:46How long will we let that PHP function run before we turn terminate it now the default?
05:53production value that is recommended is 60 for 60 seconds
05:56So a script shouldn't take more than 60 seconds and if it does then it should be terminated
06:02Okay, so I'm not gonna play around with these configurations in here what I do recommend you do is
06:09Get you know like just do a Google search for a good
06:13PHP in I configuration for a production and just use that and the way you would use that again
06:17I'm going to exit here the way you would use it
06:20You would basically just rename your PHP in I file to default maybe PHP in I default
06:27And then you could download a version for for example
06:31One of the you know, I'm gonna pause the video for a second and I'll find one in the PHP site
06:36But basically all I'm gonna do is I'm gonna search for PHP in I production file
06:41Okay, so we're gonna see you in a second
