如何在Mac OS X 10.5 Leopard上设置PEAR [英] How to set up PEAR on Mac OS X 10.5 Leopard

查看:78
本文介绍了如何在Mac OS X 10.5 Leopard上设置PEAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我已经进行了全面搜索,有关如何在Mac OS X 10.5上安装PEAR的教程"有一些变体.但是,我似乎无法让他们中的任何一个工作!有人成功吗?我不完全确定应该设置的一切,因此,如果您可以包括默认"的Mac OS X 10.5包含路径,或者对所有内容应包含的位置进行简单说明,我将不胜感激.

以下教程,我将执行以下操作:

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

我按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

我将Installation prefix更改为/usr/local,按Enter继续,键入Y还要安装PEAR_Frontend_Web-beta, PEAR_Frontend_Gtk2, MDB2.最终,所有东西都安装好了.

下一步...

在第一次尝试中,我认为include_path已从php.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] : 

我键入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

我按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

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

解决方案

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

首先,您需要担心的两个路径.首先是您的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!

这篇关于如何在Mac OS X 10.5 Leopard上设置PEAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆