Installation Of PHP and MySQL

Developers working with PHP and MySQL often find it convenient to work on a local computer rather than a web server. In general, it is also safer to create and test your applications on a localpreferably privatecomputer and then deploy them to a public server where others can enjoy your work.

Typically, you need to install Apache, PHP, and MySQL on the local computer, while your ISP handles installation on the public server. Developing your construct on your local computer is the recommended way to learn, since you can interact with all of the components on your own machine and not risk causing problems on a production server.

That way, if there are problems in the local environment, you can fix them immediately without exposing them to your site's visitors. Working with your files locally means that you don't have to FTP them to a server, you don't have to be connected to the Internet, and you know exactly what's installed since you did it yourself.

There are three components to install:

  • Apache
  • PHP
  • MySQL

You will install the programs in that order. All our examples will be from the installation perspective of a PC with Windows installed, with notes for the Macintosh.

First, Apache needs to be installed and operational before PHP and MySQL can be installed, or else they won't work correctly. Plus, there wouldn't be any use for the coding application and database without the Apache web server. A web server delivers web pages, has an IP address, and might have a domain name.

For example, if you enter in your browser, this sends a request to the server whose domain name is The server fetches the page named index.html and sends it to your browser.

Any computer can be turned into a web server by installing server software and connecting the machine to the Internet, which is why you need to install Apache.

  1. Download the Apache 2.0.5 Win32 binary. It's downloadable from httpd.apache.or. The file that you save to your desktop is called apache2_0.55-win32-x86-no_ssl.msi.
  2. Install Apache using the Installation Wizard. Double-click the MSI installer file on your desktop.
  3. Accept the license terms by clicking the radio button.
  4. You'll see a "Read This First" box. Additionally, this window offers a number of excellent resources related to the web server. Click Next.
  5. In the blank dialog box, enter all pertinent network information.
  6. In the next screen, select the setup type. The Typical install will work for your purposes. Click Next.
  7. Accept the default installation directory. Click Next.
  8. Click Install. The installer installs a variety of modules, and you will see some DOS windows appear and disappear. Click Finish when the installer is done.
  9. Test your installation by entering http://localhost/ in your browser's location field. The local host's IP address is
  10. After entering the URL in your browser, the default Apache page displays. The installation was successful. Now that you can serve up web pages, you're ready to add PHP.

Go to to download the latest version of PHP; both binaries and source code can be found on this web site. You need to download the zip file rather than the Windows installer, because the Windows installer only configures the IIS web server.

Create a directory for PHP on your desktop. You don't need all the files provided in the archive, so unzip the PHP archive into another temporary location. (A temporary location could be on your desktop, which will be easier to find when you go looking for the files.)

  1. Copy the following files into C:\php: php.exe, php4ts.dll, and php2apache2.dll. The php2apache2.dll file is located in the sapi directory.
  2. Load PHP extensions. If you plan to load PHP extensions, you need to copy the files in the extensions directory (or the ext directory, for PHP 5.x) to C:\php, or to a subfolder in C:\phpany subfolderas long as the PHP.ini file is updated to reflect the appropriate directory.
  3. To configure PHP, copy php.ini-dist from the extracted files into your Windows directorytypically C:\winnt or C:\Windowsand rename it php.ini.
  4. Set up PHP to load Apache as a module. To configure Apache to load PHP as a module to parse your PHP scripts, use a text editor to open the Apache configuration file, httpd.conf, typically found in C:\Program Files\Apache Group\Apache2\conf \.
  5. Load PHP as an Apache module. Open the httpd.conf file in Notepad or another text editor and search for the section that has a series of commented out LoadModule statements.

  1. Restart the Apache server by selecting Start -> Apache HTTP Server 2.0.x -> Control Apache Server -> Restart, so that it can read the new configuration directives you placed into httpd.conf. Alternatively, in the system tray, double-click on the Apache icon and click the Restart button.
  2. Search for AddType in the file, around line 754, and add the following line after the last AddType statement: AddType application/x-httpd-php .php

If for some reason this doesn't work, check to see whether your PHP or Apache setup is causing the problem. Go to the command-line prompt and type cd \php. The prompt should change to C:\php. Then type in php "C:\Program Files\Apache Group\Apache2\htdocs\phpinfo.php", since the file isn't in the c:\php directory.

If invoking PHP from the command line causes a large HTML file with all the PHP configuration information to be displayed, then your PHP setup is fine. The problem is probably your Apache configuration; go ahead and reread the procedure on how to install and configure Apache.

The final component you need to develop and test pages on your local computer is MySQL. Now download the MySQL Installer.

  1. Download the MySQL binaries. Both the binaries and the source code can be found at The link takes you to a page where you can enter personal info, or just click No Thanks to download the file. A number of download locations (or mirrors) are available; select one. Download the recommended version for the Windows Essentials (x86) MySQL 4.1 Installer. Save the installer file to your desktop.
  2. Double-click the MSI installer file on your desktop. A setup wizard walks you through the installation process. (The install process for MySQL 5.0 is the same as it is for MySQL 4.1.) Click Next.
  3. Select Typical installation by clicking the Typical radio button and then click Next.
  4. Click Install on the Ready to Install the Program dialog box.
  5. The setup program next will ask you to create a account. Select Skip Sign-Up and click Next, or sign up for an account, which provides access to a monthly newsletter as well as the ability to post bugs and comments on the online forums.
  6. Select the "Configure the MySQL Server now" checkbox, and then click Finish. This brings up the dialog box where you can just click Next.
  7. Select the Standard Configuration radio button from the dialog. Click Next.
  8. In the dialog, check both Install As Window Service and "Launch the MySQL Server automatically." Click Next.
  9. Enter a password for the root user in the password and confirm fields. Click Next. You do not need the Anonymous Account since you can do everything with named accounts.
  10. Click Execute.
  11. Click Finish. MySQL is now configured and running on your computer.