How to edit php.ini file?

September 1, 2007 / Web Hosting

What is the php.ini file?

Php.ini file is an important configuration file of your PHP server.

How a php.ini File is read?

When the PHP interpreter starts, it acts according to settings specified in any available php.ini file. The Web server will look for this file in the following locations and in the following order:

  • The directory from which the PHP script was called
  • The root of your Web directory (typically public_html)
  • The Web server’s default php.ini

To be able to work with PHP you need to be a master in that. If you are developing scripts on your own PHP is enabled computer or if you have administrator-level control over your server, you can globally change how your PHP installation runs.

These are the common settings you might want to adjust include:

  • register_globals
  • display_errors
  • error_reporting
  • magic_quotes_gpc

You should keep in mind that PHP is installed with the settings that the developers think are best. Changing any single setting may make it easier to learn the language but at the cost of security or performance.

Where is this php.ini file located?

Thie php.ini file location depends on many things: if you are using Windows or Linux, where you installed your webserver, … the file is always located on the server where the scripts of Claroline will run.

You can find the php.ini location by using the following command:

phpinfo();
?>
How to edit php.ini file ?

These are the following steps to edit a php.ini file:

  1. First find the location of the php.ini file
  2. Place this script on your server.
  3. Run this script in your Web browser by going to http://anyofyour.url.here/phpinfo.php in your Web browser (on your own computer, this may be like http://localhost/phpinfo.php or http://localhost/~username/phpinfo.php).
  4. On the result page, look for the line which says “Configuration File (php.ini) Path”. It should be about 6 rows down in the table.
  5. Note the location of your php.ini file. It is the active file PHP is using. Your server may have multiple php.ini files on it but this is the one that counts.
  6. 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 it one by one :
    1. Download the complete source code from http://www.php.net/downloads.php.
    2. Extract the source (unzip or whatever)j so that you now have a folder of files.
    3. Find the php.ini-dist file, located in the main folder.
    4. Rename this file as php.ini and move it to the proper directory.
  7. Open the php.ini file in a text editor (do not 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).
  8. Make the changes you want, keeping in mind the following:
    1. Comments marked using a semi-colon(;). Anything after the semi-colon is ignored.

    2. Instructions on what most of the settings mean included in the file.

    3. 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.

    4. Note for safety purposes, do not change any default settings, just comment them out (by preceding the line with a semi-colon), then add the new, modified line afterward.

    5. 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 1/9/2007

  9. Save the file.
  10. Restart the Web server (Apache, IIS, etc.). You do not need to restart your whole computer.
  11. Rerun the phpinfo.php script to make sure the changes took effect.

Hope you have understood How to edit the php.ini file? For assistance contact the bodHOST support team which is available just for you 24×7.