Tapefreak
Tapefreak

Reputation: 982

How to make a PATH variable availailable to Apache? (OSX Lion)

I have a Python script that is using MySQLdb on OSX Lion. To get MySQLdb to work, I had to add

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

to my ~/.bash_profile. The python script, when executed from the command line, works just fine.

When I try executing the same python script from a PHP script using the exec() function, the python script is unable to locate the library path. Here's the err msg from the Apache log:

ImportError: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Library/Python/2.7/site-packages/_mysql.so
  Reason: image not found

I'm assuming this is a user issue though I'm unclear on how to fix it.

Where should I put this path so that it will be globally available to all scripts and users on my machine? (well at least, to Apache and Root)

Upvotes: 0

Views: 696

Answers (3)

Lance Helsten
Lance Helsten

Reputation: 10047

For Apache you can add PYTHONPATH entry to the EnvironmentVariables section in /System/Library/LaunchDaemons/org.apache.httpd.plist that will make it available to anything Apache runs. See man launchd.plist for details.

For root you can add an export PYTHONPATH to /etc/profile which will make it available to all sh and bash login shells. See man bash for details.

Upvotes: 0

Tapefreak
Tapefreak

Reputation: 982

Solution: creating a soft link did the trick:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

This solution was taken from comments on this post. Perhaps this solution will help another struggling with MySQLdb on OSX.

Though I'm still not clear on why it worked on one user and not another - or, rather, to which file the above mentioned export should have been saved in order to make it available to all. Any explanation on this would be appreciated.

Upvotes: 1

Ivan Kolodyazhny
Ivan Kolodyazhny

Reputation: 574

It looks like you need to modify sys.path array. It initialized from the environment variable PYTHONPATH: http://docs.python.org/library/sys.html#sys.path

Upvotes: 0

Related Questions