如何在 Mac OS X 上安装 Perl 的 DBI,以便 Apache 可以找到它?

发布于 2024-08-30 14:16:32 字数 3544 浏览 5 评论 0原文

我正在尝试在我的 Mac 笔记本电脑上设置 Perl 开发环境,但一直很难让它正常工作。我以为我已经正确配置了所有内容,但是当我尝试运行示例脚本时,它报告 DBI 模块错误并且无法访问数据库。

以下是 Apache 错误日志中报告的内容:

[Fri Apr 30 23:11:33 2010] [error] [client 127.0.0.1] Can't locate DBI.pm in @INC (@INC contains: /Library/Perl/Updates/5.10.0/darwin-thread-multi-2level /Library/Perl/Updates/5.10.0 /System/Library/Perl/5.10.0/darwin-thread-multi-2level /System/Library/Perl/5.10.0 /Library/Perl/5.10.0/darwin-thread-multi-2level /Library/Perl/5.10.0 /Network/Library/Perl/5.10.0/darwin-thread-multi-2level /Network/Library/Perl/5.10.0 /Network/Library/Perl /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level /System/Library/Perl/Extras/5.10.0 .) at main.pm line 5.

我使用 论坛帖子

For DBI

1. cd /Library/Perl/DBI-1.611 
2. sudo Perl Makefile.PL 
3. sudo make 
4. sudo make install 

For DBD

1. cd /Library/Perl/DBD-mysql-4.014 
2. sudo Perl Makefile.PL --mysql_config=/Applications/MAMP/Library/bin/mysql_config 
3. sudo make 
4. sudo make install 

运行上述命令时我注意到这些文件似乎安装在 '/opt/local/lib/perl5/ 中site_perl/5.8.9/darwin-2level/' 目录似乎不是 Apache 在本文开头的错误中提到的搜索目录之一。以下是我在安装过程中看到的内容:

$ sudo make install
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/DBI.bundle
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/dbipport.h
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/DBIXS.h
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/dbixs_rev.h
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/Driver.xst
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/Driver_xst.h
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/TASKS.pod
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBD/DBM.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBD/File.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBD/Gofer.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI/Changes.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI/DBD.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI/Profile.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI/ProxyServer.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI/PurePerl.pm
Installing /opt/local/share/man/man3/DBD::DBM.3pm
Installing /opt/local/share/man/man3/DBD::File.3pm
Installing /opt/local/share/man/man3/DBD::Gofer.3pm
Installing /opt/local/share/man/man3/DBI.3pm
Installing /opt/local/share/man/man3/DBI::DBD.3pm
Installing /opt/local/share/man/man3/DBI::Profile.3pm
Installing /opt/local/share/man/man3/DBI::ProxyServer.3pm
Installing /opt/local/share/man/man3/DBI::PurePerl.3pm
Installing /opt/local/share/man/man3/TASKS.3pm
Installing /opt/local/bin/dbiprof
Installing /opt/local/bin/dbiproxy
Writing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/.packlist
Appending installation info to /opt/local/lib/perl5/5.8.9/darwin-2level/perllocal.pod

我的问题是,我做错了什么以及我该如何 1) 让 Apache 在 DBD 和 DBD 所在的正确目录中查找?安装 DBI 模块或 2) 更新我安装模块的方式以将它们安装到搜索目录之一。老实说,我不知道哪种选择更有意义,也可以使用这方面的指导。

正如你可能知道的那样,我现在很迷茫。请帮忙!!!提前致谢。

I'm trying to setup a Perl development environment on my Mac laptop and have been having a really hard time getting it working. I thought I had everything configured correctly but when I try to run a sample script it is reporting errors with the DBI module and can't access the DB.

Here is what is reported in the Apache error logs:

[Fri Apr 30 23:11:33 2010] [error] [client 127.0.0.1] Can't locate DBI.pm in @INC (@INC contains: /Library/Perl/Updates/5.10.0/darwin-thread-multi-2level /Library/Perl/Updates/5.10.0 /System/Library/Perl/5.10.0/darwin-thread-multi-2level /System/Library/Perl/5.10.0 /Library/Perl/5.10.0/darwin-thread-multi-2level /Library/Perl/5.10.0 /Network/Library/Perl/5.10.0/darwin-thread-multi-2level /Network/Library/Perl/5.10.0 /Network/Library/Perl /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level /System/Library/Perl/Extras/5.10.0 .) at main.pm line 5.

I downloaded and installed both modules manually to work with MAMP using the following commands as specified in this forum post:

For DBI

1. cd /Library/Perl/DBI-1.611 
2. sudo Perl Makefile.PL 
3. sudo make 
4. sudo make install 

For DBD

1. cd /Library/Perl/DBD-mysql-4.014 
2. sudo Perl Makefile.PL --mysql_config=/Applications/MAMP/Library/bin/mysql_config 
3. sudo make 
4. sudo make install 

What I noticed while running the above commands is that the files seems to be getting installed in the '/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/' directory which doesn't seem to be one of the search directories that Apache mentions in the error at the beginning of this post. Here is what I'm seeing during the install:

$ sudo make install
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/DBI.bundle
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/dbipport.h
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/DBIXS.h
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/dbixs_rev.h
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/Driver.xst
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/Driver_xst.h
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/TASKS.pod
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBD/DBM.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBD/File.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBD/Gofer.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI/Changes.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI/DBD.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI/Profile.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI/ProxyServer.pm
Installing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/DBI/PurePerl.pm
Installing /opt/local/share/man/man3/DBD::DBM.3pm
Installing /opt/local/share/man/man3/DBD::File.3pm
Installing /opt/local/share/man/man3/DBD::Gofer.3pm
Installing /opt/local/share/man/man3/DBI.3pm
Installing /opt/local/share/man/man3/DBI::DBD.3pm
Installing /opt/local/share/man/man3/DBI::Profile.3pm
Installing /opt/local/share/man/man3/DBI::ProxyServer.3pm
Installing /opt/local/share/man/man3/DBI::PurePerl.3pm
Installing /opt/local/share/man/man3/TASKS.3pm
Installing /opt/local/bin/dbiprof
Installing /opt/local/bin/dbiproxy
Writing /opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/auto/DBI/.packlist
Appending installation info to /opt/local/lib/perl5/5.8.9/darwin-2level/perllocal.pod

My question is, what am I doing wrong and how can I either 1) Get Apache to look in the right directory where the DBD & DBI modules are installed or 2) Update the way I'm installing the module to install them into one of the search directories. I honestly don't know what option makes more sense and could use guidance on that as well.

As you can probably tell I'm pretty lost at the moment. Please help!!! Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夏日落 2024-09-06 14:16:32

看起来您已经通过 macports 安装了另一个 Perl(/opt/local 是所有 macports 安装所在的位置),并且/opt/local/bin 在 $PATH 中的位置早于 /usr/bin 中的系统 Perl。如果您愿意运行 Perl 5.8.9 而不是 Perl 5.10.0,那很好(提示:如果您不确定差异,那么差异并不重要)。

通常建议不要对系统 Perl 进行额外的安装。 Apple 可能会通过定期系统更新来升级组件,这可能会干扰您所做的任何修改,如果您在安装时犯了错误,那么如果不重新安装完整的系统或对操作系统的内部结构有一些认真的了解,就很难纠正它。因此,既然您已经准备好另一个 Perl 安装,我强烈鼓励您坚持使用该安装。

但是,如果 macports 上已经有可用的发行版,您可能不应该手动安装库。我使用 port search dbiport search dbd 来查找它们:发行版名为 p5-dbi 和 p5-dbd-mysql。您可以像安装任何其他 macports 模块一样安装它们:使用 sudo port install。 (您可能还需要安装 mod_perl 本身。)

之后,您只需告诉 Apache/mod_perl 使用 Perl 安装而不是系统 perl。我从来没有这样做过,所以我无法建议最好的方法。然而,在 http://superuser.com 上的快速搜索表明 apache 的 macports 版本将默认运行(通过相同的 $PATH 顺序),所以我只是尝试一下看看:)。

It looks like you've already installed another Perl via macports (/opt/local is where all macports installations go), and /opt/local/bin is earlier in your $PATH than the system Perl in /usr/bin. That's fine, if you are happy running Perl 5.8.9 rather than Perl 5.10.0 (hint: if you aren't sure of the differences, then the differences don't matter).

It's usually advised to not make extra installations to the system Perl. Apple may upgrade components through regular system updates, which could interfere with any modifications you have made, and if you make a mistake with an installation, it's difficult to remedy it without doing a full system reinstallation or having some serious understanding of the operating system guts. So, since you've already got another Perl installation ready, I would strongly encourage you to stick with that one.

However, you probably shouldn't be manually installing libraries if there is already a distribution available on macports. I used port search dbi and port search dbd to find them: the distributions are named p5-dbi and p5-dbd-mysql. You can install those like any other macports module: with sudo port install <distroname>. (You may need to install mod_perl itself, too.)

After that, you simply need to tell Apache/mod_perl to use that Perl installation rather than the system perl. I've never done that, so I can't advise on the best way to do it. However, quick searches on http://superuser.com suggest that the macports version of apache will run by default (via the same $PATH ordering), so I'd just Try It And See :).

秋叶绚丽 2024-09-06 14:16:32

很好的答案,以太。我已经做过很多次了,我可以给你一些建议:

注意:我显然仅限于帖子中的单个链接,因此我必须删除所有注释。值得庆幸的是,在 Delicious 中,我用 stackoverflowmacports 标签。下面任何我删除链接以适应 Stack Overflow 荒谬的反垃圾邮件措施的地方,我都用 (*) 标记。

  1. 如果有一个可靠工作的开发环境始终对您很重要,请尽可能依赖 Mac OS X 捆绑软件。我喜欢 Apple,但他们绝对会尽可能频繁地破坏其软件的自定义设置。

  2. 如果#1 听起来像您需要做的,Macports 是一个绝佳的选择。我曾经使用过 Fink,但它们在易用性和可用软件范围方面早已落后了。安装 macports 最简单的途径是通过二进制包安装方法(*)

  3. 正如 Ether 提到的,当你正确设置所有内容时,Macports 提供的 MySQL、PHP 和 Apache 都可以协同工作没有系统安装的类似物的干扰。其中大部分与您的 PATH 设置有关,但所有这些详细信息都由软件包安装程序的飞行后脚本处理 (*)

  4. 一旦您登上 Macports 列车,它应该变成您寻找任何软件的第一个地方。 端口搜索端口信息是永远的伴侣。他们目前拥有 6863 个端口(*),涵盖了您的大部分基地。

  5. 当您确实需要到 Macports 领域之外查找某些内容时,请将其安装在 /usr/local 中。文件系统层次结构的这一部分是您可以使用的。不要陷入错误的安全感,并认为因为 Macports 没有您要安装的内容,所以可以将其放在 /opt/local 中,因为该软件总是会安装一些依赖项也将成为某些 Macports 软件的依赖项,如果某个 port 的任何一个文件将覆盖 Macports 不管理的现有文件(除非),Macports 将不允许安装该 port 当您确实

  6. Macports 没有您正在寻找的 CPAN 模块。 (而且,实际上,考虑到有二十五亿个 CPAN 模块,谁能责怪它们呢?)。这种情况经常发生,您很可能会厌倦手动安装方法(*) (perl Makefile.PL; make; make test; sudo make install; cha; cha; cha< /code>)并且渴望您已经习惯了 Macports 的易用性。

    如果是这样,您完全可以使用 cpan (*) 实用程序、CPANPLUS (*) 或 cpanminus (*) 来处理所有您的安装需求。只需确保对您选择的工具的配置进行必要的调整,以指示它将您的模块安装到 /usr/local/lib/perl5 中,忽略 /opt/local/bin /perl 坚持将模块放入 /opt/local/lib/perl5 中。您可以在 shell 的初始化脚本中设置 PERL5LIB 环境变量,以便另外在 /usr/local/lib/perl5 中查找模块。只需从 perl -V 获取 @INC 输出并将其固定在末尾...

  7. 最后...利用系统的每日初始化脚本 或第三方软件,如 Anacron (*) 或 MacPorts Notifier (*)(均通过 MacPorts 可用),请确保经常更新您的软件。你没有苹果母亲通过Macports安装的软件的软件更新来保护你,这些软件与苹果捆绑的相同软件一样有很多错误和安全漏洞。

    通过频繁更新,您将领先于坏人,并且通过自动化,升级实际上会发生,并且您不会像我过去那样度过一个完整的周末因为你有大量过时的端口需要升级。注意:Macports 分阶段进行更新,如果在任何时候失败,您当前的版本将继续工作。我告诉你,苹果可以从他们身上学到一两件事......

所以,这就是我此刻能想到的。希望上面的课程能让你快速上手,并节省我过去几年学习它所经历的所有时间、精力和压力。我认为它仍然比替代方案要好得多:讨厌苹果,因为它们破坏了你所有的好东西......:-)

Great answer, Ether. Having done this far too many times to count, I can give you a few pieces of advice:

Note: I am apparently limited to a single link in the post, so I had to remove all of my annotations. Thankfully, there is Delicious where I've stored them all with a stackoverflowmacports tag. Any place below where I removed a link to fit under Stack Overflow's ridiculous anti-spam measure, I've marked it with (*).

  1. If having a reliably-working development environment at all times is important to you, rely on as LITTLE Mac OS X bundled software as possible. I love Apple but they have absolutely no qualms about breaking custom setups of their software as often as possible.

  2. If #1 sounds like what you need to do, Macports is an EXCELLENT choice. I used to use Fink but they got left in the dust ages ago in terms of ease of use and spectrum of available software. The easiest route to installing macports is via the binary package install method (*)

  3. As Ether mentions, when you have everything set up correctly, the Macports-provided MySQL, PHP and Apache all work together well without the system-installed analogs interfering. Most of that has to do with your PATH setting but all of those details are handled by the package installers post-flight script (*)

  4. Once you're on the Macports train, it should become the very first place you look for any software. port search and port info are constant companions. They've got 6863 ports (*) currently which covers MOST of your bases.

  5. When you do need to go outside of the Macports realm to find something, install it in /usr/local. That part of the file system hierarchy is yours to play with. Don't be lulled into a false sense of security and think that because Macports doesn't have what you're installing, it's okay to put it in /opt/local because invariably that software will install some dependency that will ALSO be a dependency for some piece of Macports software down the line and Macports will not allow a port to be installed if any one of its files would overwrite an existing file not managed by Macports (unless you force it which is always bad manners)

  6. If you do any work with Perl and you use Macports' version, you will absolutely find yourself in a situation Macports doesn't have the one CPAN module you're looking for. (And, really, given that there are two and a half billion CPAN modules, who can blame them?). This will happen often enough that you will most likely tire of the manual installation method (*) (perl Makefile.PL; make; make test; sudo make install; cha; cha; cha) and long for the ease of use you've grown accustomed to with Macports.

    If so, you can absolutely use the cpan (*) utility, CPANPLUS (*) or cpanminus (*) for all of your installing needs. Just make sure to make the necessary adjustments in the configuration of your tool of choice to instruct it to install your modules into /usr/local/lib/perl5, ignoring /opt/local/bin/perl's insistence that modules go into /opt/local/lib/perl5. You can set the PERL5LIB environment variable in your shell's init scripts to additionally look in /usr/local/lib/perl5 for modules. Just grab the @INC output from perl -V and tack it on the end...

  7. And finally... Leveraging the system's daily init scripts or third-party software like Anacron (*) or MacPorts Notifier (*) (both available through MacPorts), make sure to update your software frequently. You don't have Mother Apple protecting you with Software Updates for the Macports installed software which have just as many bugs and security exploits as the very same software Apple bundles.

    By updating frequently, you'll stay ahead of the baddies and by automating it, the upgrades will actually happen and you won't end up as I have in the past with a full weekend blown because you had a mountain of outdated ports to upgrade. Note: Macports stages its updates and if it fails at any point, your current version continues to work. Apple could learn a thing or two from them, I tell ya...

So, that's all I can think of a the moment. Hopefully the lessons above will get you going quickly and save all of the time, effort and stress I've experienced in past years in learning it. I would argue it's still far better than the alternative: Hating Apple because they break all of your nice things... :-)

比忠 2024-09-06 14:16:32

我在使用错误的 Perl 时遇到了类似的 Apache 问题。我通过将以下行附加到我的 httpd.conf 文件来修复它:

SetEnv PATH [colon-separated list of directories]

SetEnv PERL5LIB [colon-sep'd list of directories]

在我的例子中,它看起来像这样:

SetEnv PATH /opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/mysql/bin:$PATH
SetEnv PERL5LIB  /opt/local/lib:/usr/local/lib

I had a similar problem with Apache using the wrong Perl. I fixed it by appending the following lines to my httpd.conf file:

SetEnv PATH [colon-separated list of directories]

SetEnv PERL5LIB [colon-sep'd list of directories]

In my case, it looked like this:

SetEnv PATH /opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/mysql/bin:$PATH
SetEnv PERL5LIB  /opt/local/lib:/usr/local/lib
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文