Configuring PHP flags in HTTPD
In this session you will learn how to create and set an .htaccess that will enable us to set php settings for specific folders.
Video Transcript
00:00So we left off in the last video where we in this specific PHP file requested to change some sort of
00:07INI configuration such as the displaying errors as we've seen. What we want to do in this video
00:12is kind of say hey this whole site or this whole folder or this whole section should override
00:17specific properties. To make that happen we're going to do a few steps and first of them I'm
00:22going to go back into the file itself. Go back into my PHP file and I'm just going to comment
00:28out that override of configurations. I'm going to save that. Go back onto my server just to make sure
00:35that I'm not getting that error message anymore. Now that I'm not getting the error message anymore
00:40I'm going to come back in here and this time around what I want to do is I want to revisit
00:44and go back into my HTTP config file. So to do that I'm going to go into my X file folder.
00:51I'm going to find my HTTP D. I'm going to find my config. HTTP config. Oh I didn't I didn't say what
01:01I want to do with the folder so we want to V into it so I'm going to V into it and now what I'm going
01:07to do is I'm going to click on the shift G which will throw me all the way to the bottom of the
01:12file and I'm going to come into my virtual host my10.us move into insert mode break a line here
01:20tab myself into being right underneath that last property and we're going to add a new
01:26directory and this directory will enable us to say I want to approach this directory
01:33and which directory basically the root directory and on of that specific folder of that which
01:40is of our server basically our public folder and we want to make sure that we close it as well
01:45and obviously we want to make sure that we don't have spelling errors because those could be
01:51problematic. So inside of my directory now what I'm going to do is I'm going to give the command
01:56allow override now by default we cannot override the default configuration that is for our security
02:06so only if we want to enable a directory to make configuration changes only then we allow
02:11that override now it's best to always give the least amount of override that we can so we're
02:17going to leave the options which will enable us to enable us to change PHP options but it won't give
02:23access to absolutely everything we could also set it to all but in our case less is more so
02:29we're going to allow override only for options and I'm going to exit once I exit what I want
02:36to do is I want to restart my server so I'm going to go ahead and find that restart line instead of
02:42typing it all over again each time so sudo service hcpd restart I'm going to restart I see I don't
02:49have an error which is wonderful the next step involved now that I don't have the display of
02:53errors is I want to create inside of my folder so I'm going to sudo v inside of my directory
03:02I'm going to go right into my public directory go by going into www example public and I'm going
03:10to create a new file called dot ht access now it's really important to name it in this way because
03:18our server is going to search for these files now don't worry these files are not visible even
03:22though they're in the public folder because any file that starts with a dot is automatically hit
03:28a hidden file on a linux so by default it's fine that it's inside of the public folder because that
03:33will never be visible to the user unless we make it visible act actively which we would never do
03:40so I'm going to click on and enter oh I didn't put your sudo instead of that I type
03:46sudo which I'm going to roll with typos because it's been a long day
03:50and now that we're finally inside of it I'm going to go into insert mode and I'm going to
03:53add a PHP flag by PHP underscore flag space I'm going to name the property that I want to change
04:01which is the display errors and I'm going to set the value I want after a space so I'm going
04:07to PHP flag display errors and set it to be on and again I'm going to exit and by the way I
04:13already restarted the server so I don't have to restart it again any changes to ht access would
04:18happen automatically as soon as I make those changes all that's left for me to do is to go
04:22back into my browser and click on refresh and now we could see the error exactly the way we wanted
04:29to and if we had there are hundreds of difference of files we wouldn't have to go each file and do
04:33that and this is an example of how you would create a development maybe a staging server
04:39versus a live server and and obviously you would want to password protect that
04:43server so no one has access to it and a really good username and password and then you could
04:48use those errors even on the live site because sometimes you want to see the errors that are
04:52happening on the live site but not the actual production site so there you go and that's how
04:56you play with the ht access and the properties we're not going to go into every single configuration
05:00of PHP but this I think was the most critical one so you know how the process goes and then
05:06you know once you need to change these properties dynamically you'll know how to do it all right
05:11so that's it about PHP and configuring its securities and overriding its configuration
05:16settings we've seen how to do it directly in the config in the php.ini file we saw how to do it
05:22directly using the php underscore ini function and now we've seen also how we could control it using
05:28hctp the server enabling us to override the default settings and going through our our
05:36ht access file that we've just created to add configuration so we've seen all the plethora of
05:40the different options of security and configurations of PHP
