Accessibility

Table of Contents

Setting up a PHP development environment for Dreamweaver

Set up PHP for Windows

PHP pages need to be processed through a web server. So, to develop with PHP in Dreamweaver, you need access to a PHP-enabled web server and the MySQL database. It's also useful to have a graphical interface to MySQL. You can install all of them independently, but the quickest and easiest way is to use an all-in-one solution, such as XAMPP.

This section describes how to install XAMPP on your Windows computer. This installs the Apache web server, MySQL, and a MySQL front end called phpMyAdmin in a single operation. All three components are open source software that you can use for developing, testing, and deploying web applications—and they are free!

If you're a Mac user, see Set up PHP for Mac OS X.

This section covers the following topics:

Before you start

XAMPP installs the Apache web server, which listens for requests on port 80. This is the default port used by most web servers, including Microsoft Internet Information Services (IIS). Only one web server at a time can listen on port 80. If you have installed IIS on your computer to develop with ASP or ASP.NET, you must stop the IIS web server before installing XAMPP.

If you want to test ASP, ASP.NET, and PHP without stopping and starting web servers to switch between them, you can install PHP to run on IIS. The official Microsoft IIS site has separate instructions for installing PHP on IIS6 (Windows XP) and IIS7 (Vista). After installing IIS, skip to the instructions on how to install MySQL and phpMyAdmin separately.

The following instructions assume that you don't have a web server installed on your computer, or that you intend to stop IIS when running PHP in Apache.

Install XAMPP

In Vista, you need to be logged into an Administrator account. If User Access Control (UAC) is enabled in Vista, you always need to run XAMPP from the same account. Otherwise, the XAMPP control panel won't have sufficient privileges to control Apache.

  1. Go to the Apache Friends website and download XAMPP for Windows. Choose the Basic package installer.
  2. Close all applications on your computer, and double-click the installer package you downloaded.

    Note: If UAC is enabled on Vista, you will see a warning about not installing XAMPP in C:\Program Files. You can ignore this warning, because the default installation location is C:\xampp.

  3. Accept the default installation location and click Next. This opens the dialog box shown in Figure 1.

    The default options, shown in Figure 1, are fine for most people.

    Note: Select the options to install Apache and MySQL as services if you want them to run automatically each time you start the computer. Running Apache and MySQL as services seems to be the most reliable option on Vista. If you're not sure, choose the options shown here. XAMPP makes it easy to install them as services later.

    XAMPP installation options

    Figure 1. These are your XAMPP installation options.

  4. Click Install after you have made your choices. The installation process takes a few minutes, because there are many files to unpack.
  5. At the end of the installation process, you're asked if you want to start the XAMPP control panel. Click Yes.

Start the servers

To start the Apache and MySQL servers, click the Start button alongside Apache and MySQL in the XAMPP control panel. MySQL usually starts very quickly, but it might take a little longer (less than a minute) for Apache to start. Confirmation that they have started successfully is displayed alongside, and the label on the Start buttons changes to Stop, as shown in Figure 2.

The XAMPP control panel

Figure 2. Start and stop the servers in the XAMPP control panel.

Note: If a Windows Security alert pops up asking whether to keep blocking the program mysql or apache, choose Unblock for both programs.

Note the following in case of errors:

  • If Apache fails to start, make sure you are logged into your computer with an Administrator account. Selecting the option Run as administrator in Vista usually does not give sufficient privileges to start the web server.
  • If Apache reports an error on startup, double-click the file C:\xampp\apache\logs\error.log in Windows Explorer, and scroll to the bottom of the file to read any error messages.
  • The error log for MySQL is located in the C:\xampp\mysql\data folder. It's in a file that uses the same name as your computer followed by an .err file name extension. To open it, double-click its icon, and select Notepad when prompted to select a program to use.

If you want to enable Apache or MySQL as Windows services so they start automatically, select the Svc check box alongside each one. (FileZilla and Mercury are FTP and mail programs, which are not required to develop with PHP in Dreamweaver. They are not covered in this article.)

Secure the database

To secure the database:

  1. Launch a browser and type http://localhost/ into the address bar.
  2. If everything has been correctly installed, you should see a web page offering a choice of languages. Select the language you want to use.
  3. The menu on the left of the following welcome screen gives you web-based access to various parts of XAMPP, including security configuration options.

    XAMPP web-based configuation screen

    Figure 3. The XAMPP welcome screen.

  4. Click Security in the menu on the left of the screen. This opens a new browser window or tab with a report on the current security status of your installation. Scroll down below the status report, and click the following link: http://localhost/security/xamppsecurity.php.

    This displays the screen shown in Figure 4, which prompts you to create a password for the MySQL superuser, root.

    Note: Even if you are the only person using the computer, it's good practice to password protect the MySQL database.

    Setting the MySQL root password

    Figure 4. Setting the MySQL root password.

  5. Enter your chosen password in both fields. It can contain special characters, but should not have any spaces.

    Note: Immediately below the password fields is a pair of radio buttons that determine how phpMyAdmin connects to MySQL as the root superuser. The default is to store it in a cookie. If you select http, you will be prompted for your root password every time you access phpMyAdmin.

    If you're worried about forgetting the password, you can select the Safe plain password check box to store it in a plain text file. How much of a security risk this represents depends on who else has access to your computer.

  6. After making your choices, click the Password changing button.
  7. Click Security in the menu on the left of the screen.

    The status report still shows that PHP is not running in "safe mode" and marks this as insecure. This is not a problem. You should not run PHP in safe mode unless you need to reproduce conditions on your hosting server. Some hosting companies run shared hosting accounts in safe mode, but it is considered unnecessarily restrictive and will be removed from future versions of PHP.

After installing XAMPP and securing the database, test the PHP installation as described in the following section.

Test the PHP installation

  1. Close the XAMPP security window or tab, and return to the welcome screen (see Figure 3).
  2. Click phpinfo() in the menu on the left of the screen. You'll see the page shown in Figure 5.

    PHP configuration information

    Figure 5. PHP configuration information.

Congratulations! You now have a working installation of PHP, MySQL, and phpMyAdmin. Although this screen might feel like information overload at this stage, it contains a wealth of information about your PHP setup. Return to this screen whenever you need to check how PHP is configured.

Note: You can display the same information by creating a PHP file containing the following script and loading it into a browser:

<?php phpinfo(); ?>

The next page deals with installation on Mac OS X, so skip to page 5 to learn how to define a PHP site in Dreamweaver or return to Part 1 of the tutorial series Creating your first dynamic site in Dreamweaver (if that's where you started).