此问题之前已经解决,我尝试过提供的解决方案,并认为我做错了什么。我正在尝试使用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所在的目录。我跑的时候 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
有什么想法吗?我很容易打字错误,所以总是有可能,所以我放在这里的所有内容都是剪切/粘贴的。
答案 0 :(得分:6)
有一篇关于如何让它正常运行的优秀文章:
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
答案 1 :(得分:1)
在MacOS High Sierrra 10.3.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
答案 2 :(得分:0)
macOS 10.15.5上的工作解决方案。使用的PHP版本:7.3.19,使用自制软件安装。使用Pear使用Pear安装了Pphcs
sudo pear install PHP_CodeSniffer
php -i | grep ini
的php.ini。输出将类似于下面给出的内容。注意值Loaded Configuration File
。与Loaded 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文件。