php 如何在 Mac OS X 10.5 Leopard 上设置 PEAR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/628838/
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-08-24 23:19:09  来源:igfitidea点击:

How to set up PEAR on Mac OS X 10.5 Leopard

phpmacospearosx-leopard

提问by Andrew

I'm ultimately trying to install PEAR so I can easily install PHPUnit. I want to set up a Mac, Apache, MySQL, PHP, PHPUnit development environment so I can test locally. I already have Apach, MySQL and PHP working. Now all I need is PHPUnit, which means I need PEAR to install it.

我最终尝试安装 PEAR,以便我可以轻松安装 PHPUnit。我想搭建一个 Mac、Apache、MySQL、PHP、PHPUnit 开发环境,以便在本地进行测试。我已经在使用 Apache、MySQL 和 PHP。现在我只需要 PHPUnit,这意味着我需要 PEAR 来安装它。

I have searched all over, and there are a few variations of "the tutorial" on how to install PEAR on Mac OS X 10.5. However, I can't seem to get any of them to work! Has anyone had success with this? I'm not totally confident that I have everything set up as it should be, so if you could include the "default" Mac OS X 10.5 include paths, or a simple explanation of where everything should go, I would appreciate it.

我搜索了很多遍,关于如何在 Mac OS X 10.5 上安装 PEAR 的“教程”有一些变体。但是,我似乎无法让它们中的任何一个工作!有没有人在这方面取得成功?我并不完全相信我已经按原样设置了所有内容,因此,如果您可以包含“默认”Mac OS X 10.5 包含路径,或者对所有内容应该放在何处的简单说明,我将不胜感激。

Following thistutorial I do the following:

按照教程,我执行以下操作:

curl http://pear.php.net/go-pear > go-pear.php
sudo php -q go-pear.php

I press enter until I get to a list with 7 include paths:

我按 Enter 直到我看到一个包含 7 个包含路径的列表:

1. Installation prefix ($prefix) : /Users/andrew
2. Temporary files directory     : $prefix/temp
3. Binaries directory            : $prefix/bin
4. PHP code directory ($php_dir) : $prefix/PEAR
5. Documentation base directory  : $php_dir/docs
6. Data base directory           : $php_dir/data
7. Tests base directory          : $php_dir/tests

I change the Installation prefixto be /usr/local, press enter to continue, type Yto also install PEAR_Frontend_Web-beta, PEAR_Frontend_Gtk2, MDB2. Eventually, everything is installed.

我将其更改Installation prefix/usr/local,按 Enter 继续,键入Y也安装PEAR_Frontend_Web-beta, PEAR_Frontend_Gtk2, MDB2. 最终,一切都安装好了。

Next...

下一个...

On the first try, I think include_pathwas commented out of the php.ini file, but since I've already changed this line, and this is not the first time I've tried installing, I get the following message:

第一次尝试时,我认为include_pathphp.ini 文件被注释掉了,但由于我已经更改了这一行,而且这不是我第一次尝试安装,我收到以下消息:

WARNING!  The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
</usr/local/PEAR>
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.

Would you like to alter php.ini </private/etc/php.ini>? [Y/n] : 

I type Yand let pear automatically update my include path:

我输入Y并让 pear 自动更新我的包含路径:

php.ini </private/etc/php.ini> include_path updated.

Current include path           : .:/usr/share/pear
Configured directory           : /usr/local/PEAR
Currently used php.ini (guess) : /private/etc/php.ini

I press enter to continue, and get the following message:

我按 Enter 继续,并收到以下消息:

The 'pear' command is now at your service at /usr/local/bin/pear

** The 'pear' command is not currently in your PATH, so you need to
** use '/usr/local/bin/pear' until you have added
** '/usr/local/bin' to your PATH environment variable.

Run it without parameters to see the available actions, try 'pear list'
to see what packages are installed, or 'pear help' for help.

For more information about PEAR, see:

  http://pear.php.net/faq.php
  http://pear.php.net/manual/

Thanks for using go-pear!

PHP Warning:  rmdir(/usr/local/temp): Not a directory in /Users/andrew/go-pear.php on line 1237

Warning: rmdir(/usr/local/temp): Not a directory in /Users/andrew/go-pear.php on line 1237

Update:I think I know why these last two warnings came up. Previously, I tried to fix the temp directory problem by creating a symbolic link to /tmp but if I understand correctly, PEAR is trying to create its own temp directory for installation, then it's going to delete it when it's finished. So I should not have created this symbolic link since it's going to try to delete the temp directory when the installation has finished.

更新:我想我知道为什么会出现最后两个警告。以前,我试图通过创建指向 /tmp 的符号链接来解决临时目录问题,但如果我理解正确,PEAR 正在尝试创建自己的临时目录进行安装,然后它会在完成后将其删除。所以我不应该创建这个符号链接,因为它会在安装完成后尝试删除临时目录。

回答by Alan Storm

There's a few things that could be going wrong here, these are only guesses.

这里有一些事情可能会出错,这些只是猜测。

First, there's twoinclude paths you'll need to worry about. The first is your PHP include path. PEAR libraries are (mostly) just PHP code, specially packaged up. When you install a PEAR module you're downloading all the PHP code needed for that library, and any other PEAR libraries the library you're installing rely on (sorry about that sentence, but I'm not sure there's a better way to say that). This include path is set in your php.ini files (one file for your command line php, another for yoru web server php; often the same file).

首先,您需要担心两个包含路径。第一个是您的 PHP 包含路径。PEAR 库(大部分)只是专门打包的 PHP 代码。当您安装 PEAR 模块时,您正在下载该库所需的所有 PHP 代码,以及您正在安装的库所依赖的任何其他 PEAR 库(抱歉这句话,但我不确定有没有更好的说法那)。这个包含路径在你的 php.ini 文件中设置(一个文件用于命令行 php,另一个用于 yoru web 服务器 php;通常是同一个文件)。

The second include path you'll need to worry about is your UNIX/shell include path. This is the path that your computer will search for commands in when you enter a command from a terminal. The 'pear' command is a command line command.

您需要担心的第二个包含路径是您的 UNIX/shell 包含路径。当您从终端输入命令时,这是您的计算机将在其中搜索命令的路径。'pear' 命令是一个命令行命令。

So, we need to make sure that

所以,我们需要确保

  1. The php.ini file for your website has the PEAR directory in its include path
  2. The php.ini file for your command line php application has the PEAR directory in its include path
  3. Your shell application (terminal, likely BASH in you're on OS X) has the PEAR directory in its include path
  1. 您网站的 php.ini 文件在其包含路径中包含 PEAR 目录
  2. 命令行 php 应用程序的 php.ini 文件在其包含路径中包含 PEAR 目录
  3. 您的 shell 应用程序(终端,可能是 OS X 中的 BASH)在其包含路径中包含 PEAR 目录

So, for number 1, put a PHP page on your server that include the function call

因此,对于数字 1,在您的服务器上放置一个包含函数调用的 PHP 页面

phpinfo();

This will list a bunch of information about your server. Look for the location of php.ini. Open this file in a text editor, look for the include_path variable, and add the path to your PEAR directory (don't remove the other paths, just add yours).

这将列出一堆有关您的服务器的信息。查找 php.ini 的位置。在文本编辑器中打开此文件,查找 include_path 变量,并将路径添加到您的 PEAR 目录(不要删除其他路径,只需添加您的路径)。

For number 2, run the following from your command line

对于数字 2,从命令行运行以下命令

php -r "phpinfo();" | grep '.ini'

A bunch of lines will print out, look for the one that reads something like "Loaded Configuration File". Open this file in a text editor, look for the include_path variable, and add the path to your PEAR directory (don't remove the other paths, just add yours).

将打印出一串行,查找读取诸如“加载的配置文件”之类的行。在文本编辑器中打开此文件,查找 include_path 变量,并将路径添加到您的 PEAR 目录(不要删除其他路径,只需添加您的路径)。

Finally, and this is what I think your problem is, we need to ensure that the pear command line command is in your shell/bash path. That's what this error is refering to

最后,这就是我认为您的问题所在,我们需要确保 pear 命令行命令在您的 shell/bash 路径中。这就是这个错误所指的

** The 'pear' command is not currently in your PATH, so you need to

There should be a file in your home directory named '.bash_profile'. It's a hidden file, so it won't showup in the Finder. Open it with a text editor. If you're having trouble because this is a hidden file, use the command line pico editor. Ctrl-X will save from pico

您的主目录中应该有一个名为“.bash_profile”的文件。这是一个隐藏文件,所以它不会出现在 Finder 中。用文本编辑器打开它。如果您因为这是一个隐藏文件而遇到问题,请使用命令行 pico 编辑器。Ctrl-X 将从 pico 保存

cd ~
pico .bash_profile

This file gets executed by your shell everytime you open a terminal window. We're going to add /usr/local/bin to your PATH, which means when you attempt to run a command, yoru computer will search for the command in this folder. Add the following line to the bottom of .bash_profile

每次打开终端窗口时,该文件都会由您的 shell 执行。我们要将 /usr/local/bin 添加到您的 PATH,这意味着当您尝试运行命令时,您的计算机将在此文件夹中搜索该命令。将以下行添加到 .bash_profile 的底部

export PATH=/usr/local/bin:$PATH

This is, more or less, equivilant to the following PHP code

这或多或少等同于以下 PHP 代码

$PATH = '/usr/local/bin:'.$PATH

You're adding /usr/local/bin as the first colon-delimited place to look for command, and then adding the rest of the existing path to it. Once you've added that line, close your terminal, re-open it, and then type

您将 /usr/local/bin 添加为第一个以冒号分隔的位置来查找命令,然后将现有路径的其余部分添加到它。添加该行后,关闭终端,重新打开它,然后键入

pear

This should give you a list of valid pear commands, but more importantly will let you know pear is in your path.

这应该会给你一个有效的 pear 命令列表,但更重要的是会让你知道 pear 就在你的路径中。

Good luck!

祝你好运!

回答by Andrew

I figured it out. You "HAVE TO" run the go-pear.php at where you want pear installed, so you need to run it under /usr/local if you want pear binary to be installed under /usr/local/bin

我想到了。你“必须”在你想要安装 pear 的地方运行 go-pear.php,所以如果你想在 /usr/local/bin 下安装 pear 二进制文件,你需要在 /usr/local 下运行它

:-)

:-)

回答by Andrew

user "bryan kennedy" (above) wanted to know the syntax for the "include_path" change needed in "php.ini"

用户“bryan kennedy”(上图)想知道“php.ini”中需要的“include_path”更改的语法

(I had a similar problem to the OP and I just fixed the issue with the help of this post.)

(我遇到了与 OP 类似的问题,我只是在这篇文章的帮助下解决了这个问题。)

the change to php.ini will look like...

对 php.ini 的更改将如下所示...

include_path=".:/path_to_pear_dir/PEAR"

this is how it looks when you allow "go-pear.php" to make the change....

这是当您允许“go-pear.php”进行更改时的样子....

;***** Added by go-pear
include_path=".:/usr/local/bin/PEAR"
;*****