What do we have in this session?
Running PHP Commands from Windows Console
The following screenshots show running php on Windows command prompt.
For more readable version, you can redirect the output to a text file using the following command.
C:\>php -i > php_info_test.txt
Our PHP seems to be configured correctly. At least from configuration point of view and try running the following command.
C:\>php-cgi -v
This should print the PHP version if run from command prompt.
Configuring IIS to Parse PHP files/extensions using FastCGI
Next, let configure IIS so that it will recognize and parse any PHP files. Open IIS snap-in, select the Default Web Site > right-click mouse > select Properties menu. This task will sets up IIS to actually respond to requests for php files. Until now, IIS hadn't known what to do with php files, we just told it to pass them through php-cgi.exe (previously using the DLL. We have tested using php5isapi.dll however it failed!)
Select Home Directory tab and click Configuration button.
In the Mappings page, click Add button.
Click the Browse button to select the DLL/EXE.
Select php-cgi.exe executable file and click Open button.
In the Extension field, fill in .php for PHP file/extension and in Verbs group box, select Limit to: and type GET, POST, HEAD. You can select All Verbs which should tally with your needs. The GET, POST and HEAD verbs (HTTP methods) will give us the most basic functionalities. Click OK button.
Now, IIS should 'understand' file with PHP extension. Click OK button.
Restart the IIS service.
Testing the IIS Web Server with PHP Files
Let test the PHP engine. Create an index.php file with the following code and save it in ANSI format.
<?php
phpinfo();
?>
Or the index.html file (with PHP code) with the following code.
<html>
<head>
<title>PHP Test Page</title>
</head>
<body>
<?php phpinfo(); ?>
</body>
</html>
<? phpinfo(); ?> doesn't work because short_open_tag parameter was off by default in php.ini.
Blank Webpage Problem
Open the page from Internet browser. Well, we have some problem with both IE and Firefox, an empty or blank page. Take note that the default first web page should be index.html in this case.
------------------------------------------------------------
---------------------------------------------------------------------------
Let check the source.
The source was not stripped.
Let check the World Wide Web Service (W3SVCx) log file.
The returned code is 200 (200 means OK. The client request has succeeded) and this should be fine. Then, what is the problem?
Let add the .html mapping to php-cgi executable in IIS so that the php-cgi can parse the html file. Repeat the previous steps and used .html as the extension instead of .php.
Use .html as the extension.
Now, php-cgi.exe can parse both .HTML and .PHP files. Click OK button.
Restart the IIS service.
Re-check the default first web page.
Working PHP Engine Example
Reload the web page through Internet browser. Well, it works!
Then, test the index.php file. It also works!
We can test the web page directly from IIS snap-in as shown in the following snapshot.