PEAR directory problem on Windows

柔情痞子 提交于 2019-12-20 09:45:30

问题


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

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

ERROR: failed to 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:\php5 is in PEAR/go-pear.phar and 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.

Now, I probably could go in and make C:\php5 a 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.

I since looked into pear help install and apparently I can use -P or -R so 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:

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

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

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

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

By now I guess both C:\ and php5 are 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.

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


回答1:


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-set because 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.

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.

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

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




回答2:


A slightly better option than michael h's answer might be:

  1. Open $prefix\pear\PEAR\Config.php where $prefix is the value used in the PEAR installer. (On my Windows system, $prefix was 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);
    }
    

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.

Apparently the PEAR developers overlooked the fact that WINDOWS, Program Files and 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.)




回答3:


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

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:\php5 is the builtin default directory when you don't set another one.




回答4:


you can specify the config file via

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



回答5:


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

I copied pear.ini to C:\windows and everything started to work.




回答6:


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

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

Error got when I run the command. This also happen for PHPDocumentor Solution: 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.

Pear default setting Now change five path in xampp like this

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:\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.

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



来源:https://stackoverflow.com/questions/3255091/pear-directory-problem-on-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!