# libz.so.6 not found by mod_wsgi in jail



## alexii (Mar 10, 2013)

Hi, I believe this is a FreeBSD question and not a Python or mod_wsgi question, I hope everyone agrees.

Running 9.1 64-bit, created a jail with ezjail: `# ezjail-admin create jail.domain.com 10.0.0.1` installed apache22-worker-mpm and mod_wsgi3 from ports in the jail, and copied in Python scripts from a different FreeBSD system on which everything works (hence the problem is not my Python scripts).

When I visit the new web app, I get the familiar 
	
	



```
server encountered an internal error or misconfiguration
```
 and the Apache error log reads as follows:


```
[Sun Mar 10 23:15:16 2013] [error] [client 192.168.2.2]   File "/usr/local/www/wsgi/main/index.py", line 3, in <module>
[Sun Mar 10 23:15:16 2013] [error] [client 192.168.2.2]     from urllib2 import urlopen
[Sun Mar 10 23:15:16 2013] [error] [client 192.168.2.2]   File "/usr/local/lib/python2.7/urllib2.py", line 92, in <module>
[Sun Mar 10 23:15:16 2013] [error] [client 192.168.2.2]     import base64
[Sun Mar 10 23:15:16 2013] [error] [client 192.168.2.2]   File "/usr/local/lib/python2.7/base64.py", line 10, in <module>
[Sun Mar 10 23:15:16 2013] [error] [client 192.168.2.2]     import binascii
[Sun Mar 10 23:15:16 2013] [error] [client 192.168.2.2] ImportError: Shared object "libz.so.6" not found, required by "binascii.so"
```

Clearly urllib2 imports binascii which looks for libz.so.6 but does not find it. The curious thing is that in the problem jail, I can import and use both urllib2 and binascii from the python interpreter without issue. The mod_wsgi interpreter is behaving differently and I can't figure out why.

I have also confirmed that both /lib/libz.so.6 and /usr/lib32/libz.so.6 exist in the jail and are readable.

Additional information upon request.

Thoughts?


----------



## Carpetsmoker (Mar 11, 2013)

You can check if the linker picks up libz with:
[cmd=]ldconfig -r | grep libz\.so[/cmd]

In addition, you can view library dependencies about a binary or library like so:
[cmd=]ldd /usr/local/lib/python2.7/lib-dynload/binascii.so[/cmd]


Your problem probably has something to do with the environment Python is run in, I've never used Apache with wgsi, but you can try making a simple test-script, run that in apache/wsgi, and make it print out (or write to log) some debug information (*pprint.pprint* is useful here). Compare that with whatever you get from the shell and look for differences.

For example, you could try:
- os.environ
- sys.modules
- sys.path
- Above ldd and ldconfig commands (Using os.system or the subprocess module if that works)
- Make sure your Apache user has read permissions. (ie open('/lib/libz.so.6', 'rb') should raise an Exception if it's not readable).

Also make sure you're using the same Python version on the shell as Apache uses (sorry if this sounds too basic, just making sure).

If this doesn't shed any light, post your (preferably complete) apache configuration.



> Clearly urllib2 imports binascii



Well, bit of a nitpick, but not exactly. urllib2 imports base64 which imports binascii.


----------

