Setting up MAMP, PEAR, and Headress
A simple guide for setting up MAMP, PEAR, and Headress
This article guides you through the basics of setting up a MAMP server on your Mac with Headress and any PEAR framework you choose. MAMP's self contained web server and Headress's ability to set up virtual hosts makes for a perfect solution for developing locally on your Mac. PEAR is a distribution system for PHP frameworks which can easily be installed in MAMP without needing to use the command line.
MAMP
MAMP is a self contained Apache, MySQL, and PHP web server for the Mac. Like most other Mac applications, installation involves a simple drag and drop. MAMP not only includes an Apache and MySQL server, but also allows for seamless switching between PHP 4 and PHP 5.
Installation
- Download and mount the MAMP dmg.
- Drag the MAMP folder to the supplied Applications shortcut, then unmount.
- Navigate to the
Applications/MAMPfolder and launch MAMP.
Setup
Initially MAMP will activate the Apache and MySQL servers on both port 8888 (Apache) and 8889 (MySQL) which can be easily changed to the default 80 (Apache) and 3306 (MySQL) ports. MAMP also defaults to PHP5. These settings can be easily changed in the preferences of the application. If you want the MAMP servers to be active at all times, even when the MAMP application is closed, simply uncheck "Stop Servers When Quitting MAMP" in the "Start/Stop" tab in the preferences. You should also at this time navigate to the "Apache" tab and choose where you want to store your server files, should you decide to have them somewhere other than folder supplied by MAMP (Applications/MAMP/htdocs/).
PEAR in MAMP
PEAR is a distribution system for an extensive collection of PHP frameworks. Some of the frameworks included are for authentication, database management, image manipulation, and more.
Installation
- After locating the framework you want on pear.php.net, download the latest version from the "Download" tab on that framework's main page.
- Unzip the downloaded file.
- Open the folder that was extracted to find another similarly named folder and a file named package.xml.
- Copy just the folder to
Applications/MAMP/bin/php5/lib/php/orApplications/MAMP/bin/php4/lib/php/.
To make sure that the installation of the framework went smoothly, run the following PHP code.
- PHP
- <?php
- include_once('Text_Diff-1.0.0/Diff.php');
- if (class_exists('Diff.php')) { echo '<p>Framework Installed!</p>'; }
- else { echo '<p>Error Loading Framework.</p>'; }
- ?>
Notice: The above code was specifically coded to test the installation of the Text_Diff framework. To make it work with the framework you just installed, simply replace Text_Diff-1.0.0 with the name of the folder you just copied, change Diff.php to a file within that directory, and change Text_Diff to the name of a class within that file. Sometimes a framework might require more than one file to be included, check that framework's documentation for more information on how to use it.
Headdress and MAMP
Headdress is an application that can edit MAMP's Apache config file, allowing you to add virtual hosts through the use of different port numbers. A virtual host is similar to hosting separate domains on one server.
Installation:
- Stop the MAMP server.
- Download and unzip the Headdress application.
- Drag the unzipped application to the Applications folder and run.
- Delete the default
httpd.conffile in the sidebar. - Add MAMP's apache
httpd.conffile (/Applications/MAMP/conf/apache/httpd.conf). - Proceed to add Sites (max 2 for the application's demo) in the main panel by choosing "Add Site" and then navigating to it's location on the computer. Give it a name then save.
- Restart MAMP servers.
- Navigate back to the Headress application and click on the link to any of the virtual hosts you setup.
If everything worked you should now have two or three separate virtual servers; localhost:8888, localhost:9000, and localhost:9001.