Being able to work with the php.ini file goes along way towards mastering PHP. If you are developing scripts on your own PHP-enabled computer or if you have administrative level control over your server, you can globally change how your PHP installation runs.
Common settings you might want to adjust include:
Keep in mind that PHP is installed with the settings that the developers think are best. Changing any particular setting may make it easier to learn the language but at the cost of security or performance. That being said, I present to you…
Steps for editing your php.ini file:
- Create a script called phpinfo.php containing the following code:
<?php phpinfo(); ?>
- Place this script on your server.
- Run this script in your Web browser by going to http://your.url.here/phpinfo.php in your Web browser (on your own computer, this may be something like http://localhost/phpinfo.php or http://localhost/~username/phpinfo.php).
- In the resulting page, look for the line which says “Configuration File (php.ini) Path”. It should be about 6 rows down in the table.
- Note the location of your php.ini file. This is the active file PHP is using. Your server may have multiple php.ini files on it but this is the one that counts.
- If you don’t have a php.ini file on your server (if the value is blank in the phpinfo.php script or if you go to the directory it lists and there’s no php.ini file there), create one by:
- Downloading the complete source code from http://www.php.net/downloads.php.
- Extract the source (unzip or whatever)j so that you now have a folder of files.
- Find the php.ini-dist file, located within the main folder.
- Rename this file as php.ini and move it to the proper directory.
- Open the php.ini file in a text editor (don’t use Notepad, Word, TextEdit, or any other text editor which will not properly display line or will not let you save a plain text file).
- Make any changes you want, keeping in mind the following:
- Comments are marked using a semi-colon. Anything after the semi-colon is ignored.
- Instructions on what most of the settings mean are included in the file.
- The top of the page lists general information with examples. Do not change these values. Change the settings where they appear later in the file.
- For safety purposes, don’t change any original settings, just comment them out (by preceding the line with a semi-colon), then add the new, modified line afterwards.
- Add a comment (using the semi-colon) to mark what changes you made and when. For example:
; register_globals = Off register_globals = On ; Added by LEU 4/8/2004
- Save the file.
- Restart the Web server (Apache, IIS, Xitami, etc.). You do not need to restart your whole computer.
- Rerun the phpinfo.php script to make sure the changes took effect.