- Download the software at: http://mamp.info/en/Click Download Now button. It’s a big download, so it takes a while to complete. (MAMP is free, but the download also includes the commercial product, MAMP Pro, which makes administering MAMP easier. You don’t need MAMP Pro for this tutorial, and you don’t have to install it either.)
Once downloaded, the file (named something like MAMP_1.7_universal.dmg.zip) unzips itself, and appears in the list of volumes in a Finder window. In addition, License Agreement will appear; click Agree and the window pictured in Figure 1 below should appear. (You may need to double-click the .zip file to unzip its contents.)
Figure 1: Installing MAMP is just a matter of downloading a DMG (disk image) file, unzipping it, and dragging the MAMP folder into your Applications folder.
- Drag the MAMP folder (not the MAMP Pro folder) into your Applications folder (see Figure 1).
That’s it! You’ve just installed the world’s most popular and powerful Web server (tell your IT guys that the next time they say it’ll take two weeks for them to fix your email problem).
Now, you need to start the Web server.TIP: Since you’ll frequently access the MAMP program to turn the Web server on and off, it’s a good idea to add it to the OS X Dock.
- In Applications–>MAMP, start the MAMP program, and then click the Start Servers button if a red light appears to the left of either Apache or MySQL (see Figure 2).
The MAMP program (see Figure 2) lets you start and stop the Web and MySQL servers, as well as set preferences for how each server works. At this point, you have a functioning Web server, database server, and application server on your Mac. (PHP starts automatically whenever you start Apache.) You need to take care of one last thing before seeing if the server works; step 4 has the details.
Figure 2: When the servers are running, a green button to the left of Apache Server and MySQL Server lights up. To stop the servers, click the Stop Servers button. A red light next to either server indicates that the server is turned off.
- In the MAMP program, click the Preferences button, and then click the Ports tab (see Figure 3).
Ports are virtual entryways that manage how other computers access different server programs on your Mac. For example, you can assign a Web server to a particular port number, and then all requests for Web pages are directed to that port. By convention, port 80 is reserved for Web servers; Web browsers therefore normally request Web pages over that port.
When you visit http://www.cosmofarmer.com, you’re really visiting port 80 of the server that’s hosting http://www.cosmofarmer.com. Port 3306 is most commonly used for MySQL. However, out of the box, MAMP uses ports 8888 and 8889 for Apache and MySQL, respectively. Unfortunately, this system means you need to tack on the port number whenever you request a Web page from your testing server. So instead of typing http://localhost/ into a Web browser, to go to the home page for your local server, you must type http://localhost:8888/. This is a bit of a pain. Fortunately, it’s easy to change.
Figure 3: After installing MAMP it’s a good idea to set Apache and MySQL to their normal port settings of 80 and 3306. You can’t do this setting, however, if you don’t have administrator privileges for your computer. In that case, you have to stick to the 8888 and 8889 port settings that MAMP ships with. When you visit a Web page running on your local server, you have to add the port, like this: http://localhost:8888/my_cool_page.php.
- Click the “Set to default Apache and MySQL ports” button (see Figure 3), and then click OK.
You need administrator privileges to make these port changes, so you’re prompted to enter your administrator’s password. (If you’re not using an administrator’s account, see Figure 22-8.) Now it’s time to see if everything worked.NOTE: Mac OS X ships with a version of Apache already installed. If you have it running when you install MAMP, you can’t set the MAMP Apache port to 80. In this case, turn off Apache on your Mac by opening System Preferences. Click the Sharing tab, and then turn off the Personal Web Sharing checkbox. Now you can complete steps 4 and 5 above to set up MAMP’s Apache on port 80.
- In the MAMP program window, click the “Open start page” button (see Figure 2).
The home page for your new MAMP installation appears (see Figure 4). If you see the page, you know everything is set up correctly—you’re actually viewing this page through an active Web server on your own computer (pretty cool and geeky stuff). From this page you can access phpMyAdmin, a Web-based tool for managing a MySQL database (you’ll be using phpMyAdmin to help set up the database for the tutorials).
Figure 4: The MAMP home page gives you access to a few useful tools, including phpMyAdmin, which you’ll use for working with MySQL databases. You can always get to the MAMP homepage by typing its URL in a Web browser: http://localhost/MAMP; or, in the MAMP controller program, clicking the Open Start Page button (Figure 2).
You can find a helpful forum for asking questions and learning more about MAMP at http://forum.webedition.de/phpBB/viewforum.php?f=13.
To remove MAMP, simply drag the MAMP folder into the trash; but first remember to remove any Web page files you’ve created in the htdocs folder, and back up your MySQL database if you want to keep the data in it. You can learn how to back up a MySQL database at http://php.about.com/od/learnmysql/ss/mysql_backup_3.htm.
You can also have multiple Web sites running simulatneously on your computer, each with separate “virtual domains” that you can access independently. For example, typing http://clientA/ in a browser will show the site for client A, and http://clientB/ will show the site for client B. Here are instructions for setting up Virtual Hosts with MAMP.