Getting command line access to PHP and MySQL running MAMP on OSX

If you have MAMP installed on your Mac OS X box, you're probably going to want command line access to those applications at some point. Assuming you're running a default install you'll run into difficulty when you type php or mysql without logging into the appropriate directory. In MAMP the directories are as follows:

/Applications/MAMP/bin/php5/bin/php
/Applications/MAMP/Library/bin/mysql

Rather than referencing those full paths every time you'll probably want to include them in the PATH. You can do this by editing your .profile file. (You can get to the directory where this lives by typing cd).

Use a text editor to open up .profile and change the following line:
export PATH=/opt/local/bin:/opt/local/sbin:$PATH

To include the additions to the $PATH like so:
export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5/bin/:/opt/local/bin:/opt/local/sbin:$PATH

You'll probably need to make the shell reload your profile like so:
. ./.profile

Also if you have any problems connecting to mysql you may need to run the following command:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

Thanks to the following blog entries:
http://www.tech-recipes.com/rx/2621/os_x_change_path_environment_variable/
http://www.fischerlaender.net/apple-mac/mac-os-x-trouble-with-mamp-mysql

Comments

I am unable to find .profile under Snow Leopard. Upon opening Terminal, I have tried the command "open .profile" Telnet replies, "The file /Users/Matthew/.profile does not exist." Any suggestions?

joaquin's picture

Hmm... I'm not running Snow Leopard, but you should be able to get to your home directory by typing:

cd

Once there try typing:

ls -al

That will give you a list of all of the files in that directory, including files that start with the . character that are otherwise hidden.

To anyone who is having problems getting Zend_Tool working on their MAC OS X (10.6) in Terminal, this is how to solve the problem.

Step 1
---
Download the Zend Framework to your downloads folder. Once downloaded, rename the folder ZendFramework

Step 2
---
Open Terminal and type: sudo cp -r ~/Downloads/ZendFramework /usr/local/ZendFrameworkCli

Step 3
---
In Terminal, type: open ~/.bash_profile

Note: If file is not found...
---
Open the application TextEdit. Create a new file and make sure you are typing in plain text only. Type the following: alias zf=/usr/local/ZendFrameworkCli/bin/zf.sh

Save and exit TextEdit

Step 4
---
In Terminal, type: zf show version

Done!

Thought I would update the instructions here for MAMP 1.9

The path has changed to
/Applications/MAMP/bin/php5.3
/Applications/MAMP/bin/php5.2

First, make MAMP's php executable
chmod +x /Applications/MAMP/bin/php5.2/bin/php

then edit your path for the version of PHP you want to use:
export PATH=/Applications/MAMP/Library/bin/:/Applications/MAMP/bin/php5.2/bin/:/opt/local/bin:/opt/local/sbin:$PATH

This was exactly what I was searching for, that symlink saved my - thank you!

thanks to all of the above !!

I changed the password when I was in phpMyAdmin, the root by accident, then I got the following message:
/Applications/MAMP/Library/bin/mysqlcheck: Got error: 1045: Access denied for user 'root'@'localhost' (using password: YES) when trying to connect

How do I fix the root password in the terminal so that I can access the phpMyAdmin again.

Add new comment