PHP Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 3.00

Adding PHP to IIS as CGI

This section provides a tutorial example on how to add the PHP engine to the IIS server to serve PHP scripts as Web pages.

If you want to add PHP scripts to your IIS server to serve as Web pages, you need to add the PHP engine to the IIS server as a CGI interface.

1. Add \php to the PATH environment variable. I assume you know how to do this.

2. Set up PHP configuration file. First copy \php\php.ini-recommended to \php\php.ini. Then edit \php\php.ini to set the following values:

cgi.force_redirect = 0
doc_root = "c:\inetpub\wwwroot"
cgi.redirect_status_env = ENV_VAR_NAME

3. Create a new environment variable PHPRC with \php. This is needed to access php.ini.

4. Now we need to change IIS configuration to run PHP scripts as CGI scripts. Click Control Panel, Internet Information Service (IIS), Default Web Site, and Properties. On the Directory tab, first set Execute Permissions to "Scripts only". Then click Configuration to add a new Application Mapping with Executable=\php\php-cgi.exe, Extension=.php, and Script engine checked.

5. Stop and start Default Web Site in IIS.

6. Copy Hello.php to \inetpub\wwwroot.

7. Run Internet Explorer (IE) with http://localhost/Hello.php. You should see:

Hello world!

Congratulation, you have added PHP to IIS as CGI correctly!

Last update: 2007.

Sections in This Chapter

What Is PHP?

Downloading and Installing PHP 5.0.4 for Windows

Downloading and Installing PHP 5.2.2 for Windows

"php -help" - Command Line Options

"php -m" - Compiled-in Modules

"php -i" - PHP Engine Information

Hello.php - My First PHP Script

Adding PHP to IIS as CGI

Dr. Herong Yang, updated in 2009
Adding PHP to IIS as CGI