Accessibility

Dreamweaver Article

 

Setting up a PHP development environment for Dreamweaver


Table of Contents

Set up a PHP application server (Macintosh)

To set up a PHP development environment, you must first set up or get access to a PHP application server. An application server is software that helps a web server process web pages containing server-side scripts or tags. When such a page is requested by a browser, the web server hands the page off to the application server for processing before sending the page to the browser.

This section describes how to install PHP 5 on your Macintosh computer. PHP is open source software that you can use for developing, testing, and deploying web applications. For more information, see the PHP documentation at www.php.net/download-docs.php.

If you're a Windows user, see Set up a PHP application server (Windows).

This section contains the following topics:

Start the Apache web server

First, you need a web server. PHP installs as an extension to an existing web server, enabling the web server to process PHP files. Mac OS X users can use the Apache web server included with their operating system. This section describes how to start the web server, and how to make sure it's working properly.

  1. Select Apple > System Preferences > Sharing.
  2. Select the Personal Web Sharing option from the Services tab.
  3. Click the Start button.
  4. In Dreamweaver or any text editor, create a plain text file called myTestFile.html and enter the following line in the HTML code:

    <p>My web server is <em>working</em>.</p>
  5. Save the HTML file in the following folder on your computer:

    /Users/your_user_name/Sites/

    where your_user_name is your Macintosh user name.

  6. Enter the following URL in your web browser:

    http://localhost/~your_user_name/myTestFile.html

Note: Make sure to include the tilde (~) character with your user name.

If the browser displays your page and the word "working" is in italics, the web server is running normally. If the browser fails to display the page properly, check the URL for errors. Also make sure you prefixed your Macintosh user name with the tilde character.

Install PHP on your Macintosh computer

  1. If applicable, log into your Macintosh system using the Administrator account.
  2. Create a folder named webapps in your main user folder, Users/your_user_name/webapps.
  3. From the Entropy web site at www.entropy.ch/software/macosx/php/, download the PHP for 5.x for Apache 1.3 package (for example, entropy-php-5.2.0-3.tar.gz) and save it in your webapps folder.
  4. On your Macintosh, open Terminal (Applications/Utilities) and change the default folder to webapps by typing the following line on the command line and pressing Enter:

    cd webapps
  5. In Terminal, uncompress the gz file by typing gunzip followed by the name of the gz file in your webapps folder.

    For example, if you downloaded entropy-php-5.2.0-3.tar.gz, enter the following command and press Enter:

    gunzip entropy-php-5.2.0-3.tar.gz 

    Note: Do not use Stuffit Expander to uncompress the file.

  6. In Terminal, open the tar archive that was uncompressed by typing tar xf followed by the name of the tar file. Example:

    tar xf entropy-php-5.2.0-3.tar 

    An installer package called entropy-php.mpkg is extracted from the archive.

  7. Double-click the installer package entropy-php.mpkg and follow the onscreen instructions.

After installing PHP, test the application server as described next.

Test the PHP server

  1. In Dreamweaver or any text editor, create a plain text file and name it timetest.php.
  2. In the file, enter the following code:

    <p>This page was created at
    <b><?php echo date("h:i:s a", time()); ?></b> on the computer running PHP.</p>

    This code displays the time the page when was processed on the server.

  3. Copy the file to the following folder on your Macintosh:

    /Users/your_user_name/Sites 

    The Sites folder is your personal root folder for the Apache web server.

  4. In your web browser, enter the following URL and press Return:

    http://localhost/~your_user_name/timetest.php 

The test page should open and display the time of day. The specified time is known as dynamic content because it changes every time you request the page. Click your browser's Refresh button to generate a new page with a different time.

If the page doesn't work as expected, check for the following possible errors:

  • The file does not have a .php extension.
  • The URL contains a typing mistake. Check for errors and make sure the filename is not followed by a slash, such as http://localhost/~your_user_name/timetest.php/. Also make sure you included the tilde (~) before your user name.
  • The page code contains a typing mistake.
  • The Apache server is not running. Look in System Preferences, in the Sharing category, to see whether Personal Web Sharing is enabled.

After successfully installing and testing the server software, create a root folder for your web application as described in the next section.

Create a root folder for your application

You should create a root folder to store all the files of your web application. If you're using the Apache web server on your Macintosh, a good place to create the folder is in the Sites folder, as in the following example:

 /Users/your_user_name/Sites/MyWebApp

The Apache web server will serve any page in the Sites folder or in any of its subfolders in response to an HTTP request from a web browser.