Installing PHP on Windows

From PGVWiki
Jump to navigation Jump to search

This document will help you to get PHP installed on Windows and running in your web server.

Getting PHP

  1. Download the binary MSI or ZIP package of the latest PHP release from http://www.php.net/downloads.php
  2. If you install PHP from the MSI installer, make sure you select to install the GD2 and the MySQL extensions.
  3. If you don't use the installer then you will need to extract the ZIP to C:\PHP
  4. To run PhpGedView, we need to enable some optional extensions:
    1. From the C:\PHP\ext directory copy the following files up one level into the C:\PHP directory
      • php_gd2.dll
      • php_mysql.dll (Only if you are using PHP 5)
      • php_mssql.dll (If you want to run PHP with MS SQL Server)
    2. Edit the php.ini file: If php.ini does not exist then copy the php.ini-dist file to php.ini
      1. To uncomment a line, remove any leading semicolons from that line.
      2. Uncomment the line extension=php_gd2.dll
      3. For PHP 5, uncomment the line extension=php_mysql.dll
      4. For SQL Server support, uncomment extension=php_mssql.dll
      5. If installing in IIS using CGI mode as described below, change the line ;cgi.force_redirect = 1 to cgi.force_redirect = 0. Note that the line has been uncommented as well as edited.
      6. Sometimes when running PHP in CGI mode on IIS you will get a "threads exited" error at the bottom of the page. This is a bug in the latest libmysql.dll that comes with PHP. You will need to replace this DLL with one from an older version of PHP 5.2.1 or with one from the mysql directory.
  5. The latest versions of PHP come with display_errors in the php.ini set to off which will likely cause you not to see any errors during your development. You probably want to set display_errors = On.

Enable PHP in your Web server

Enabling PHP in IIS

  1. Modify the Windows PATH environment variable to include the PHP directory. This way the PHP DLL files, PHP executables, and php.ini can all remain in the PHP directory without cluttering up the Windows system directory. Control Panel -> System -> Advanced tab -> Environment Variables
  2. Associate IIS with PHP
    1. Open the Internet Information Services Manager
    2. Open the Control Panel, open Administrative Tools, and then open Internet Information Services
    3. Expand the tree on the left until you see Default Web Site. Right click on Default Web Site and choose Properties
    4. Under the Home Directory tab, set the Execute Permissions setting to Scripts only
    5. Click on the 'Configuration' button, and choose the Application Mappings tab.
    6. Click Add and set the Executable path to the c:\php\php-cgi.exe. Supply .php as the extension. Check the 'Script engine' checkbox. Now, click OK a few times until you get back to the Home Directory tab.
    7. Switch to the Documents tab and add index.php to the list of Default Documents.
    8. Click OK
  3. Stop and start the Default Web Site
    1. Right-click the Default Web Site, and click stop
    2. Right-click the Default Web Site, and click start
  4. For more detailed instructions, see the install.txt file in the C:\php directory.

Enabling PHP in Apache 2

  1. Edit the httpd.conf file and add the following lines:
# For PHP 5 do something like this:
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php

  1. configure the path to php.ini
PHPIniDir "C:/php" 
  1. Add index.php to the DirectoryIndex
DirectoryIndex index.html index.html.var index.php
  1. Stop and start the apache service
  2. For more detailed instructions, see the install.txt file in the C:\php directory.

Test your PHP installation

  1. Go to your web document root.
    • Should be C:\inetpub\wwwroot for IIS
    • Should be C:\Program Files\Apache Software Foundation\Apache 2\htdocs for Apache 2
  2. Create a new text file named phpinfo.php and put the following line of code in it:
    <?php phpinfo(); ?>
  3. Open a web browser and go to http://localhost/phpinfo.php. You should see a long page detailing your PHP configuration. Clipboard01.png
  4. Scroll down the page and make sure that you find a section on gd, mysql or mssql. If you don't see these sections, then go back and check you php.ini file again.