Using ZendPHP with Microsoft IIS
Internet Information Services for Windows Server (IIS) is an extensible web server for hosting your web site using ZendPHP.
Prerequisites
Before you follow this tutorial, verify that you fulfill the following prerequisites:
-
Install IIS with the "FastCGI" feature enabled. For more information, see Build a PHP Website on IIS (learn.microsoft.com).
In this tutorial, we assume that the NTS build of ZendPHP is installed in C:\Program Files\Zend\ZendPHP
.
Identify the file locations
In the following table, <x.y> stands for the major.minor version number, such as 8.2.
Setup item | ZendPHP MSI installation | Command line installation |
Base installation path | "C:\Program Files\Zend\ZendPHP\<x.y>" | C:\zendphp\<x.y> |
php-cgi.exe | "C:\Program Files\Zend\ZendPHP\<x.y>\php.cgi.exe" | C:\zendphp\<x.y>\php.cgi.exe |
php.ini | "C:\Program Files\Zend\ZendPHP\<x.y>\etc\php.ini" | C:\zendphp\<x.y>\php.ini |
conf.d directory | "C:\Program Files\Zend\ZendPHP\<x.y>\conf.d\" | C:\zendphp\<x.y>\etc\conf.d\ |
Plan and Prepare your application setup
Set up the location for the PHP scripts and prepare the web site for this specific PHP application.
Some examples for web server application setup choices:
-
single application directory per server?
-
multiple application directories for a single site?
-
virtual hosts (hosting separate applications on a single web server instance for multiple host names)?
-
separate port numbers for different applications?
-
and combinations of all above
For more information, see Plan IIS and PHP installation (learn.microsoft.com).
Handler Mapping
To set up the handler mapping for PHP:
-
Open IIS Manager and select the hostname of the computer in the Connections panel.
-
Navigate to your specific web site in the navigation tree (left side of the IIS Manager window).
-
Double-click Handler Mappings.
-
Verify that there is no handler already set up for the Path *.php.
If there is already a handler specified, then make sure you have selected the correct web site and remove the existing handler for *.php items.
This action removes your existing PHP executable from the selected web site configuration. This is a destructive action that may break your existing web site. -
In the Action panel, click Add Module Mapping.
-
Under Request path, type
*.php
. -
From the Module menu, select
FastCGIModule
. -
Under Executable, type the following path. Enter the PHP major and minor version in place of
{MAJOR_VERSION}.{MINOR_VERSION}
, for example,8.2
or7.4
. Include the quotation marks."C:\Program Files\Zend\ZendPHP\{MAJOR_VERSION}.{MINOR_VERSION}\php-cgi.exe"
-
Under Name, define a free-form name for your module mapping. As a best practice, include the version number and ZendPHP name.
For example,ZendPHP-8.2-FastCgi
. -
Click OK to save the settings.
For more information, see IIS Handlers (learn.microsoft.com) and Install IIS and PHP (learn.microsoft.com).
FastCGI Configuration
-
Open IIS Manager and select the hostname of the computer in the Connections panel. The one at the root level of the tree, not the web site.
-
Edit the FastCGI Settings.
-
Find the item pointing to the php-cgi.exe for this specific setup. If the entry is missing, verify you have performed the Handler Mapping procedure.
-
Edit the environment variables.
-
Add two environment variables and set them to your PHP installation paths. Ensure that you enter the path for your PHP version installation here, the examples use 8.2.
Name Example value Description PHPRC C:\Program Files\Zend\ZendPHP\8.2\etc\php.ini Path to the php.ini file for the specific installation. PHP_INI_SCAN_DIR C:\Program Files\Zend\ZendPHP\8.2\etc\conf.d Path to the directory for additional configuration files. Those are the ini files for the loadable php extensions. -
Save the changes.
Configure PHP Extension location
Configure the directory where the PHP extensions are stored:
-
Open the php.ini file in a text editor.
-
Change the following line:
extension_dir = "ext"
-
Save the file.
Configure Permissions
Update the file access permissions for the C:\Program Files\Zend\ZendPHP\var\*
directories so that "Users" have Write access:
-
Open the Terminal.
-
Enter the following command:
cacls.exe "C:\Program files\Zend\ZendPHP\var\*" /e /p Users:f
Default Document
Optionally, set up index.php
as a default document:
-
On the Connections panel, double-click Default Document.
-
In the Action panel, click Add.
-
Under Name, type
index.php
and then click OK. -
Click Add again. Under Name, type
default.php
, and then click OK.
Verify the installation
-
Add a new file named index.php in your newly created web site directory.
-
Enter the following text content into this file:
<?php phpinfo(); ?> -
Open the web page for this site in your web browser.
If the PHP information page is displayed, the set up was sucessful.