Subscribe to Tutorial Feed

Flash and PHP Bible

The Flash and PHP Bible has been released! The book can be found on Amazon or wherever fine books are sold in your area.

The Flash and PHP Bible has a forum for quick support.

Scriptplayground » tutorials » mysql » Configuring MAMP on OS X to use default settings

Configuring MAMP on OS X to use default settings

Quickly configure MAMP to use the default MySQL and web directory that ship with OS X.

When working on a project I learned PHP 5 on OS X 10.5.8 and lower does not ship with SOAP support installed. One option was to re-configure PHP and include that support but as a general rule I try not to mess with default installs, especially as they can be updated in future OS X updates.

After poking around online I learned about the MAMP application. MAMP is a local web server application with PHP, MySQL, and Apache support all rolled into one application. This makes it possible to quickly get a development web server up and running which is all under your control. However by default MAMP has its own apache root directory (where your web files are stored) and uses its own MySQL client. For most people this is fine but I also use the OS X version of PHP and really didn't want to maintain two database and directories.

The process of editing MAMP is quite simple for most things. Lets start with changing the web directory. Simply open the MAMP app found in your /Applications directory and then click Preferences... to begin making changes. Click the Apache tab and change the Document Root to the following:

/Library/WebServer/Documents

Now that the documents folder is updated the next step is to change the ports. Click the Ports tab in the Preferences panel and you will see a "Set to default Apache and MySQL ports" button, click to change the port settings to the defaults and then click OK to save the changes. The MAMP server will automatically restart itself and you will notice the green status lights aren't both lit up.


Figure 1: MAMP Settings panel

Did you really think it would be that easy? Of course not! The problem is MAMP won't be able to connect because that port is already in use. Okay, so what now? Well, you could disable the default MySQL and be on your way, but then why would you have changed the port? So the real solution here is to point the MySQL information in MAMP to your default installation.

This part is not quite as simple as changing the ports, but its not terribly difficult either. Open up your Finder and navigate to the MAMP configuration directory, which should be similar to the following if you chose the default installation.

/Applications/MAMP/conf/php5

Once inside that directory, open the php5.ini file in your favorite text editor (such as TextEdit) and search for the following section, more specifically the last line.

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /Applications/MAMP/tmp/mysql/mysql.sock

Change the last line to the default location of the MySQL socket which on my system is:

mysql.default_socket = /tmp/mysql.sock

Now if you stop and start MAMP you should be able to work with your original MySQL databases. Note, MAMP will now display that MySQL is stopped, as shown in figure 2, because it really doesn't think MySQL is started. Also the Start Page will no longer function properly. This really isn't a problem, just be aware of it while debugging in the future.


Figure 2: MAMP Status panel showing MySQL stopped.

Hopefully this little guide helps you get started using MAMP on your local development machines and most of all be able to use some of the more interesting modules found in PHP, such as SOAP. Oh, remember when I mentioned the MAMP dialog no longer shows MySQL is started? Well, you can use the MySQL.prefpane to administer your default install of MySQL.


Figure 3: MySQL Preference Pane found in System Preferences, if installed with MySQL.

Follow Scriptplayground on Twitter (@scriptplay)

Comments: Configuring MAMP on OS X to use default settings

 coocoo  Tue Jun 29, 2010 4:42 pm  
this is a great tut and a great tool for mac web developers. i had to figure this out the hard way...glad to know that i am not nuts...thx!
 mkeefe  Wed Jun 30, 2010 7:19 am  
Glad the tut helped you. Post any questions that may arise as you continue to work with MAMP.
Add a comment
The ability to add new comments has been disabled in this archived version.

Loading
Main | Tutorials | Articles