AMP for development on Mac OS X: MAMP

As a web developer I always need a very convenient development environment on my computer. I used XAMPP on Windows but since I switched to full Mac, I was looking for a similar solution.

MAMP WidgetI can hear you: “Hey! Are you stupid? Mac OS X comes already with almost a full AMP platform: by default we do have Apache and PHP and it is pretty easy to download MySQL and install it”. You are right of course (as usual!), but the version in Mac OS X are pretty outdated and I found a very convenient application for Mac to do this in a very mac-ish way: MAMP from living-e. It is a nice package including everything Apache2, MySQL5, PHP5 and PHP4 and even more (SQLite, eAccelerator, PHPMyAdmin and SQLiteManager), it provides a simple Mac application (and a widget) to control the all thing and change some parameters such as ports (by default Apache runs on 8888 to avoid conflict with your native Apache in MacOS) and switch from one PHP version to the other. It simply installs in your Applications folder from where you have access to everything. So far the best tool for web dev on MacOS (not mentioning the mandatory text editor: TextMate).
Fine, starting there you can really work and develop the nextgen web6.0 app that will terrified Google itself! But there is “one more thing“(tm): how about command-line access for php and of course PEAR? Here you have to do a couple of actions to make it works transparently for you, but no fears!, it is pretty easy and I am going to show you right now.

1. We will add one line in your PATH to shorten command-line to access php binary (in our case we want php5). Add in your home folder a .profile file if it does not exist yet and type in:

export PATH=$PATH:/Applications/MAMP/bin/php/php5/bin

2. We will now rename both original php and pear of MacOS so we make sure we do not use them (and obviously we do not delete them in case…):

sudo mv /usr/bin/php/usr/bin/php4
sudo mv /usr/bin/pear /usr/bin/pear4

(You could also simply change the order in the PATH and avoid step 2 but I prefer this way…personal taste!)

Starting now you should be able to access php and pear from your MAMP installation in the command line (you can try to type php -v and pear config-show). You can also easily add virtual hosts in your apache config to get your own local domain name such as http://mywebapp/ (you will have to modify as well your host file, see Apple doc for this).

This entry was posted in Mac, OSS & Tech. Bookmark the permalink.

3 Responses to AMP for development on Mac OS X: MAMP

  1. Vilo says:

    Thanks for the effort but your instructions are not clear to me. Little more description would be much appraciated.

    I do not understand following:

    “1. We will add one line in your PATH” … what path? path in what? where? path in PHP? path in MAMP? path in Apache?

    “Add in your home folder a .profile file” … what is home folder? htdocs? bin? php5?

    thanks for your help

  2. Vilo says:

    also…
    in step 1 you say … “(in our case we want php5)” and then in step 2 you are moving php4 and pear4

    it is confusing.

  3. Jonathan Arnold says:

    Vilo:

    1. $PATH refers to an environment variable enumerating the directories in your path…which are set for bash(the bourne again shell, the shell that is included with OSX) in a file called .profile located in a users(you hve a user account on your mac) home directory which you can get to in the terminal by typing cd ~

    your home folder would be somewhere like /Users/username

    2. OSX comes preinstalled with php 4…and pear…the are sitting in /usr/bin….which incidentally is in your path when you start a new shell …so instead of typing /usr/bin/php which is long and tedious…if something is in your path you could just at the bash prompt type php…now…if we are gonna add the php bin directory…where the new php executable is to our path…then we are going to be confused..which php is which…we thus rename the php executable in /usr/bin to php-old or something …and likewise for pear….add the mamp bin directory to our path…voila now we can run php jsut by typing php from the command line and guess what…its the new php5 executable included with mamp that we are running

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>