Stephanie Stephanie - 1 year ago 76
PHP Question

Using Pear's PHP codesniffer with MAMP Pro on mac

I’d like to ask for some help getting Pear’s PHP Code Sniffer set up properly.

I’m using MAMP pro 2.0.5 on a Mac PB 10.7.4 with PHP 5.3.6.
I do have Pear installed and can run pear commands, when I installed the PHP_CodeSniffer channel I didn’t get any errors but I can’t trigger any commands.

Here is a screen shot of my command line:

I was able to reference this post:
Putting PEARs php_dir into include_path in php.ini

But my include path seems correct:
include_path = ".:/Applications/MAMP/bin/php/php5.3.6/lib/php:/Applications/MAMP/bin/php/php5.3.6/bin/pear"

When I traced the path to the PHPCS install I found it’s executable file on this path: Users/alohamediaworks/pear/bin/phpcs

I’m not sure if i’m one symlink from being able to use this or not, any help or suggestions would be welcome.

Answer Source

PEAR will install bin files like PHPCS into a configurable location. You can see this location by running pear config-show | grep bin_dir.

The value here is probably currently /Users/alohamediaworks/pear/bin

You might want to just set it to /Applications/MAMP/bin or somewhere local on your Mac, like /usr/local/bin.

Before you do this, it is worth uninstalling PHP_CodeSniffer, and also checking that PEAR knows where PHP is by running pear config-show | grep php_bin.

I'll assume both values need changing:

pear uninstall PHP_CodeSniffer
pear config-set bin_dir /Applications/MAMP/bin/php/php5.3.6/bin
pear config-set bin_dir /Applications/MAMP/bin
pear install PHP_CodeSniffer

(check that the paths are valid first and that you don't have friendlier symlink versions)

You need the php_bin to be correct because PEAR will change the #! line of all bin files (like phpcs) on install to point to your PHP executable. The bin_dir is important to ensure bin files are placed into a directory that is in your path. Uninstalling PHP_CodeSniffer is required so old files are not left around (PEAR wont move them).

Hope that helps.