Configuring PHP with Apache on Windows Vista

Pre-requisites:

  1. Follow my instructions on installing Apache on Windows Vista
  2. And then follow my instructions on installing PHP on Windows Vista

Installing PHP with Apache on Windows Vista is a relatively simple task until you try an configure the settings in php.ini. Problems can occur and stem from the fact that when you install PHP and edit the php.ini file, you need to not only be logged in as Administrator, but run the installer and Notepad text editor as Administrator. The php.ini file also needs to be located in the Windows directory.

Below is an outline of the steps to get your PHP installation running and configured correctly.

  1. Run Notepad as Administrator. Go to All Programs > Accessories Right-click “Notepad” and select “Run as Administrator”. Open the php.ini file, in my case:
    C:\PHP5\php.ini
  2. Edit the php.ini file as necessary, e.g.:
    extension_dir = "C:\PHP5\ext"
    upload_max_filesize = 16M
    upload_tmp_dir = "C:\PHP5\upload"
    session.save_path = "C:\PHP5\session"
  3. Enable the extensions you need by deleting the semi-colon at the beginning of the line. For example, you will commonly need the following MySQL extensions:
    extension = php_mysql.dll
    extension = php_mysqli.dll
  4. Save the edited php.ini file into your Windows directory. This is very important as Vista will not read the changes but will refer to the default settings.
  5. Check that the PHP directory has been added to your computers “Environment Variables”. Click Start, right-click on Computer, select Properties > Advanced > Environment Variables. Click on PATH and select Edit. If the PHP path is there, in my case “C:\PHP5\”, all is well, otherwise add the PHP path.
    • System Properties:

      Vista System Properties

    • Environmental Variables

      Vista Environment Variables

    • Edit Environmental Variable - PATH

      Vista Edit Environmental Variable PATH

  6. Open your Apache configuration file (httpd.conf). Ensure the following lines are present (at the bottom of the file):
    LoadModule php5_module "C:\PHP5\php5apache2_2.dll"
    AddType application/x-httpd-php .php
    AcceptPathInfo on
    PHPIniDir "C:\Windows"

    If there are additional LoadModule lines, remove them, leaving only the one that relates to your version of Apache.

  7. Find the DirectoryIndex in the Apache config and append index.php, e.g.:
    <ifmodule dir_module>
    	DirectoryIndex index.html index.php
    </ifmodule>
  8. Restart the Apache service.
  9. Create a index.php file in your webroot and add the following lines:
    < ?php phpinfo(); ?>
  10. Navigate to the file (e.g. http://localhost/index.php) and you will be presented with all the PHP and server settings. You’re now good to go.


About this entry