1

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.

3
  • PEAR is way out of date for many years. You should be using composer nowadays: composer require squizlabs/php_codesniffer --dev. Commented Oct 19, 2017 at 15:09
  • @Tomáš Votruba, I followed your advice and used composer. I am now able to run ./vendor/bin/phpcs command. Thanks for the advice. Commented Oct 19, 2017 at 15:54
  • Great job! That's awesome, I'll turn it into answer so it's easier to found. Commented Oct 19, 2017 at 17:00

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.