Computer Bookshelf

PHP Web Development with Dreamweaver MX 2004

Revised installation instructions for PHP, Apache & MySQL

Book coverSince PHP Web Development with Dreamweaver MX 2004 was published in June 2004, considerable changes have taken place in the recommended methods of installing PHP and MySQL on Windows. If you use the same versions of PHP and MySQL as in the book (PHP 4.3.x and MySQL 4.0.x), the instructions remain unchanged. Many readers, however, naturally want to use the latest versions of PHP (5.0.x) and MySQL (4.1.x). These instructions replace those given in the book.

Although the changes don't affect installation on Mac OS X, some readers have found difficulty setting the root password for MySQL. Revised instructions for doing so can be found on the following page:

Getting Windows to display filename extensions

By default, Windows hides the three- or four-letter filename extension, such as .doc or .html, so all you see in dialog boxes and Windows Explorer is thisfile, instead of thisfile.doc or thisfile.html. The ability to see these filename extensions is essential for installing the necessary software for this book.

If you haven’t already enabled filename extensions on your computer, open My Computer (it’s on the Start menu on some systems and on the desktop as an icon on others). Then from the menu at the top of the window, choose Tools > Folder Options > View. Uncheck the box marked Hide extensions for known file types.

Installing PHP 5 on Windows

The recommended method of installing PHP on Windows no longer involves copying files to the Windows and Windows\system32 folders. If you have an existing installation of PHP on your computer, you must remove them for these revised instructions to work. Otherwise, Windows will use the old files instead of the new ones, leading to erratic behaviour. The new method of installation makes any future upgrades to PHP much simpler, so the time spent reinstalling now will be repaid many times in future.

  1. If you have never installed PHP on your computer before, go straight to step 2. If you have an existing installation, open Windows Explorer, and browse to the Windows folder. Find php.ini, and move it to a temporary folder. The location of the temporary folder is not important, as you will eventually delete the contents — it's simply a wise precaution, so that you can roll back to your previous configuration if anything goes wrong. Now browse to the Windows\system32 folder. Find all files that begin with "php" (such as php4apache.dll), and move them to the temporary folder. If you also have a copy of libmysql.dll in the Windows\system32 folder, move it to the temporary folder with all the others. You're now ready for a clean install of PHP.
  2. Go to www.php.net/downloads.php and select the Windows binaries ZIP file for the latest stable version of PHP 5. Do not choose the PHP Windows installer. This runs PHP in a very restricted way and is not suitable for the projects in this book.
  3. Unzip the contents of the ZIP file to a new folder called C:\php5. You can choose a different location, but this is where PHP will be run from, so you will need to substitute the name of your new folder in later steps.
  4. Open the php5 folder in Windows Explorer. You should see a number of folders (probably four), together with about 30 other files. If everything is inside a single folder, move the contents of the single folder to the top level of C:\php5. Locate the file php.ini-dist, make a copy of it inside C:\php5, and name the copy php.ini. This is the main configuration file for PHP, which you need to edit to get everything running correctly.
  5. You can open php.ini in Notepad by double-clicking its icon in Windows Explorer. However, it's a very long text file, so you may find it easier to use a script editor that displays line numbering. Also note that any line in php.ini that begins with a semicolon is a comment. Some of the configuration settings that you need to change are preceded by similar lines as comments, so make sure you change the correct line — in other words, the one without a semicolon at the beginning (or remove the semicolon where instructed).
  6. Scroll down to about line 288, and find the following command:

    error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT

    Change it to:

    error_reporting = E_ALL

    This sets error reporting to the correct level for a testing environment.
  7. About seven lines further down, there should be a setting for display_errors. Make sure it looks like this:

    display_errors = On

    Unless this setting is "on", you won't see any error messages onscreen. Nobody likes seeing error messages, but if this setting is "off", you'll never find out why a PHP script has failed — a sure way to lose hair quickly!
  8. In the Paths and Directories section, you should find the following command around line 450:

    extension_dir = "./"

    Change it to:

    extension_dir = "C:\php5\ext\"

    PHP uses this to find important DLL files that control various PHP extensions, including those for MySQL. If you used a different location to unzip the PHP files, change the path accordingly.
  9. Scroll further down until you come to Dynamic Extensions. You will see a long alphabetically ordered list titled Windows Extensions (around line 549), all of them commented out. These extensions add extra features to the core functionality of PHP. You can enable any of them at any time simply by removing the semicolon from the beginning of the line for the extension you want, saving php.ini, and restarting Apache. For the purposes of PHP Web Development with Dreamweaver MX 2004, you need only the extensions for MySQL, which is no longer enabled by default in PHP 5. Locate the following line:

    ;extension=php_mysql.dll

    Remove the semicolon to enable the extension. At the same time, add a new command immediately below to enable mysqli. The two lines should look like this:

    extension=php_mysql.dll
    extension=php_mysqli.dll
  10. In the Module Settings section immediately following the list of extensions, you can configure PHP to send email directly from your test pages.mail function configuration commands Find the lines indicated by arrows in the screenshot alongside (the line numbers are created by a text editor, and are not part of php.ini).

    Change the first one to to the name of the SMTP server you normally use for sending email. This is the name your ISP will have given you for outgoing mail. For example:

    SMTP = smtp.example.com

    Remove the semicolon from the beginning of the second line to uncomment it, and replace me@example.com with whatever email address you want to appear in the From field of emails sent from PHP scripts.
  11. The final change you need to make to php.ini is considerably further down (around line 879). Locate the line that reads:

    ;session.save_path = "/tmp"

    Remove the semicolon from the beginning of the line, and change the value of the setting to the name of your Windows Temp folder. This will normally be:

    session.save_path = "C:\Windows\Temp"
  12. That's all you need to configure PHP. If you ever need to make further changes to your configuration, simply open php.ini, make the appropriate changes, and restart Apache. If you're following these instructions for the first time, Apache hasn't yet been installed, so don't worry — we'll get to that quite soon. The next step, though, is telling Windows where to find PHP.