Join David Powers for an in-depth discussion in this video Changing configuration settings in php.ini, part of Introducing PHP.
- You've seen how to check the configuration of your server using phpinfo. If you need to make any changes, you need to edit the PHP configuration file, php.ini. The location of the file depends on your server. It's listed here as Loaded Configuration File so that's the location of php.ini on my server. You also need to check this value here, Additional .ini files parsed. Usually, the value is none, as it is here.
But it's possible that something else is overriding values in the main configuration file. We'll come back to that later. First, let's deal with the main version of php.ini that's listed as the Loaded Configuration File. php.ini is just a plain text file so you need to open it in a text editor. In Windows, double-clicking the file in the File Explorer automatically opens it in Notepad. On a Mac, it doesn't have a default program to open it.
So I'm going to use this program, TextWrangler, which is a free script editor for the Mac that you can download from www.barebones.com. But if you're on Windows, Notepad is just fine. And because I've been working with php.ini, it's already loaded it into TextWrangler. Lines that begin with semicolons, like all of these lines here, are comments. The configuration commands are on lines that don't begin with a semicolon.
And because it's such a long file, it's best to use the script editor search command to find the configuration setting you're looking for. I'm going to search for error_reporting and then click Next. Here is a line that begins with a semicolon, so that's a comment, that's not what we want. Let's search for the next one. This line here doesn't begin with a semicolon so this is the actual command.
The value of error_reporting is set to E_ALL, all in uppercase. This is a PHP constant so it must be always in uppercase. And this is the value that you should have. This results in even minor errors being reported. Some developers prefer a less strict level but I think it's very important to see every error message, particularly when you're learning. So make sure that that is set to E_ALL.
The next thing that we need to look at is display_errors. And that's actually very close by. Here it is. In my version, display_errors equals On. That's what we want in a local testing environment. Now, the default value in MAMP is off so you must change this to on. The last configuration command you might need to change is date.timezone so let's search for that. This is on a comment line but the next line doesn't have a semicolon at the beginning so that's the actual value.
So date.timezone, I've set it to Europe/London. The value is normally a continent or ocean followed by a slash and the name of a city. This is because PHP automatically adjusts for daylight saving time. You can find the correct timezone setting for your location in the PHP online documentation. Let's take a look at that. This is a list of all the supported timezones in PHP. There's a very large number of them and they're all organized geographically.
America covers the whole of the American continent, North, South and Central. Something which is important to realize about America is that it doesn't include offshore islands. For example, if you're in Hawaii, you actually have to look in Pacific because that's where Hawaii is listed. Europe, that lists most of the countries in Europe but some offshore islands are listed as being in Atlantic. Find the correct location and then change the value of date.timezone in your php.ini.
When you've made the changes, save php.ini and restart the web server then reload the script that runs phpinfo. This is phpinfo here, and when you've made the changes, you should be able to see the changes reflected in here. Those changes will normally be relisted in Core under Local Value, or in the case of date, also under Local Value but of course not in the Core section, it's in the Date section.
However, if the changes didn't take effect and the file is listed alongside Additional .ini files parsed, that was up here at the top, if you've got a different file listed here, then locate that file and make the changes there too. Making changes to your testing server configuration through editing php.ini sounds a daunting prospect because it's such a long file, but it's really quite simple. Just make sure you edit the configuration settings on lines that don't begin with a semicolon.
And don't forget to restart your web server after making the changes.
- 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