carlarenee
carlarenee

Reputation: 19

Pear and PHP_CodeSniffer installation issues: not able to use phpcs from command line

My setup: Mac OSX El Capitan 10.11.6, PHP 7.0.24-1+ubuntu14.04.1, PEAR Version: 1.10.5, I'm working on a local wordpress build using vagrant/virtualbox (vvv).

I'm new to pear and php_codesniffer and cannot seem to get phpcs commands to work. I've been trying to install PHP_CodeSniffer using pear:

My first issue is when trying to install PEAR. I follow the instructions: $ curl -O https://pear.php.net/go-pear.phar & $ php -d detect_unicode=0 go-pear.phar. Then when I try to configure Installation base to /usr/local/pear and Binaries Directory to /usr/local/bin, I get the following error: Unable to create PHP code directory ($php_dir) /usr/local/pear/share/pear. Run this script as root or pick another location.

I found others with the same error and saw this solution: sudo php /usr/lib/php/install-pear-nozlib.phar -d /usr/local/lib/php -b /usr/local/bin But this prompted an error: Could not open input file: /usr/lib/php/install-pear-nozlib.phar

I then tried configuring pear using: /home/vagrant/pear. I was able to install PHP_codesniffer, when I use pear list, I can see php_codesniffer:

vagrant@vvv:~$ pear list Installed packages, channel pear.php.net: Package Version State Archive_Tar 1.4.3 stable Console_Getopt 1.4.1 stable PHP_CodeSniffer 3.1.1 stable Structures_Graph 1.1.1 stable XML_Util 1.4.2 stable

when I run phpcs, I get the following message: The program 'phpcs' is currently not installed. To run 'phpcs' please ask your administrator to install the package 'php-codesniffer'

I found this post: which prompted me to: sudo pear config-set php_bin /usr/bin/php, then uninstall and reinstall codesniffer. Everything seems to work correctly, but when I try which phpcs, there is nothing.

I've installed and uninstalled pear a few times. When I try to uninstall, it says that pear is not installed, but when I do which pear, I get usr/bin/pear. It's a bit of a mess, any advice would be greatly appreciated.

Upvotes: 1

Views: 1599

Answers (1)

Tomas Votruba
Tomas Votruba

Reputation: 24280

PEAR is way out of date in 2017.

You should be using composer nowadays instead:

composer require squizlabs/php_codesniffer --dev

Then run like:

vendor/bin/phpcs ...

To get more details about PEAR timeout, there is RFC about PEAR removal for PHP 8.

Upvotes: 2

Related Questions