且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-02-21 22:41:25

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

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

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

因此,我们需要确保

  1. 您网站的php.ini文件的包含路径中包含PEAR目录
  2. 您的命令行php应用程序的php.ini文件在其包含路径中具有PEAR目录
  3. 您的shell应用程序(终端,可能是OS X上的BASH)在其包含路径中包含PEAR目录

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

phpinfo();

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

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

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

将打印出几行,寻找读到类似"Loaded Configuration File"的内容.在文本编辑器中打开此文件,查找include_path变量,然后将该路径添加到您的PEAR目录中(不要删除其他路径,只需添加您的路径即可).

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

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

您的主目录中应该有一个名为".bash_profile"的文件.这是一个隐藏文件,因此不会显示在Finder中.用文本编辑器打开它.如果由于这是一个隐藏文件而遇到麻烦,请使用命令行pico编辑器. Ctrl-X将从pico中保存

cd ~
pico .bash_profile

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

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

这与以下PHP代码大致相同

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

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

pear

这应该为您提供有效的pear命令列表,但更重要的是让您知道梨在您的路径中.

祝你好运!

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.

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.

Following this tutorial 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:

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 prefix to be /usr/local, press enter to continue, type Y to also install PEAR_Frontend_Web-beta, PEAR_Frontend_Gtk2, MDB2. Eventually, everything is installed.

Next...

On the first try, I think include_path was 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:

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 Y and let pear automatically update my include path:

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:

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.

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

First, there's two include 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).

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.

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

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

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).

For number 2, run the following from your command line

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).

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

** 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

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

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

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

$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

pear

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

Good luck!