The best integrated Apache, PHP, and MySQL package for Microsoft Windows is EasyPHP. It's frequently updated, carefully maintained, and reasonably easy to install. However, unless you're a French speaker, it does have the minor disadvantage that some of the documentation and instructions are in French.
Here are the steps to installing EasyPHP under Microsoft Windows. In all steps, make sure you use upper or lowercase characters as shown:
Using a web browser, visit the http://www.easyphp.org/ web site. Click on the language icon at the top of the page that best suits you (the U.S. flag means English).
Under the Main Menu heading on the left of the page, click on Downloads and then click on the current version to start the download; at the time of writing, this was EasyPHP1.7 which contains Apache 1.3.27, PHP 4.3.3, and MySQL 4.0.15, and we assume this version in these steps.
Save the downloaded file in a temporary directory such as C:\temp.
When using EasyPHP 1.7, you'll find that some of the features of MySQL 4.1 discussed in Chapter 15 and the features of PHP5 discussed in Chapter 14 can't be used. However, the rest of the material (including the online winestore) works without modification.
Run the downloaded file using the Run option in the Start menu. If you downloaded EasyPHP 1.7, the file that's downloaded is easyphp1-7_setup.exe. and you can run it by typing:
c:\temp\easyphp1-7_setup.exe
Click OK. This will begin the EasyPHP installation process.
Now, click Next to start, read the agreements and then check the option that accepts the agreement and click Next. Then, if your French is good, read the advice and click Next again; the advice suggests that the EasyPHP environment works well for development but isn't for application deployment. Our advice?for security and performance reasons?is to use a Unix environment such as Linux for application deployment.
The installer asks where you want to install the software, and defaults to c:\Program Files\EasyPHP1-7\. Unless you want to change it, click Next and answer Yes to creating the new directory. We assume this directory in the rest of this appendix.
Now, choose where you want the EasyPHP menu option to be in your Start Menu launcher. Unless you don't want it in the Programs menu, just accept the default by clicking Next. We assume it's in the Programs menu in the following steps.
You've now made all the choices that are needed. Click Install and wait as the install process completes. When it's finished, click Finish.
You can now run your Apache and MySQL servers. Click on the Start menu, Programs, Easy PHP 1.7, and on the Easy PHP program. A window should appear; if it doesn't, Apache is already running, and you should see a large E in your taskbar that you can double-click to make the window appear.
In the EasyPHP window, choose the language from the drop down that suits you. Then, assuming you've chosen English, select the options Start on Windows Startup and Start Apache and MySQL as Services. Then click on Apply, and minimize the window. You should now see a large E with a blinking red dot in your taskbar that signifies EasyPHP is running.
To test your Apache and PHP, create the file phpinfo.php in the directory C:\Program Files\EasyPHP1-7\www\ and type in the following contents:
<?php phpinfo( ); ?>
If you don't have a special-purpose text editor, use Notepad or WordPad, but make sure the file is saved with the extension .php and not .php.txt.
Now, load the URL http://127.0.0.1/phpinfo.php with a web browser on the same machine as your EasyPHP installation. You should see a screen containing information about your Apache and PHP installation.
Make a note that your Apache Document Root is C:\Program Files\EasyPHP1-7\www\.
Let's configure your MySQL. To begin, test that you can access the MySQL server using the command interpreter. To do this, select the Run option in the Start Menu and enter:
"C:\Program Files\EasyPHP1-7\mysql\bin\mysql.exe" -uroot
Click OK, and a window containing the command interpreter should appear. This means your MySQL server is running. Quit the MySQL command interpreter with the command:
mysql> quit
The window should close automatically.
Choose and set a password for root user access to the MySQL DBMS. To set a password of secret, choose the Run option in the Start Menu and enter:
"C:\Program Files\EasyPHP1-7\mysql\bin\mysqladmin.exe" -uroot
password secret
Click OK and a window will rapidly open and close, and you shouldn't hear a beep if you've typed the command correctly. Record the password for later use.
Start the MySQL command line interpreter using the password defined in the previous step by clicking on Run in the Start Menu and entering:
"C:\Program Files\EasyPHP1-7\mysql\bin\mysql.exe" -uroot -psecret
Click OK.
Record this step for later use?you'll need it whenever you want to access the command interpreter as the root user.
Let's create a new user for the MySQL installation that can carry out all actions required for a typical application (such as accessing our winestore database examples in the book), but has no access to other databases and can't change database access privileges. The new user also can't access the DBMS from a remote server.
To add the user, choose a username to replace username and a password to replace password in the following command:
GRANT SELECT, INSERT, UPDATE, DELETE, LOCK TABLES ON winestore.* TO username@127.0.0.1 IDENTIFIED BY 'password';
MySQL responds with:
Query OK, 0 rows affected (0.00 sec)
Record the username and password. Quit the MySQL command interpreter with the command:
mysql> quit
The window should close automatically.
Start the MySQL command line interpreter using the username and password you defined in the previous step by clicking on Run in the Start Menu and entering:
"C:\Program Files\EasyPHP1-7\mysql\bin\mysql.exe" -uusername -ppassword
Record this step for later use?you'll need it whenever you want to access the command interpreter using your user account username. Quit the MySQL interpreter again with:
mysql> quit
Your Apache, PHP, and MySQL setup is now functioning. To finish installation, you now need to set up PEAR and your mail services. Let's start with PEAR, and for this you'll need an Internet connection.
Edit the file C:\Program Files\EasyPHP1-7\php\go-pear.bat. To do this, you can use Notepad or WordPad. Change:
set PHP_BIN=cli/php.exe
to
set PHP_BIN=php.exe
Save the file and quit the editor.
Click on Run in the Start Menu and enter:
"C:\Program Files\EasyPHP1-7\php\go-pear.bat"
Click OK. Press Enter to proceed, and then either type in your web proxy server details or press Enter (for most installations, you can just press Enter).
You'll now be presented with a list of 7 options, and option 1 should show c:\Program Files\EasyPHP1-7\php\PEAR. If it doesn't press 1, Enter, and type in the path:
c:\progra~1\easyph~1\php\PEAR
Press Enter and the path should update next to option 1.
Option 7 may not show the path to your php.exe correctly. If it's blank or is not set to C:\Program Files\EasyPHP1-7\php\ then type 7 and press Enter, and then type:
C:\progra~1\easyph~1\php\
The trailing backslash is necessary. When you press Enter, you should see that option 7 has updated to the correct path.
Press Enter to continue the installation. Check that you're still connected to the Internet, and then press Enter to choose to install the bundled packages. This will start the install process and you'll see packages being installed.
At the conclusion of the install, there may be a warning about your php.ini not containing the correct path to the PEAR include files. Ignore this by pressing Enter, and we'll fix it manually in the next step.
Using an editor such as Notepad or WordPad, edit the file:
C:\Program Files\EasyPHP1-7\apache\php.ini
Find the line beginning:
include_path =
and change it so the complete line is:
include_path = ".;c:\Program Files\EasyPHP1-7\php\pear\pear"
While we're editing the php.ini file, we'll update the mail sending settings. Find the line beginning:
SMTP =
and adjust this to be the name of your outgoing SMTP mail server. Generally, this is your ISP's domain name prefixed by mail. For example, for users of bigpond.com, it's:
SMTP = mail.bigpond.com
Now find the line beginning:
sendmail_from =
and update it to your email address me@myaddress.com:
sendmail_from = me@myaddress.com
Now, save the file and exit the editor. The mail configuration allows both PHP's internal mail( ) function and the PEAR Mail package to work.
To re-read the php.ini file, you need to restart your Apache web server. To do this, double-click on the E in the taskbar, press the button labeled "Apache," click on Restart, and then press Close to minimize the window.
You've now completed the installation process. Make a note that your PHP configuration php.ini file is located in C:\Program Files\EasyPHP1-7\apache.
Your MySQL configuration my.ini file (this is known as my.cnf in Unix) is in stored in C:\winnt or C:\windows depending on your Windows version. To check where it is, click on the Start menu, then on Search, and then on For Files or Folders. Type my.ini and press the Enter key. The folder that contains the file will be shown after the search is complete. Make a note of the folder.
If need to edit these files, you can do so using Notepad, WordPad, or another editor, or you can edit them by double-clicking on the large E in the taskbar, and then single-clicking the E in the top-left of the window, selecting the Configuration option, and selecting the file you want to edit. You can also use the EasyPHP window to start and stop Apache and MySQL; clicking on the MySQL and Apache buttons shows all of the options.
This completes the Microsoft Windows install. If you want to install the book sample code, continue on to the next section.