Join David Powers for an in-depth discussion in this video Running phpinfo() to check the PHP configuration, part of Introducing PHP.
- I assume that you've already installed a testing server and are raring to go. Before we can start, it's important to make sure we're all using the same basic settings. So we're going to run a very simple PHP command to inspect how PHP has been configured. Fire up your editing program. I'm using PHP Storm, and I've already set up a project to save all of my files in the introducing PHP folder in my server document route. Create a blank file. I'm going to create it in the ch01, 01_01 folder.
And I'm going to call it config.php. My editing program automatically adds the .php on the end of the file name, and it also inserts the PHP opening tag on the first line. If your editing program adds HTML code, delete all of the HTML and replace it with this opening PHP tag on the first line. It's an opening angle bracket, or <, a ?, and then php.
Make sure there are no spaces between any of the characters. Then insert a space after the opening PHP tag and type phpinfo followed by () and a ;. That's all we need to type. There won't be any of a script in this file, so we don't need a closing php tag, but it doesn't matter if you add one. Just save the page and then load it into a browser. Now I can load directly from my editing program, but if necessary, if you've set up the same as I have, the URL in your browser will be localhost/introducingphp/ch01 /01_01/config.php.
And this configuration page contains a huge amount of information. And the contents will differ depending on how your server has been set up. If you've never used PHP before, this can seem like information overload. Fortunately, you don't need to worry about most of it. Let's just highlight some of the most important points. Right at the very top is the PHP version number. I'm using PHP version 7.0.0RC4.
RC stands for release candidate. I recorded this course shortly before the final release of PHP 7, so the version I'm using contains exactly the same features as the final release, but it was still going through some final quality tests. The final release of PHP 7 should be available by the time you watch this. You don't need to be using PHP 7 yourself, but do make sure that the version is not less than PHP 5.4. There were important changes in PHP 5.4, and if you're using an older version, some of the code in this course won't work.
Now halfway down the screen here is Loaded Configuration File. This is the location of the main configuration file, php.ini. You need to make a note of the location because you might need to edit it. So this is where my php.ini is. That's the active version of php.ini. Then let's scroll down, and this configuration section lists in alphabetical order all of the features enabled on your server.
The one that we want to look at is called call. So let's just scroll down, and here we are, call. What we want to look at in here is this one here, display_errors. This tells you whether error messages are displayed on screen, and the value that you need to look at is the one listed under Local Value. And in my case, it's on. That's exactly what we want. If it's set to off in your system, some errors will result in a completely blank screen.
In a live website, that's exactly what you want. Displaying errors can reveal information that could expose you to malicious attacks. However, in a testing environment, it's vital to see all error messages. So if display_errors is set to off on your local computer, you'll need to change this setting as described in the next video. Then the next thing we need to look at is error_reporting. It's this one here. And it's a numeric value, and it should be set to 32767 as shown here.
If it shows a lower value on your system, follow the instructions in the next video. And there's one other setting that you should check. It's a bit further down. It's in the date section. Let's just find that. Here we are, date. Make sure there's a value for Default timezone. I'm based in the UK, so I've set it on my system to Europe/London. If the timezone is wrong for your location, time and date functions will display the wrong values.
So that's all we need to do. Those are the most important settings. If you ever ask for help with a PHP feature not working as expected, the first question you're likely to be asked is whether you've run php info to check if a feature is enabled. Although this page feels overwhelming when you first start out, you'll quickly learn to value the insight it gives you into your service configuration. In the next video, I'll show you how to change the configuration settings on your server.
- Naming variables
- Storing text as strings
- Doing calculations with PHP
- Using conditional statements to make decisions
- Creating custom functions
- Deciphering error messages
- Emailing the contents of an online form
- Dealing with multiple-choice form fields