How can I install Perl DBI on Mac OS X so Apache can find it?

I am trying to set up a Perl development environment on my Mac laptop and am working very hard. I thought everything was set up correctly, but when I try to run the sample script it reports errors in the DBI module and cannot access the DB.

This is what the Apache error logs report:

[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 mentioned 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 when running the above commands is that the files seem to be installed in the directory '/opt/local/lib/perl5/site_perl/5.8.9/darwin-2level/' which doesn't seem to be one of search directories that Apache mentions in the bug at the beginning of this post. This is what I see during installation:

$ 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: 1) get Apache to search in the correct directory where the DBD and DBI modules are installed, or 2) update the way the module is installed to install them in one of the search directories. I honestly don't know which option makes more sense, and could be guided by that as well.

As you can probably tell, I am very lost right now. Please help !!! Thanks in advance.

+2


a source to share


3 answers


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 yours $PATH

than the Perl system in / usr / bin. This is fine if you are happy with Perl 5.8.9 and not Perl 5.10.0 (hint: if you are not sure about the differences, the differences do not matter).

It is generally recommended not to install additional installations on a Perl system. Apple can keep components up to date with regular system updates, which can interfere with any changes you have made, and if you make a mistake during the installation, you have a hard time fixing it without performing a complete system reinstall or having a serious understanding of the operating system whales. you already have another Perl installation, I highly recommend you stick with that.



However, you probably shouldn't manually install libraries if there is already a distribution available for 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 them like any other macports module: with sudo port install <distroname>

. (You may also need to install mod_perl itself.)

After that, you just need to tell Apache / mod_perl to use that Perl installation and not the perl system. I've never done this, so I can't advise on how to do this. However, a quick search at http://superuser.com suggests that the default apache macports version will execute (via the same $ PATH ordering), so I'll just try and See :).

+4


a source


Great answer, broadcast. Having done this too many times, I can give you some tips:

Note. I am apparently limited to one link in the post, so I had to remove all my annotations. Luckily there is Delicious where I saved them all with the stackoverflowmacports tag . Anywhere below where I removed the link matching Stack Overflow, a ridiculous anti-spam measure, I marked it with (*) .



  • If a reliable working development environment is important to you, always rely on the bundled LITTLE Mac OS X software. I love Apple, but they have absolutely no qualms about breaking the custom settings of their software as often as possible.

  • If # 1 sounds like what you need to do, Macports is a GREAT choice . I used to use Fink, but they got lost in the dust a long time ago in terms of ease of use and the range of software available. The easiest way to install macports is via the binary package install method (*)

  • As Ether mentions, when you have everything set up correctly, the Macports provided MySQL, PHP and Apache work well without the intervention of system counterparts. Most of them have to do with the PATH setting, but all these details are handled by the package installers after the flight script (*)

  • Once you're on the Macports train, it should be the first place you look for any software. port search

    and port info

    are constant companions. They currently have 6863 ports (*) that MOST covers your bases.

  • Whenever you need to go outside the Macports realm to find something, set it to /usr/local

    . This part of the file system hierarchy is yours. Don't lull yourself into a false sense of security, and assume that since Macports doesn't have what you install, it's okay to put it in /opt/local

    , because invariably this software will install some dependency that will also be dependent on some. a piece of Macports software down the line, and Macports won't let you install a port if any of its files overwrite an existing file not managed by Macports (unless you force it, which always doesn't work well)

  • If you are working with Perl, and using the Macports version, you are bound to find yourself in a situation. Macports doesn't have the one CPAN module you're looking for. (And, indeed, 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 get tired of the manual install (*) ( perl Makefile.PL; make; make test; sudo make install; cha; cha; cha

    ) method and take a long time for the usability you are used to in Macports.

    If so, you can absolutely use the cpan (*) , CPANPLUS (*) or cpanminus (*) utility for all your installation needs. Just make sure to do the necessary tweaks in your selection tool's setup so that it instructs it to install your modules in / usr / local / lib / perl 5, ignoring the /opt/local/bin/perl

    insistence that modules come in /opt/local/lib/perl5

    . You can set an environment variable PERL5LIB

    in your shell init script to view further /usr/local/lib/perl5

    for modules. Just take the @INC

    output from perl -V

    and tie it to the end ...

  • And finally ... Using system daily init scripts or third party programs such as Anacron (*) or MacPorts Notifier (*) (both available through MacPorts), be sure to update your software frequently . You don't have a parent Apple protecting you with software updates for your installed Macports software that has as many bugs and security vulnerabilities as Apple's packages themselves.

    By updating frequently, you will be ahead of the villains and by automating this the updates will actually happen and you won't end up like I did in the past with a full weekend transition because you had a mountain of legacy ports to update. Note. The macros handle their updates, and if they fail at any point, your current version continues to work. Apple may learn a few of them, I tell you ...

So that's all I can think of. Hope the above tutorials help you quickly and save you all the time, effort, and stress I have experienced in recent years while studying it. I'd say it's even better than the alternative: hate Apple because they break all your nice stuff ... :-)

+2


a source


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

:

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

      

0


a source







All Articles