Accessibility

Table of Contents

Setting up a PHP development environment for Dreamweaver

Set up PHP for Mac OS X

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.

The Apache web server and PHP are preinstalled in Mac OS X. However, they're not enabled by default. Moreover, the preinstalled version of PHP lacks a lot of useful features, and you need to install and configure MySQL separately. Unless you're very comfortable working with the command line in Terminal, it's much easier to install the all-in-one solution MAMP.

This section describes how to install MAMP on your Mac. 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. What's more, they're free.

Note: You can also purchase a license for a commercial add-on called MAMP PRO. This makes it easier to organize your sites. However, the free version is perfectly adequate for developing PHP pages with Dreamweaver, so MAMP PRO is not covered here.

If you're a Windows user, see Set up PHP for Windows.

This section covers the following topics:

Before you start

Instead of using the preinstalled version of Apache, MAMP installs a separate version in a different location on your hard disk. This makes it easier to uninstall everything by simply dragging the MAMP folder to the trash if you decide you no longer want MAMP on your computer. MAMP also avoids conflicts with the preinstalled version of Apache by using a non-standard port (8888) to listen for requests for web pages.

To make it easier to deploy your PHP pages on the Internet, it's a good idea to configure MAMP to use the standard port for web servers (80). Instructions for how to do this are given later, but you should first check that the preinstalled version of Apache is not running.

  1. Open System Preferences, and select Sharing in Internet & Network.
  2. Make sure that Web Sharing is not selected.
  3. As long as MySQL has never been installed on your computer, you're good to go.

Note: If you prefer to use the preinstalled version of PHP in Mac OS X 10.5, follow the tutorial on my website. Then skip to the instructions on how to install MySQL and phpMyAdmin separately.

Install MAMP on your Mac

To install MAMP on your Mac:

  1. Go to the MAMP download page and select the link for MAMP & MAMP PRO. This downloads a disk image that contains both the free and commercial versions.
  2. When the download completes, you will be presented with a license agreement. You must click Agree to continue with mounting the disk image.
  3. When the disk image is mounted, drag the MAMP folder onto the shortcut icon for Applications as indicated by the arrow (see Figure 6).

    MAMP disk image

    Figure 6. Installing MAMP from the disk image.

  4. Verify that MAMP has been copied to your Applications folder, and eject the disk image.

For the purposes of this article, you need to install only the free version of MAMP. The commercial version is an add-on that you can add later if you want to use its advanced features. To learn more about the commercial version, visit the MAMP PRO website.

Test and configure MAMP

To test and configure MAMP:

  1. Double-click the MAMP icon in Applications/MAMP.
  2. After a few moments, your default browser should launch and present you with a page welcoming you to MAMP. Note that the URL in the browser address bar begins with http://localhost:8888. The :8888 string after localhost indicates that the web server is listening for requests on the non-standard port 8888.
  3. Minimize the browser and locate the MAMP control panel, which should be running on your desktop. The green lights alongside Apache Server and MySQL Server indicate that both servers are running (see Figure 7).

    MAMP control panel

    Figure 7. The MAMP control panel.

  4. Click the Preferences button, and select Ports at the top of the panel that opens. The panel shows that Apache and MySQL are running on ports 8888 and 8889, respectively (see Figure 8).

    Changing the default ports

    Figure 8. Changing the MAMP ports.

  5. Click Set to default Apache and MySQL ports, as shown in Figure 8. The numbers change tothe standard ports: 80 for Apache and 3306 for MySQL. This will make your development with Dreamweaver easier.

    Note: If, for any reason, you want to change back to the non-standard MAMP ports, open this panel and click Reset MAMP ports.

  6. Click OK and enter your Mac password when prompted.

    MAMP stops and restarts both servers.

  7. When both lights are green again, click Open start page. This reloads the MAMP welcome page into your browser. This time, the URL should have :80 after localhost. Because port 80 is the default, the addition of :80 is unnecessary, but it serves as a reminder that you have changed the MAMP settings.
  8. Click the phpinfo link in the MAMP menu. You should see the page shown in Figure 9.

    PHP configuration information

    Figure 9. PHP configuration information.

Congratulations! You 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 details of the way 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(); ?>

Now that you have a PHP testing environment on your computer, you can skip to the section Define a PHP site in Dreamweaver so you can start developing, or return to Part 1 of the tutorial series Creating your first dynamic site in Dreamweaver (if that's where you started).