Windows 上的 PEAR 目录问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3255091/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:50:24  来源:igfitidea点击:

PEAR directory problem on Windows

phpwindowspear

提问by Joey

I've downloaded the ZIP archive of PHP and extracted it under my profile. I then needed some PEAR packages. go-pear.batapparently installed PEAR just fine, I just needed to go into the pear.batfile afterwards and adapt the path to php.exe– no big deal and after that it ran.

我已经下载了 PHP 的 ZIP 存档并将其解压缩到我的个人资料下。然后我需要一些 PEAR 包。go-pear.bat显然 PEAR 安装得很好,我只需要在pear.bat之后进入文件并调整路径php.exe- 没什么大不了的,然后它就运行了。

However, when I try installing something I get the following error:

但是,当我尝试安装某些东西时,出现以下错误:

ERROR: failed to mkdir C:\php5\pear\data\Console_CommandLine\data

错误:无法 mkdir C:\php5\pear\data\Console_CommandLine\data

Naturally, no write access is allowed in the root directory but I'm a little at a loss to know how exactly PEAR thinks it should install anything in a location that neither exists nor is configured anywhere. PHP currently resides somewhere below H:\(subst'ed to my profile). All paths I entered during PEAR installation were sane and the only place I can find C:\php5is in PEAR/go-pear.pharand in the documentation. One of those is something I shouldn't change anyway, I guess and the other thing is hardly relevant for the program itself.

自然地,根目录中不允许写访问,但我有点不知道 PEAR 到底认为它应该在一个既不存在也没有配置的位置安装任何东西。PHP 目前驻留在下面的某个地方H:\(subst'ed 到我的个人资料)。我在 PEAR 安装过程中输入的所有路径都是正常的,我唯一能找到的地方C:\php5是在PEAR/go-pear.phar文档中。其中之一是我无论如何都不应该改变的东西,我想另一件事与程序本身几乎无关。

Now, I probably could go in and make C:\php5a junction/symlink to the directory where PHP lies currently or actually install it in that location – both things I'd rather avoid since this was originally just intended for a little test of something.

现在,我可能可以进入并创建C:\php5一个连接/符号链接到 PHP 当前所在的目录或实际将其安装在该位置 - 我宁愿避免这两件事,因为这最初只是为了对某些东西进行一些测试。

I since looked into pear help installand apparently I can use -Por -Rso set some paths. The exact difference between those is still unclear to me but it won't hurt to try them, I guess. Somehow the results were ... unexpected:

我从那以后调查过pear help install,显然我可以使用-P-R设置一些路径。我仍然不清楚它们之间的确切区别,但我想尝试它们不会有什么坏处。结果……出乎意料:

-P H:\Downloads\php\PEARresulted in the fun error (among others)

-P H:\Downloads\php\PEAR导致有趣的错误(除其他外)

ERROR: failed to mkdir C:\Downloads\php\PEAR\php5\pear\data\Console_CommandLine\data

错误:无法 mkdir C:\Downloads\php\PEAR\php5\pear\data\Console_CommandLine\data

while -Rusing the same path (apparently -Rdictates where downloads are stored, since that worked before I guess I shouldn't touch this) resulted in even more fun:

虽然-R使用相同的路径(显然-R决定了下载的存储位置,因为在我想我不应该碰它之前它起作用了)导致了更多的乐趣:

download directory "C:\Downloads\php\PEAR\Users\JOHANN~1\AppData\Local\Temp\pear\download" is not writeable. Change download_dir config variable to a writeable dir

下载目录“C:\Downloads\php\PEAR\Users\JOHANN~1\AppData\Local\Temp\pear\download”不可写。将 download_dir 配置变量更改为可写目录

By now I guess both C:\and php5are somewhere hardcoded for no apparent reason (my environment variables also contain nothing of that sort) so I'll go digging again, this time looking for shorter string and therefore longer result lists.

现在我想都C:\php5被硬编码的地方没有明显的原因(我的环境变量中还含有什么之类的),所以我会去再次挖掘,这次寻找较短的字符串,因此不再结果列表。

But if anyone has an idea about this in the meantime, this might be helpful.

但是,如果在此期间有人对此有所了解,这可能会有所帮助。

回答by hashchange

The problem is that PEAR looks for its ini file in the Windows directory, and because it doesn't find it there, it resorts to guessing the location. Even worse, you can't change any configuration settings with pear config-setbecause PEAR doesn't have a pear.ini to write to. At the same time, PEAR ignores an existing pear.ini file in its own directory. It's a mess. See this bug report.

问题是 PEAR 在 Windows 目录中寻找它的 ini 文件,并且因为它没有在那里找到它,所以它诉诸于猜测位置。更糟糕的是,您无法更改任何配置设置,pear config-set因为 PEAR 没有可写入的 pear.ini。同时,PEAR 会忽略其自身目录中的现有 pear.ini 文件。一团糟。请参阅此错误报告

If there is just one global PEAR install, PEAR can be told where to look for an ini file by creating an environment variable, PHP_PEAR_SYSCONF_DIR, pointing to the right directory.

如果只有一个全局 PEAR 安装,则可以通过创建PHP_PEAR_SYSCONF_DIR指向正确目录的环境变量 来告诉 PEAR 在哪里查找 ini 文件。

But if there are multiple, local PEAR installs, you'll have to patch pear.bat by adding this line:

但是,如果有多个本地 PEAR 安装,则必须通过添加以下行来修补 pear.bat:

IF "%PHP_PEAR_SYSCONF_DIR%"=="" SET "PHP_PEAR_SYSCONF_DIR=C:\path\to\pear.ini\directory"

IF "%PHP_PEAR_SYSCONF_DIR%"=="" SET "PHP_PEAR_SYSCONF_DIR=C:\path\to\pear.ini\directory"

回答by Unsigned

A slightly better option than michael h's answermight be:

michael h 的答案稍好的选择可能是:

  1. Open $prefix\pear\PEAR\Config.phpwhere $prefixis the value used in the PEAR installer. (On my Windows system, $prefixwas C:\php\5.4.0)

  2. Find the section below:

    if (getenv('PHP_PEAR_SYSCONF_DIR')) {
        define('PEAR_CONFIG_SYSCONFDIR', getenv('PHP_PEAR_SYSCONF_DIR'));
    } elseif (getenv('SystemRoot')) {
        define('PEAR_CONFIG_SYSCONFDIR', getenv('SystemRoot'));
    } else {
        define('PEAR_CONFIG_SYSCONFDIR', PHP_SYSCONFDIR);
    }
    
  3. And make the following changes:

    if (getenv('PHP_PEAR_SYSCONF_DIR')) {
        define('PEAR_CONFIG_SYSCONFDIR', getenv('PHP_PEAR_SYSCONF_DIR'));
    //} elseif (getenv('SystemRoot')) {
        //define('PEAR_CONFIG_SYSCONFDIR', getenv('SystemRoot'));
    } else {
        //define('PEAR_CONFIG_SYSCONFDIR', PHP_SYSCONFDIR);
    
        // This next line is new
        define('PEAR_CONFIG_SYSCONFDIR', $PEAR_INSTALL_DIR);
    }
    
  1. Open $prefix\pear\PEAR\Config.phpwhere$prefix是 PEAR 安装程序中使用的值。(在我的 Windows 系统上,$prefixC:\php\5.4.0

  2. 找到以下部分:

    if (getenv('PHP_PEAR_SYSCONF_DIR')) {
        define('PEAR_CONFIG_SYSCONFDIR', getenv('PHP_PEAR_SYSCONF_DIR'));
    } elseif (getenv('SystemRoot')) {
        define('PEAR_CONFIG_SYSCONFDIR', getenv('SystemRoot'));
    } else {
        define('PEAR_CONFIG_SYSCONFDIR', PHP_SYSCONFDIR);
    }
    
  3. 并进行以下更改:

    if (getenv('PHP_PEAR_SYSCONF_DIR')) {
        define('PEAR_CONFIG_SYSCONFDIR', getenv('PHP_PEAR_SYSCONF_DIR'));
    //} elseif (getenv('SystemRoot')) {
        //define('PEAR_CONFIG_SYSCONFDIR', getenv('SystemRoot'));
    } else {
        //define('PEAR_CONFIG_SYSCONFDIR', PHP_SYSCONFDIR);
    
        // This next line is new
        define('PEAR_CONFIG_SYSCONFDIR', $PEAR_INSTALL_DIR);
    }
    

This solution is less hazard-prone when dealing with multiple PHP/PEAR versions/installations, especially when running more than one at the same time, as you avoid environment clobbering.

在处理多个 PHP/PEAR 版本/安装时,此解决方案不太容易发生危险,尤其是在同时运行多个版本时,因为您可以避免环境破坏。

Apparently the PEAR developers overlooked the fact that WINDOWS, Program Filesand friends have been deprecated as application-data directories since Windows Vista, and are generally no longer writable by non-elevated applications. (For good security reasons.)

显然,PEAR 开发人员忽略了一个事实,即从 Windows Vista 开始不推荐使用WINDOWS,Program Files和朋友作为应用程序数据目录,并且通常不再由非提升的应用程序写入。(出于良好的安全原因。)

回答by álvaro González

Look at the config-...parameters of the PEAR command:

查看config-...PEAR命令的参数:

config-create          Create a Default configuration file
config-get             Show One Setting
config-help            Show Information About Setting
config-set             Change Setting
config-show            Show All Settings

I presume C:\php5is the builtin default directory when you don't set another one.

C:\php5当您不设置另一个目录时,我认为是内置的默认目录。

回答by cweiske

you can specify the config file via

您可以通过指定配置文件

pear -c /path/to/config/file $command

回答by pog

I've had the same problem. My config file was missing from the C:\Windowsdirectory - there is definitely something wrong with the go-pear installer - I specified a different INIfile location, yet my wish has not come true.

我遇到了同样的问题。我的配置文件从C:\Windows目录中丢失- go-pear 安装程序肯定有问题 - 我指定了一个不同的INI文件位置,但我的愿望没有实现。

I copied pear.inito C:\windowsand everything started to work.

我复制pear.iniC:\windows,一切都开始工作。

回答by Mr. Piyush Ghosh

If your PHP installation has been done somewhere else other than the C:\ drive, then “pear install” command may throw errors.

如果您的 PHP 安装已在 C:\ 驱动器以外的其他位置完成,则“pear install”命令可能会引发错误。

Example: Here in my case, the xampp has been installed into E:\ drive and the “pear install” throws error.

示例:在我的情况下,xampp 已安装到 E:\ 驱动器中,并且“pear install”引发错误。

Error got when I run the command. This also happen for PHPDocumentorSolution: I get into the “pear” directory and checked config values set for different pear related directories. All were set to C:\ drive by default. So, we need to change those settings to correct path. Open the command prompt in "Run as administrator" mode.

运行命令时出错。这也发生在 PHPDocumentor解决方案:我进入“pear”目录并检查为不同的 pear 相关目录设置的配置值。默认情况下,所有都设置为 C:\ 驱动器。因此,我们需要将这些设置更改为正确的路径。在“以管理员身份运行”模式下打开命令提示符。

Pear default settingNow change five path in xampp like this

梨默认设置现在像这样更改xampp中的五个路径

E:\xampp\php>
E:\xampp\php>pear config-set doc_dir E:\xampp\php\pear

If you are using C drive and getting the same error then also the above statement will remain same just replace the drive name E:\ to C:\ vice versa. example for C: drive

如果您使用 C 驱动器并收到相同的错误,那么上述语句也将保持不变,只需将驱动器名称 E:\ 替换为 C:\,反之亦然。C:驱动器的示例

C:\xampp\php>pear config-set doc_dir C:\xampp\php\pear

Then press enter it will display a msg of config-set succeeded

然后按回车会显示配置设置成功的消息

Like this you have to enter 5 commands.

像这样,您必须输入 5 个命令。

E:\xampp\php>pear config-set doc_dir E:\xampp\php\pear

config-set succeeded

配置集成功

E:\xampp\php>pear config-set cfg_dir E:\xampp\php\pear

config-set succeeded

配置集成功

E:\xampp\php>pear config-set data_dir E:\xampp\php\pear

config-set succeeded

配置集成功

E:\xampp\php>pear config-set test_dir E:\xampp\php\pear

config-set succeeded

配置集成功

E:\xampp\php>pear config-set www_dir E:\xampp\php\pear

config-set succeeded

配置集成功

Finally installed pear

最后安装梨