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:
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.
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>
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.
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.
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
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.
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.
After installing PHP, test the application server as described next.
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.
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.
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:
After successfully installing and testing the server software, create a root folder for your web application as described in the next section.
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.