Installing IIS and PHP to set up a localhost website on Windows 10
The idea is to set up your Windows PC as a web server, not online but locally on the PC itself. It means you can play around making PHP websites without the need to upload anything to the web (or even being online). I did this a few years ago on another PC but forgot the steps I went through and had to learn it all again for my current PC. So I've written it down this time. There might be other ways to do it but this worked for me.
The server software will be Microsoft-IIS, not Apache. The operating system will be WINNT, not Linux. Apache web server will run on Windows 'localhost' but I wanted IIS to compare it to Linux / Apache (what you usually get with personal web hosting packages). It means .htaccess won't work and neither will the PHP mail function (as far as I know).
(1) Get IIS running
Control Panel / Programs / Turn Windows features on or off
- Check Internet Information Services.
- In Web Management Tools check IIS Management Console.
- In World Wide Web Services / Application Development Features check CGI, which also installs FastCGI.
Screenshot:
To verify that IIS installed successfully, type 'http://localhost' into a web browser. You should see the default IIS Welcome page.
(2) Add a new website
Somewhere in Documents on your PC create a folder with an index.htm file inside it (later on it will be index.php). In this example the folder name is iis. Now go to:
Start / Windows Administrative Tools / Computer Management
- Expand Services and Applications and select Internet Information Services (IIS) Manager.
- Under Connections, expand to Sites.
- Stop Default Website (right hand pane).
- In Application Pools stop DefaultAppPool (right hand pane).
- Right-click Sites to add a new website. Give it a name (iis in this example) and in Physical Path select the iis folder you created above.
Screenshot:
There should be another Application Pool with the name of the website. Right-click Advanced Settings and under Process Model enter / select Identity as LocalSystem.
This is a crucial bit (or it was for me). To avoid this message coming up:
"HTTP Error 401.3 - Unauthorized — You do not have permission to view this directory or page because of the access control list (ACL) configuration or encryption settings for this resource on the Web server."
besides enabling Anonymous Authentication for the web site, I had to go a step further and edit Anonymous Authentication (by right clicking) and change it from a Specific User to Application pool identity.
In Default Document put index.php at the top and index.htm second.
In Manage Website (right hand pane) start the new website.
All that got the new website working but without PHP — that's why to begin with the 'index' file is index.htm.
(3) Install PHP
I did this manually. On PHP Windows download page download the ZIP file for the latest x86 Non Thread Safe version and unzip to a folder named PHP in Windows Explorer OS(C:).
In C:PHP open php.ini-production with Notepad and save as php.ini
php.ini now needs to be edited:
fastcgi.impersonate = 1 cgi.fix_pathinfo = 0 cgi.force_redirect = 0 extension_dir = "./ext" error_log="C:php_errors.log"
Windows extensions:
Un-comment all these lines
extension=bz2 extension=curl extension=fileinfo extension=gd2 extension=gettext extension=gmp extension=intl extension=imap extension=interbase extension=ldap extension=mbstring extension=exif extension=mysqli extension=oci8_12c extension=odbc extension=openssl extension=pdo_firebird extension=pdo_mysql extension=pdo_oci extension=pdo_odbc extension=pdo_pgsql extension=pdo_sqlite extension=pgsql extension=shmop
(4) Back to Windows
Click 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 the Environment Variables button at the bottom.
Select the Path variable from the System Variables section, and then click Edit. Add: c:php to the system path.
Save then start IIS Manager again: Start, Programs, Administrative Tools, then Internet Information Services (IIS) Manager.
From the IIS Manager, click on the hostname of the server in the Connections panel on the left. Double-click the Handler Mappings icon.
From the Handler Mappings Actions panel, click Add Module Mapping.
Type the following information into the appropriate text boxes, and then click OK.
Request path: *.php Module : FastCGImodule (select) Executable: C:phpphp-cgi.exe Name: FastCGI
Now, instead of index.htm the index file should be index.php and contain some PHP to check that it works. It should work. Test it by putting localhost or http://localhost in a browser's address bar. If it doesn't, go through everything again — it can be a bit fiddly and took a few tries in my case.
More information here (James McCaffrey) »
Articles »