Setting up CodeSniffer with MAMP on Mac OS X


Following coding standards ensures that code will be maintainable, independent of personal preferences and well organised. Sharing a document between coworkers can’t help ensuring that these standards will actually be followed, so some kind of checking system has to be set in place.

When programming in PHP, there are certain tools which help with implementing the best practice. One of them is CodeSniffer which can be tricky to setup to work with MAMP. Luckily, there is an easy way to set it up, and it is described here.

Notice: This instruction was written for Mac OS 10.9.2, MAMP 2.2 and PHP 5.4.19.

Edit your bash profile:
vim ~/.bash_profile

Alter the PHP version used by the system by adding the following line (you can add your version of PHP (it doesn’t have to be php5.4.19):
alias php=’/Applications/MAMP/bin/php/php5.4.19/bin/php’

Restart the terminal, and once you open it again, validate your settings with
php -v

If you get output like below, all is done well. If not, you should check your path in .bash_profile. Output you should get:
PHP 5.4.19 (cli) (built: Sep 18 2013 14:26:26)
Copyright (c) 1997-2013 The PHP Group

Check which pear is used currently by typing which pear. If output doesn’t point to ‘Application/MAMP/…’ edit ~/.bash_profile again and extend your include path with following:
export PATH=/Applications/MAMP/bin/php/php5.4.19/bin:$PATH

Restart the terminal again and run which  pear to ensure it is pointing to ‘/Applications/MAMP/…’ Then run phpcs –version.

If you get something similar to shown output below, it means all is setup and you’re ready to go:
PHP_CodeSniffer version 1.5.2 (stable) by Squiz (

If your output looks more like this: -bash: phpcs: command not found, it means you need to install PHP_CodeSniffer. It is simple and easy, and can be done with just one command: pear install PHP_CodeSniffer

So, there you have it – setting up CodeSniffer with MAMP on Mac OS X has never been so easy. Enjoy your development with your favourite IDE and see if you can integrate CodeSniffer with it.