【问题标题】:Wrong include_path for CodesnifferCodesniffer 的 include_path 错误
【发布时间】:2013-02-25 06:38:55
【问题描述】:

此问题之前已解决,我已尝试提供的解决方案并认为我做错了什么。我正在尝试使用 Mountaion Lion 在 Mac 上配置 PHP Codesniffer。我认为这并不重要,但我使用 XAMMP。运行 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

这个错误,基于所有的搜索,是因为 php.ini 中的 include_path 不正确。 据我了解,这条路径应该是梨所在的目录。当我跑 pear config-get php_dir 它返回 /usr/lib/php/pear 我期望这个。 所以我修改了php.ini文件(这个文件是系统上唯一的php.ini,所以不是从另一个文件中抓取设置)改为:

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

这看起来不错,但我一直收到同样的错误。我已经删除了领先的 .: 但这没有帮助......而且它不应该工作。我还删除了尾随 / 和相同的结果。 请注意,phpcs 位于 usr/bin 目录中。 下面是运行 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

有什么想法吗?我很容易出现拼写错误,所以这总是有可能的,所以我放在这里的所有东西都是剪切/粘贴的。

【问题讨论】:

  • 当您更改 include_path 时,错误消息是否会更改为向您显示新路径?如果没有,请运行 php --ini 以查看它正在使用哪个 ini 文件(如果有)。
  • 嗨,格雷格,感谢您的回复。系统上只有一个 php.ini。当我运行 php --ini 它返回:配置文件(php.ini)路径:/etc 加载的配置文件:(无)扫描其他 .ini 文件:(无)解析的其他 .ini 文件:(无)跨度>
  • 您的其他 php.ini 可能正在用于 Apache 或其他 Web 服务器,或者它可能根本没有被使用。尝试将该 php.ini 复制到 /etc/php.ini,这可以是您从现在开始编辑的命令行之一。看看它是否可以放置在那里。
  • 嗨,格雷格,发生了一件奇怪的事情。我将我的一个 php.ini 文件复制到 /private/etc 并运行 php --ini 这一次它识别了该文件,但是当我运行 phpcs 时,我得到了一堆看起来像这样的附加错误: PHP 警告:PHP 启动:无法加载动态链接库 .... 路径 .... 文件名。这个错误重复了大约 20 个不同的文件。我现在正在调查这些错误。它们似乎与系统上有不同版本的 PHP 有关。 Mountain Lion 自带,我正在运行 XAMMP。顺便说一句 - 我在大约 10 分钟内在 Win 7 上配置了所有这些以及更多内容,去看看吧!
  • 我在我的 Mac 上使用内置的 PHP 版本(我有一个用于测试其他版本的 VM)来完成我所有的 PHPCS 开发,并且只使用从 /etc 复制默认的 php.ini。我还没有安装 XAMMP,所以我无法真正帮助如何配置它。奇怪的是它不会为 CLI 提供干净的工作 php.ini。你总是可以使用 OS X 的:cp /etc/php.ini.default /etc/php.ini 看看它是否有效。

标签: pear codesniffer xampp


【解决方案1】:

macOS 10.15.5 上的工作解决方案。使用的 PHP 版本:7.3.19,使用自制软件安装。 Pphcs 是使用 pear 安装的

sudo pear install PHP_CodeSniffer
  • 步骤 1. 识别 php 版本和使用的 php.ini php -i | grep ini。输出将类似于下面给出的内容。注意值Loaded Configuration FileLoaded Configuration File对应的值就是我们需要编辑的文件。
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
  • 第 2 步。使用pear config-get php_dir 识别梨路径。输出将是类似/usr/local/share/pear@7.3 的路径。复制此路径。

  • 步骤3.打开步骤1中获得的配置文件,添加以下行 include_path = "PATH OBTAINED IN STEP 2。在这种情况下,include_path = "/usr/local/share/pear@7.3"

本质上,它的作用是在 php cli 加载时加载所有 Pear 文件。

【讨论】:

    【解决方案2】:

    在 MacOS High Sierra 10.3.2 上只需 2 个简单步骤:

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

    最后一行将include_path 设置在/etc/php.ini 文件的末尾

    【讨论】:

    • 谢谢!它对我有用!
    【解决方案3】:

    有一篇关于如何启动并运行它的优秀文章:

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

    我按照简单的说明操作,很快就可以使用了!

    秘诀是使用以下命令修复包含路径:

    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
    

    【讨论】:

    • 为那些寻求解决方案并发现此问题的人而发布...
    猜你喜欢
    • 2013-06-07
    • 2012-12-24
    • 2015-01-05
    • 2016-04-10
    • 2013-01-29
    • 1970-01-01
    • 2020-06-03
    • 1970-01-01
    • 2012-06-26
    相关资源
    最近更新 更多