Table of Contents
Install and Configure PHP 7.0.26 On Windows Server
Obtain the PHP Binaries for Your Windows Operating System and the Visual C++ Redistributables for Visual Studio
- Go to http://windows.php.net/download to find and download the appropriate PHP binaries and the corresponding Visual Studio Visual C++ Redistributable.
- If you are planning to use FastCGI support in IIS, which you should for performance purposes, then you should download a Non-Thread-Safe version of PHP. Note that the architecture of IIS and the FastCGI extension provide an isolation model that keeps requests separate, removing the need for a thread-safe version.
- If your Windows Server has a 32 bit operating system, then download the Zip file for VC14 x86 Non-Thread Safe
- If your Windows Server has a 64 bit operating system, then download the Zip file for VC14 x64 Non-Thread Safe
- For example, with a 32-bit server, download the ZIP file for Non-Thread Safe named “php-7.0.26-nts-Win32-VC14-x86.zip” and place the Zip file in a new download folder that you created and named for this purpose
- Unblock the Zip file from Windows access protection (How? Right-click the file and select Properties, then Click the “Unblock” button where is says this file came from another computer, and then click the Apply button)
- Extract the files from this Zip Archive by Right-clicking the Zip File and then left click “Extract All” from the option menu presented
- Click “Extract” button and/or Click “Next” button (to proceed with extracting)
- After extracting, view the root of the extracted files in Windows Explorer. They should be located in the php-7.0.26-nts-win32-VC15-x86 sub-folder. Remember this location for later. You can use a text editor like Notepad++ to view the “Install.txt” file.
Caution - 500 Errors with Newer PHP Builds: Trying to install PHP 7.2 on either Server 2008 SP2 or Server 2008 R2 requires the use of the VC15 Binaries and the corresponding Visual C++ Redistributable for Visual Studio 2017 (rather than Visual Studio 2015). One or both of these, that is either the PHP 7.2.x build or the C++ Redistributable for Visual Studio 2017, seem to be incompatible with IIS7 and/or those older operating systems. When testing the install of PHP 7.2.0 VC15 with the C++ Redistributable for Visual Studio 2017, the IIS 7 displays a 500 Error - Internal Server Error crashing the FastCGI Module. Also on those 2008 operating systems, you may want to avoid PHP 7.1.x as well, even though PHP 7.1.x build uses a VC14 download that corresponds to using Visual C++ Redistributable for Visual Studio 2015 (rather than 2017). 500 Errors may result using the 7.1 Binaries.
Enable FastCGI Role Service for IIS7
- Make sure that you have enabled FastCGI support for IIS7. This is the URL for the source article containing the following listed instructions: https://docs.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-on-iis/enable-fastcgi-support-in-iis-7-on-windows-server-2008-windows-server-2008-r2-windows-vista-or-windows-7
- Note on Prerequisites: If you are enabling FastCGI on Server 2008, you may need to download and install the FastCGI Update for IIS 7 for Windows Server 2008 (KB954946) from here: http://go.microsoft.com/fwlink/?LinkId=131593. This will provide an extra icon for FastCGI Settings in the IIS 7 Management Console. This FastCGI Settings module is in addition to the existing Handler Mappings module.
- Note2 on Prerequisites: You may also need or want to install Microsoft IIS 7 Administration Pack 1.0 (x86) on Server 2008 SP2 (x86) from here: http://go.microsoft.com/?linkid=9655656 - (File Name: AdminPack_x86.msi). When you attempt installation using this *.msi file, an alert box may tell you whether this Package is not suitable for your operating system.
- Begin Instructions to Enable FastCGI Role Service. First, Open the “Server Manager” and, in the left pane, select the icon for “Roles” (but do not +expand roles)
- In the right pane, under Windows Server (IIS), look under the subcategory of Role Services, and click the link on the far right to “Add Role Services”
- Under Application Development category, select the checkbox next to “CGI” for installing the “CGI” role service. This enables both the CGI and the FastCGI services.
- Click the “Next” button to proceed
- Confirm the selections on the Confirm Installation Selection page, and then click the “Install” button
- After the “Progress” indicator shows the conclusion of the installation, you will be presented with the “Results” page, hopefully stating that the “Installation Succeeded”
- Click the “Close” button
Install the Visual C++ Redistributable for Visual Studio 2015
- The “VC14” builds require installation of the Visual C++ Redistributable for Visual Studio 2015 either x64 or x86 depending on whether you are installing the 32bit or 64bit builds of PHP on your Windows server.
- Visual Studio 2015 for X64 (64bit) or for x86 (32bit) may be downloaded here: https://www.microsoft.com/en-us/download/details.aspx?id=48145
- Now install the downloaded Visual Studio 2015 x86 or x64 redistributable by opening or running the file named VC_redist.x86.exe or VC_Resist.x64.exe as the case may require
- Click the checkbox to agree to the license terms for the Microsoft Visual C++ 2015 Redistributable (x86), and click the “Install” button
- When the prompt states “Setup Successful,” click the Close button
- At this point, maybe restart the IIS service
- -Using Windows Explorer, make a new folder named “php” at the root of the C:\ drive. Namely, c:\php
- Copy all of the extracted files and folders from the source “php-7.0.26-nts-win32-VC15-x86” sub-folder that you just extracted and paste them into the c:\php folder. In other words, the c:\php folder is the selected target folder of the copy routine.
Configure the php.ini File
- In the c:\php folder, open the php.ini-production file using a good text editor like Notepad++ and then “save as” the contents of this file using the new file name “php.ini” and then close (x) both the php.ini-production file (tab) and the new php.ini file (tab) from within Notepad++.
- Re-open the php.ini file using Notepad++ text editor and then un-comment and modify certain settings within php.ini as follows:
- Set fastcgi.impersonate = 1 ;REMARK FastCGI under IIS supports the ability to impersonate security tokens of the calling client. This allows IIS to define the security context that the request runs under.
- Set cgi.fix_pathinfo = 0 ;REMARK The cgi.fix_pathinfo provides PATH_INFO/PATH_TRANSLATED support for Common Gateway Interface (CGI). Setting this to 1 will cause PHP CGI to fix its paths to conform to the specification.
- Set cgi.force_redirect = 0
- Set open_basedir = a path pointing to a folder or network path where the content of the Web site(s) is located. (Such as c:\hostdata), or just leave it commented like this “;open_basedir =” without the quotes
- Set extension_dir to point to a location where PHP extensions reside. This is typically extension_dir = “./ext” However, per php.ini-production in both PHP7 and PHP8 it says for “Windows” to set it as follows: extension_dir = “ext”
- Set error_log=“C:php_errors.log” ;REMARK This can help with troubleshooting. Alternatively, set error_log = “c:\php\logs\errors_log” and make a new sub-folder in c:php named “logs” and grant the sub-folder “logs” full control write access for both IUSR and IIS_USERS.
- Enable the required PHP extension by un-commenting the appropriate lines within the extensions section of the php.ini file. See a further discussion of which extensions to enable.
Set the appropriate paths in the System Environment Variables
- Click on Start, Settings, Control Panel, and then double-click on the System icon (using the class view).
- Click on the Advanced system settings link in the left column.
- From the System Properties window, click on the Advanced tab, and then click on the Environment Variables button at the bottom.
- Select the Path variable from the System Variables section, and then click on Edit. Add/Insert: c:\php to your system path. Insert a screen capture here depicting Edit System Variable. Variable Name: Path and Variable Value C:\Windows\system32;C:\Windows;(etc;)C:\php
- Click OK until you have exited the System Properties window.
Configure Handler Mappings for FastCGI Module in IIS Manager
- Start IIS Manager by clicking on Start, Programs, Administrative Tools, and then Internet Information Services (IIS) Manager.
- From the IIS Manager, click on the hostname of your server in the Connections panel on the left.
- Double-click on the Handler Mappings icon. Insert a screen capture here depicting IIS and handler mappings
- From the Handler Mappings Actions panel, click on Add Module Mapping.
- Type the following information into the appropriate text boxes, and then click OK. Request path: *.php then Module : FastCGImodule then Executable: C:\php\php-cgi.exe then Name: FastCGI (insert a screen capture depiction here)
- Click OK, and then click Yes.
Configure the default PHP documents in IIS Manager
- In the left panel, click on your server's hostname, and then double-click on the Default Document icon.
- From the Actions panel on the right, click Add.
- Enter index.php as the new default document name, and then click OK.
- Enter default.php as the new default document name, and then click OK.
- In the left panel, click on your server's hostname.
- In the Actions panel on the right, click Restart.
Test Your PHP Installation
- Create a new text document, and save it as c:\inetpub\wwwroot\phpinfo.php with the following content:
<?php phpinfo(); ?>
- You can now go to your web browser and see php information at:
http://localhost/phpinfo.php
If you have Windows Server 2008 without service pack 2 installed, then you may want to download and install Windows Server 2008 Service Pack 2. See: https://www.microsoft.com/en-us/download/confirmation.aspx?id=16468