Set the Folders/Files View

When you start doing any development on a Windows system, you need to know exactly what the are full names of files, including the file extension that Windows prefers to keep hidden from the naïve user. Make Windows to stop treating you like a baby! Make it show you file extensions as well as other "hidden" features. Then make these changes:

Ignore Inferior Windows Software Tools

Notepad++

Notepad++ is free Windows software which can effectively replace that poor excuse for an editor called Notepad. If you have even half of a brain, you never use Notepad on your own Windows system. In contrast to Notepad, Notepad++ provides very good syntax highlighting, multi-file editing, Unix text file support, etc. Furthermore, it remembers the files you've been editing so that they are readily available whenever you start it up. The home page is this:
http://notepad-plus-plus.org/
From this home page the download is obvious and the installation is trivial. Click the Download button, choose Notepad++ Installer (an .exe) file, download and double-click to install.

Once installed, to edit any text file (.txt, .ini, .conf, etc.), right-click and select
Edit with Notepad++
You can also get Notepad++ to "take over" certain file suffixes as a replacement for Notepad, although in my experience, Windows' User Access Controls have given me trouble in making the effects stick.

7zip

Windows's built-in extraction of large zip files is notoriously slow. Fix this problem by getting a decent archive/unarchive utility. The one I particularly like is 7zip with this home page:
http://www.7-zip.org/
The download link is right in front of you. Just download and double-click to install. Once installed, open any archive file (in particular a .zip file), by right-clicking and selecting
7-zip → Open Archive

Php & Apache Software

The Php home site is
http://www.php.net
and Windows downloads are found here:
http://windows.php.net/download/
For current versions of Php, the choice suitable for an Apache installation is the thread-safe version compiled by VC9. According to the suggestions on the Php site, the Apache binaries found from the apache.org site are compiled using VC6 and not suitable for the latest Php binaries. At the Php site you are told to use Apache binaries found here:
Apache Lounge
These Apache downloads are available only in zip format and provide none of the "usual" installation features in terms of menu support, etc. Nevertheless, with some minor command shell control, we can readily make them work.

The other issue with Apache installations is the conflict with User Access Controls in Windows Vista+ systems. Without special efforts, the program menu functions will not work! Special efforts are still required to get Apache Lounge binaries to work, but the user is not given an illusion that things will work as is.

Software

The software packages you'll need for Apache/Php are these installation files:
httpd-2.3.16-win32.zip (Apache)
php-5.3.8-Win32-VC9-x86.zip (Php)
php5apache2_4.dll-php-5.3.8-win32.zip (Php DLL)

Run command shell as administrator

Something we need to do consistently through various stages of installation is to create and access the Apache "service". If you are using Windows XP, you are already have administrative priviledges. In contrast, the User Account Controls (enabled by default) on Windows Vista+ systems make you jump through hoops to do make certain changes to the system.

If you are using Windows XP, any command shell will do. Just select Start → Run and type cmd to bring up the command shell.

In Windows Vista+, you need to run this command shell as administrator. Here is the procedure:
  1. click the start button
  2. Type "cmd" into the search field. Don't hit return.
  3. Wait for an entry with the name icon "cmd.exe" to appear in the Programs list. Right-click on this entry and select "Run as administrator". Say yes when Windows starts throwing a fit.

Install Apache

Open the httpd-2.3.16-win32.zip archive with 7zip. Then simply drag the folder Apache23 into the C:\ folder and close the archive.

Now we want to install and manipulate the Apache service. Bring up an administrative command shell according to the previous section. From the command shell access the Apache bin directory:
> cd c:\Apache23\bin
Leave this command shell open in this directory throughout the developement for ease of access.

Install Apache service

Type this command:
> httpd -k install
This installs the Apache service. You should see the feedback:
Installing the Apache2.4 service
The Apache2.4 service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
Most likely you will also be queried to open a firewall entry for the Apache service. Click "Allow access" button for the Windows Firewall.

Start and control Apache service

After installation, start the Apache service by doing:
> httpd -k start
We can completely control the Apache service with the following commands (with obvious effects):
> httpd -k start
> httpd -k restart
> httpd -k stop
After starting the service, test it out. Point your favorite browser to the URL:
http://localhost
You should see the congratulatory "It Works!" message.

Install Php and Apache /default URL

From the c:\ folder, create the folder c:\php.

Install Php and the Apache DLL into the c:\php folder

Open the php-5.3.8-Win32-VC9-x86.zip archive with 7zip. You need to extract all the files into c:\php. Click the Extract button and enter c:\php in the Copy to field and submit this.

Open the php5apache2_4.dll-php-5.3.8-win32.zip archive with 7zip. This time you'll simply want to drag the DLL file into c:\php.

Remove old php5ts.dll file and add c:\php to PATH

When Php runs it looks for the support DLL file php5ts.dll in directories from the system PATH. We want our system to find this file precisely in the c:\php folder and nowhere else. If you have ever installed Php on your system, you will need to remove an old php5ts.dll file. In particular, look this file here:
c:\Window\System32\php5ts.dll
If you find it, delete it, or at least move it into one of your own personal folders. In particular, it needs to be out of the PATH.

Add c:\php to system PATH

Right-click on Computer. Select Properties → Advanced system settings → Environment variables. Look for Path int the System Variables list below. Append this text to the end:
;C:\php
A more sure thing would be to prepend "C:\php;" to the beginning, but Windows makes it so painful to get to the front of the PATH to do so, and so long as you have purged an older version of php5ts.dll from any of the PATH folders, you'll be OK. You can double-check the presence of C:\php by bringing up a new shell (not necessarily administrative) and typing
> path

Edit the Apache config file

Edit the file
C:\Apache23\conf\httpd.conf
As a poignant reminder, don't just double-click, but right-click on it and select "Edit with Notepad++". Scroll to the end of the file and add a few blank lines and this text:
PHPIniDir "C:/php/" 
LoadModule php5_module "C:/php/php5apache2_4.dll" 
AddType application/x-httpd-php .php 
DirectoryIndex index.php

Alias /default "c:/default"

<Directory "c:/default">
   Order Allow,Deny
   Allow from all
   Require all granted
   Options All
   AllowOverride All
</Directory>

Restart Apache

From our administrative command shell that we have saved, type:
> httpd -k restart
If there are no errors, you've probably installed Php successfully.

Test Php at the /default location

Our Apache configuration settings have established that the Apache associates the URL
http://localhost/default
with the directory:
C:\default
Eventually we may want to change this directory to something more useful, but for now it is convenient to make all our initial tests, so create the folder:
C:\default
Navigate to this folder and create the empty file:
C:\default\info.php
Add the following one line:
<?php phpinfo() ?>
Windows makes it painful to create a file with the .php extension outside of an IDE, but you can do it. With this in place, active the URL:
http://localhost/default
You should get a directory listing and within it see the info.php file. Activate it to prove to yourself that Php is working.

Modify the Php configuration

When Apache restarts or reloads its configuration file, the Php module will reset its configuration as well. It looks the the presence of its own file php.ini By virtue of the Apache configuration setting,
PHPIniDir "C:/php/" 
this php.ini file is assumed to be in C:\php. If this init file is not found, default configurations settings are made.

Create the configuration file

We need to take control of this configuration. There are two suggested files which can be copied:
php.ini-development    and     php.ini-production
We will use the former as our basis because our interests are initially towards development. Toward that end, make a copy of C:\php\php.ini-development, drop the copy back into C:\php and rename it to:
C:\php\php.ini

Edit the Php configuration file

This config file is rather large, and so it is often easiest to use a find utility in the editor to locate the relevant configuration setting. Right-click on C:\php\php.ini and select Edit with Notepad++. Look for and modify these settings:
  1. Default Timezone. Setting this in the config file will simplify coding and avoid warnings for time access functions. Search for the "date.timezone" and make the setting (suitable for the Middle Atlantic region):
    date.timezone = "America/New_York"
    
  2. Error display settings. In a production environment, error display should always be turned off so as to avoid the inadvertent revealing of server error information. However, error display is extremely convenient for debugging in a development environment. Search for display_errors and verify that it is on (if not, change the value):
    display_errors = On
    
    You'll also want to look (in the section just above) for the error_reporting setting. We want it to be the default value
    error_reporting = E_ALL & ~E_NOTICE
    
    Probably the simplest thing to do is to comment out whatever the setting may be, e.g.:
    ;error_reporting = E_ALL & ~E_STRICT
    
    We want to turn off a variety of notices given by Php. These notices are somewhat annoying but can be useful for debugging your Php code. If necessary, you can adjust the error reporting settings directly in your Php code.
  3. Establish a session folder. In the default Php configuration, session support requires the existence of a folder which does not exist on Windows; the default folder is mostly likely suggested in the comments (suitable for UNIX systems):
    ;session.save_path = "/tmp" 
    
    Within the C:\php folder, create a new subfolder by the name
    tmp
    
    Uncomment out and change the setting to (yes, forward slashes are OK)
    session.save_path = "C:/php/tmp"
    
  4. Set the extension directory. Php extensions are DLL files which provide extended functionality to Php. The most crucial thing for us is to provide database access APIs. Look for "extendion_dir" and change the default setting (which is probably "./") to this:
    extension_dir = "C:/php/ext/"
    
    The "on Windows" comment line suggests that the relative path "ext/" by itself is sufficient, but I cannot get it to work.
  5. Add the MySQL PDO database extension. Look for the "Windows Extensions" section and within it look for an uncomment the following line by removing the initial semicolon:
    extension=php_pdo_mysql.dll
    
From our administrative command shell that we have saved, type:
> httpd -k restart

Additional Module Activation

Depending upon the type of Php/MySQL access you have in mind, you may also want these modules. You can always go back and add other modules.
extension=php_mysql.dll
extension=php_mysqli.dll
The former provides the original MySQL API with functions using the mysql_ prefix. The latter provides the so-called MySQL Improved API which supports the functional model with mysqli_ prefixed functions, or an object-oriented model.

Also, the "SQLite/PDO" API is very useful for creating applicaitons with embedded (non-external) databases:
extension=php_pdo_sqlite.dll

Test Sessions

Download and extract the following file into the "/default" folder:
session-test.php.zip
For reference, here is the file:
session-test.php (click to show)
With this file installed in the default location, refresh the URL:
http://localhost/default
Within the directory listing you should see session-test.php. Activate it to verify that sessions are working. Browser refreshes should generate the sequence of natural numbers.

Install MySQL and test Php/MySQL

We will refer you to the document MySQL on Windows. You need to go through the MySQL Installation section in full. After a successful installation, start up a command shell (it doesn't have to be administrative) and execute these commands to get the setup necessary for our test program:
> mysql -u root
mysql> create database if not exists test;
mysql> select user from mysql.user;             (verify absence of "guest" user)
mysql> create user guest@localhost;             (if necessary)
mysql> grant all on test.* to guest@localhost;
mysql> quit;

Run a MySQL/PDO test

Download and extract the following file into the "/default" folder:
mysql-test-pdo.php.zip
For reference, here is the file:
mysql-test-pdo.php (click to show)
With this file installed in the default location, refresh the URL:
http://localhost/default
Within the directory listing you should see mysql-test-pdo.php. Activate it to verify that MySQL/PDO is working.


© Robert M. Kline