PHP ini settings

Sometimes setting up PHP on your own Windows machine can be a bit of a pain. However, add a few lines of code to the php.ini file that comes with the default installation of the windows binaries of PHP v4x and above and things become a whole lot easier.

Requirements:

  • Windows 2000 or XP
  • Apache 2.0x installed
  • PHP, any version (4x + ) but not the installer package

This assumes that Apache has been installed and a PHP version has already been downloaded and extracted as per the details in this article.

If you followed the steps exactly, when you viewed your info.php file, you might have noticed a few strange things.

By default, PHP looks for the php.ini looks in X:\WINDOWS if it is not specified previously or if the file does not exist in the PHPIniDir set in Apache's httpd.conf. As the PHP distribution doesn't have a php.ini, you need to create one (see below) then PHP is getting its settings from a file doesn't exist. This means extensions won't work and we need to create a new file.

Open up your php.ini-dist file in a text editor, wordpad or notepad, and add a few lines. The file, from the installation detailed in the previous article, is found in the X:\Program Files\Apache Group\php\php-5.2.0-Win32 folder.

Note that there are many settings that can/should be tweaked, but some of the basic settings to check are:

  • Temp directories
  • E-mail Settings
  • Extensions directories
  • Include path
  • Document Root

doc_root setting is something that may or may not make a difference to your set up. You can leave it as is, or change it to your servers document root.

doc_root = "X:/Program Files/Apache Group/Apache2/htdocs"

Temp directories are important as PHP uses the system temp directories unless otherwise stated. I created a temp directory in my Apache Group folder and pointed upload_tmp_dir and session.save_path to this directory.

upload_tmp_dir = "X:/Program Files/Apache Group/tmp"
session.save_path = "X:/Program Files/Apache Group/tmp"

To allow the mail() to have a chance of working correctly without having a mail server installed on your PC, you need to modify the mail settings.

[mail function]
; For Win32 only.
SMTP = smtp.your_service_provider.com
smtp_port = 25
;
; For Win32 only.
sendmail_from = webmaster@your_domain.com

The final change and possibly the most important is to set the extensions path so PHP knows to look for all the add-ons. In PHP4 this folder was called "extensions". In PHP it is named "ext".

extension_dir = "X:/Program Files/Apache Group/php/php-5.2.0-Win32/ext"

A couple of extra settings that I use are as follows. Ensure that the files actually exist first before changing these lines. Each entry on a separate line.

mime_magic.magicfile = "X:/Program Files/Apache Group/php/php-5.2.0-Win32/extras/magic.mime"
browscap = "X:/Program Files/Apache Group/php/php-5.2.0-Win32/extras/browscap.ini"

That should be all you need to do. Left-click the Apache monitor icon that should be in your task-bar and press restart. Open http://localhost/info.php in your favorite web browser. You should now see your PHP information nicely displayed on screen with the correct php.ini information.

One final step related to PHP is to set your path in your computer's system variables. This can be done by opening up SYSTEM PROPERTIES by right clicking on your "My Computer" icon on your desktop. Click on the ADVANCED tab. You should now see a couple of buttons towards the bottom of the screen. Press the ENVIRONMENT VARIABLES button.

In the bottom of the two areas displayed, highlight path. This will, or should at least, contain things like %SystemRoot%\system32; and other paths separated by ;. At the end of the list add the following noting the ; at the beginning as the separator.

;X:\Program Files\Apache Group\php\php-5.2.0-Win32

That's it. This allows multiple instances of PHP to be installed on your PC that shouldn't interfere with each other. If you notice that certain PHP modules aren't loading, try copying them to one directory up.

Syndicate content