Web/Database environment using IIS and SQL Server.
2. | Running ASP.NET, PHP and Perl scripts on Microsoft IIS. | |
---|---|---|
In part 1 of my IIS and SQL Server tutorial, I showed how to install and configure IIS 8.5 on Windows 8.1. This part of the tutorial shows how to run scripts written in ASP.NET, PHP and Perl. It is supposed that you have IIS installed and properly running... | ||
ASP.NET. | ||
Running ASP.NET scripts on IIS should work "out of the box": Write your code, copy it into some directory accessible by the web server and that's it! | ||
Here is the code of a simple ASP.NET script, that transforms the text entered by the user into uppercase. | ||
<!-- directives --> <% @Page Language="C#" %> <!-- code section --> <script runat="server"> private void convertoupper(object sender, EventArgs e) { string str = mytext.Value; changed_text.InnerHtml = str.ToUpper(); } </script> <!-- Layout --> <html> <head> <title> Change to Upper Case</title> </head> <body> <h3> Conversion to Upper Case</h3> <form runat="server"> <input runat="server" id="mytext" type="text" /> <input runat="server" id="button1" type="submit" value="Enter..." OnServerClick="convertoupper"/> <hr /> <h3> Results:</h3> <span runat="server" id="changed_text" /> </form> </body> </html> |
||
I named the script test_asp.aspx and copied it to the Document root of my ISS. To run the script, type the following in the address bar of your web browser: localhost/test_asp.aspx or using the computer name: http://wk-win81g/test_asp.aspx |
||
The screenshot shows the result (after the text has been entered and after the button has been pushed). | ||
|
||
PHP. | ||
Using PHP on IIS is similar as on Apache, maybe somewhat more complicated. Also, I think that I have read somewhere that up from version 8, PHP is no longer supported by Microsoft (?). | ||
On my Windows 8.1, I actually use PHP 7.4 (64-bit) that you can download from windows.php.net. Be sure to download the non-thread safe version (the thread safe version is intended to be used with Apache). The download is a ZIP archive; unpack the files in some folder, such C:\Progs\php. Be sure to add this folder to the PATH system environment variable. | ||
The screenshot shows the content of the PHP installation directory. | ||
|
||
PHP requires the C++ runtime of the version of Visual Studio that it has been built with. The easiest way to have the correct runtime present on your computer is to install the Visual C++ 2015-2019 redistributable (x64). You find the download link at the PHP site. The screenshot shows the startup of the installation program. | ||
|
||
Run IIS Manager and in the group IIS, select Handler Mappings (German: "Handlerzuordnungen"). Then, with the handler mappings displayed in the middle pane, choose Add Module Mapping... (German: "Modulzuordnung hinzufügen...") in the right pane. | ||
|
||
In the opening Add module mapping dialog box, enter the mappings for all files with extension .php (*.php). As module, select the FastCGI module. Use the "Browse" button to find the executable (German: "Ausführbare Datei") php-cgi.exe (located in the PHP installation directory). | ||
|
||
When you push the OK button, another dialog box pops up, asking you if you want to create a FastCGI application for this executable. Push the Yes (German: "Ja") button to confirm. | ||
Also from the group IIS, select Default documents (German: "Standarddokumente"), and add "index.php" to the list. | ||
The easiest way to configure PHP on IIS is to install PHP Manager for IIS, that you can download from www.iis.net. The installation adds an item called PHP Manager to the IIS group in IIS Manager. | ||
|
||
With PHP Manager, you can tailor your PHP configuration to your needs and wishes. | ||
|
||
The Not optimal PHP configuration detected warning primarily concerns some settings that have no value set by default. Clicking the link View recommendations, a window with these settings pops up and you can select the different check boxes in order to set the settings to the proposed values. I did this for all settings listed, except for "Default document" that I let at its typical IIS value "Default.htm" (?). | ||
|
||
One of the settings not set by default is the time zone, with a default value that is probably not the correct one for your location (in my case it was "Asia/Kuwait"). On the main PHP Manager page, click the link Mange all settings, select Date timezone in the middle pane, and in the right pane, choose Edit. Set the timezone for your region ("Europe/Luxembourg" in my case). | ||
In order to improve performance of your PHP scripts, you may want to install Windows Cache Extension for PHP, that you can download from Sourceforge. The download file is a self-extracting archive (in my case it's called wincache-2.0.0.8-dev-7.4-nts-vc15-x64.exe), that contains an (old) Readme file, that tells us that we have to copy the provided DLL into the PHP extension directory. The DLL is named php_wincache.dll and has to be copied to the "ext" subdirectory of the PHP installation folder. | ||
|
||
To use the extension, it has to be enabled in php.ini. Editing this file may be done by clicking the link Enable or disable an extension on the main page of PHP Manager. Enable php_wincache.dll. To be sure to avoid problems, you should also enable php_fileinfo.dll, php_gd2.dll, and php_mbstring.dll. | ||
|
||
And finally ready to test our PHP installation. Create the file phpinfo.php containing the code shown below and copy it to the IIS Document root. | ||
<?php phpinfo(); ?> | ||
To run the script, type localhost/phpinfo.php in the address bar of your web browser. The screenshot shows the beginning of the script output on my machine (note, that the screenshot has been taken on my Windows 10, accessing the script on IIS over the local network). | ||
|
||
Perl. | ||
You can download Strawberry Perl from strawberryperl.com. I actually use Strawberry Perl 5.32 (64-bit). The screenshot shows the 'Welcome' window of the setup program. | ||
|
||
I changed the installation directory to C:\Progs\Strawberry. The Perl executables are located in the "bin" subdirectory. No need to add them to the PATH; this is done by the setup program. | ||
Run IIS Manager and in the group IIS, select Handler Mappings (German: "Handlerzuordnungen"). Then, with the handler mappings displayed in the middle pane, choose Add Script Mapping... (German: "Skriptzuordnung hinzufügen...") in the right pane. | ||
|
||
In the opening Add script mapping dialog box, enter the mappings for all files with extension .pl (*.pl).
Use the "Browse" button to find the executable (German: "Ausführbare Datei") perl.exe (located in the "perl\bin" subdirectory of the Perl
installation folder). Important: The full and correct command to be entered in the "Executable" edit field is <perl-install-dir>\perl\bin\perl.exe %s %s |
||
|
||
When pushing the OK button, another dialog box opens, asking you if you want to enable this ISAPI extension. Push the Yes (German: "Ja") button to do so. | ||
The Perl scripts (files with .pl extension) are added to the handlers mapping list. Important: The handler for Perl scripts on IIS 8.5 is the module
CgiModule, thus we either have to use CGI.pm, or begin our scripts with something like this print "Content-type: text/plain; charset=iso-8859-1\n\n"; |
||
Here is the code of a Perl script to print the CGI environment variables: | ||
#!C:\Progs\Strawberry\perl\bin\perl.exe use strict; use warnings; print "Content-type: text/plain; charset=iso-8859-1\n\n"; foreach my $var (sort(keys(%ENV))) { my $val = $ENV{$var}; $val =~ s|\n|\\n|g; $val =~ s|"|\\"|g; print "${var}=\"${val}\"\n"; } |
||
Name the script printenv.pl and place it in the Document root of your web server. To run it, enter the following in the address bar of your web browser: localhost/printenv.pl. The screenshot shows the beginning of the script output on my machine (note, that the screenshot has been taken on my Windows 10, accessing the script on IIS over the local network). | ||
|
If you find this text helpful, please, support me and this website by signing my guestbook.