Installing PHP on Windows
Jump to navigation
Jump to search
This document will help you to get PHP installed on Windows and running in your web server.
Contents
Getting PHP
- Download the binary MSI or ZIP package of the latest PHP release from http://www.php.net/downloads.php
- If you install PHP from the MSI installer, make sure you select to install the GD2 and the MySQL extensions.
- If you don't use the installer then you will need to extract the ZIP to C:\PHP
- To run PhpGedView, we need to enable some optional extensions:
- 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)
- Edit the php.ini file: If php.ini does not exist then copy the php.ini-dist file to php.ini
- To uncomment a line, remove any leading semicolons from that line.
- Uncomment the line extension=php_gd2.dll
- For PHP 5, uncomment the line extension=php_mysql.dll
- For SQL Server support, uncomment extension=php_mssql.dll
- 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.
- 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.
- From the C:\PHP\ext directory copy the following files up one level into the C:\PHP directory
- 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
- 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
- Associate IIS with PHP
- Open the Internet Information Services Manager
- Open the Control Panel, open Administrative Tools, and then open Internet Information Services
- Expand the tree on the left until you see Default Web Site. Right click on Default Web Site and choose Properties
- Under the Home Directory tab, set the Execute Permissions setting to Scripts only
- Click on the 'Configuration' button, and choose the Application Mappings tab.
- 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.
- Switch to the Documents tab and add index.php to the list of Default Documents.
- Click OK
- Stop and start the Default Web Site
- Right-click the Default Web Site, and click stop
- Right-click the Default Web Site, and click start
- For more detailed instructions, see the install.txt file in the C:\php directory.
Enabling PHP in Apache 2
- 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
- configure the path to php.ini
PHPIniDir "C:/php"
- Add index.php to the DirectoryIndex
DirectoryIndex index.html index.html.var index.php
- Stop and start the apache service
- For more detailed instructions, see the install.txt file in the C:\php directory.
Test your PHP installation
- 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
- Create a new text file named phpinfo.php and put the following line of code in it:
<?php phpinfo(); ?> - Open a web browser and go to http://localhost/phpinfo.php. You should see a long page detailing your PHP configuration.
- 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.