Wrong include_path for Codesniffer
Asked Answered
R

3

9

This issue has been addressed before and I have tried to solutions offered and think I am doing something wrong. I am attempting to configure PHP Codesniffer on a Mac using Mountaion Lion. I don't think it matters, but I ma using XAMMP. I am getting the following error when I run phpcs.

Warning: include_once(PHP/CodeSniffer/CLI.php): failed to open stream: No such file or directory in /usr/bin/phpcs on line 31

Warning: include_once(): Failed opening 'PHP/CodeSniffer/CLI.php' for inclusion (include_path='.:') in /usr/bin/phpcs on line 31

Fatal error: Class 'PHP_CodeSniffer_CLI' not found in /usr/bin/phpcs on line 34

This error, based on all the searching, is because of an incorrect include_path in php.ini. As I understand, this path is supposed to be the directory where pear resides. When I run pear config-get php_dir it returns /usr/lib/php/pear I expected this. So I modified the php.ini file (this file is the only php.ini on the system, so it is not grabbing the setting from another file) to read:

include_path = ".:/usr/lib/php/pear/"

This looks right, but I keep getting the same error. I have removed the leading .: and that does not help...and it shouldn't work. I also removed the trailing / and same result. Note that phpcs is in the usr/bin directory. Below is the result of running pear config-show

Configuration (channel pear.php.net):
=====================================
Auto-discover new Channels     auto_discover    1
Default Channel                default_channel  pear.php.net
HTTP Proxy Server Address      http_proxy       <not set>
PEAR server [DEPRECATED]       master_server    pear.php.net
Default Channel Mirror         preferred_mirror pear.php.net
Remote Configuration File      remote_config    <not set>
PEAR executables directory     bin_dir          /usr/bin
PEAR documentation directory   doc_dir          /usr/lib/php/pear/docs
PHP extension directory        ext_dir          /usr/lib/php/extensions/no-debug-non-zts-20090626
PEAR directory                 php_dir          /usr/lib/php/pear
PEAR Installer cache directory cache_dir        /private/tmp/pear/cache
PEAR configuration file        cfg_dir          /usr/lib/php/pear/cfg
directory
PEAR data directory            data_dir         /usr/lib/php/pear/data
PEAR Installer download        download_dir     /private/tmp/pear/download
directory
PHP CLI/CGI binary             php_bin          /usr/bin/php
php.ini location               php_ini          /private/etc/php.ini
--program-prefix passed to     php_prefix       <not set>
PHP's ./configure
--program-suffix passed to     php_suffix       <not set>
PHP's ./configure
PEAR Installer temp directory  temp_dir         /JimS/temp
PEAR test directory            test_dir         /usr/lib/php/pear/tests
PEAR www files directory       www_dir          /usr/lib/php/pear/www
Cache TimeToLive               cache_ttl        3600
Preferred Package State        preferred_state  stable
Unix file mask                 umask            22
Debug Log Level                verbose          1
PEAR password (for             password         <not set>
maintainers)
Signature Handling Program     sig_bin          /usr/local/bin/gpg
Signature Key Directory        sig_keydir       /private/etc/pearkeys
Signature Key Id               sig_keyid        <not set>
Package Signature Type         sig_type         gpg
PEAR username (for             username         <not set>
maintainers)
User Configuration File        Filename         /Users/JimS/.pearrc
System Configuration File      Filename         /private/etc/pear.conf

Any ideas? I am prone to typos, so that is always a possibility, so everything I put here is cut/paste.

Rashida answered 9/3, 2013 at 20:39 Comment(6)
As you change the include_path, is the error message changing to show you the new path? If not, run php --ini to see which ini file (if any) it is using.Barrault
Hi Greg, Thanks for the reply. There is only one php.ini on the system. When I run php --ini it returns:Configuration File (php.ini) Path: /etc Loaded Configuration File: (none) Scan for additional .ini files in: (none) Additional .ini files parsed: (none)Rashida
Your other php.ini might be being used for Apache or another web server, or it might not be used at all yet. Try copying that php.ini to /etc/php.ini and that can be your command line one that you edit from now on. See if it works once placed there.Barrault
Hi Greg, An odd thing happened. I copied my one php.ini file to /private/etc and ran php --ini This time it recognized the file, but when I ran phpcs I got a bunch of additional errors that looked something like this: PHP Warning: PHP Startup: Unable to load dynamic link libary .... path .... filename. This error repeated for about 20 different files. I am now looking into those errors. They appear to be related to having different versions of PHP on the system. Mountain Lion comes with its own, and I am running XAMMP. BTW - I configured all this and more on Win 7 in about 10 mins, go figure!Rashida
I do all my PHPCS dev on my mac using the built-in PHP version (I have a VM for testing other versions) and just use copy the default php.ini from /etc. I haven't installed XAMMP so I can't really help with how to configure that. Strange that it wouldn't come with a clean working php.ini for the CLI. You could always use the OS X one: cp /etc/php.ini.default /etc/php.ini to see if it works.Barrault
Hi Greg, I have pretty much decided to just do the codesniffer work on the Win 7 PC and use git to propagate. When I have time, I will rebuild the Mac and install the AMP applications separately using something like Homebrew. I am sure this could be resolved with a careful re-install, but I am unwilling to put in the time / effort and possibly end up at the same place. I really appreciate your help even if I can't call anything an answer. If I solve this, I will reply with my own detailed answer, but I suspect I will simply use Homebrew and the built-in PHP.Rashida
H
7

There is an excellent article on how to get it up-and-running:

http://viastudio.com/configure-php-codesniffer-for-mac-os-x/

I followed the easy instructions and had it working in no time!

The secret is to fix the include path with these commands:

sudo mkdir -p /Library/Server/Web/Config/php

sudo touch /Library/Server/Web/Config/php/local.ini

echo 'include_path = ".:'`pear config-get php_dir`'"' | sudo tee -a /Library/Server/Web/Config/php/local.ini
Handedness answered 13/3, 2015 at 23:44 Comment(1)
Posted for the benefit of those who are seeking a resolution and found this question...Handedness
F
2

On MacOS High Sierrra 10.3.2 it is 2 simple steps:

sudo cp /etc/php.ini.default /etc/php.ini
echo 'include_path = ".:'`pear config-get php_dir`'"' | sudo tee -a /etc/php.ini

The last line sets the include_path at the end of the /etc/php.ini file

Fuzz answered 6/2, 2018 at 16:1 Comment(1)
Thanks! it worked for me!Blast
G
0

Working solution on macOs 10.15.5. PHP version used: 7.3.19, installed using homebrew. Pphcs was installed using pear using

sudo pear install PHP_CodeSniffer
  • Step 1. Identify the php version and the php.ini used php -i | grep ini. The output will be something similar to what is given below. Pay attention to the value Loaded Configuration File. The value corresponding to Loaded Configuration File is the file that we need to edit.
Loaded Configuration File => /usr/local/etc/php/7.3/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed => /usr/local/etc/php/7.3/conf.d/ext-opcache.ini,
/usr/local/etc/php/7.3/conf.d/ext-xdebug.ini
user_ini.cache_ttl => 300 => 300
user_ini.filename => .user.ini => .user.ini
Supported handlers => ndbm cdb cdb_make inifile flatfile
init_command_executed_count => 0
init_command_failed_count => 0
  • Step 2. Identify the pear path with pear config-get php_dir. The output will be a path like /usr/local/share/[email protected]. Copy this path.

  • Step 3. Open the configuration file obtained in step 1 and add the following line to it include_path = "PATH OBTAINED IN STEP 2. In this case, include_path = "/usr/local/share/[email protected]"

In essence, what this does is to load all the Pear files when php cli loads.

Galliard answered 23/9, 2020 at 1:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.