How do I replace/update the version of the expat library used by Apache?
Asked Answered
S

1

0

(Disclaimer: I just started using Linux and don't have much experience with configuring Apache and Python.)

I have a rather common issue that is explained in more depth here http://code.google.com/p/modwsgi/wiki/IssuesWithExpatLibrary. Basically, I'm 99% sure that my main issue is that my Apache is using version 1.95.7 of the expat library, whereas my Python is using version 2.0.1 of the expat library; thus, when I use them together I get a segmentation fault.

As is explained in the link at the very bottom of the page, I need to replace/update the version of the expat library that is used by Apache to the version used by Python. How would I do this? (Keep in mind I'm very inexperienced with this sort of thing.)

EDIT: This issue has been resolved. Below I documented everything I did to install Apache, build Python from source code, install mod_wsgi, and resolve the dreaded expat issue for my reference and for that of anyone else who experiences a similar issue.

1) Installed Ubuntu with Wubi

Installing Apache

2) On Ubuntu, downloaded Apache Unix Source httpd-2.2.21.tar.gz

3) Extracted the source from the Apache HTTPDd tarbell:

gzip -d httpd-2.2.21.tar.gz
tar xvf httpd-2.2.21.tar

4) Configured the Apache HTTPd source tree from within extracted directory:

sudo ./configure --prefix=/usr/local/apache2

5) Built the various parts which form the Apache HTTPd package:

sudo make

6) Installed the package under the directory I specified in step 4

sudo make install

7) Started Apache HTTP Server:

sudo /usr/local/apache2/bin/apachectl -k start

8) Checked localhost and it printed "It works!"

9) Stopped Apache HTTP Server:

sudo /usr/local/apache2/bin/apachectl -k stop

Installing Python from source code

10) Fetched all the common packages needed to build anything (e.g. the compiler etc.)

sudo apt-get install build-essential

11) Edited sources.list file in /etc/apt by adding the exact same "deb" lines contained in the file to the end except with "deb-src":

sudo nano /etc/apt/sources.list

12) Updated apt-get to recognize the change:

sudo apt-get update

13) Fetched all the libraries needed to build Python:

sudo apt-get build-dep python2.7

14) Downloaded python source code Python-2.7.2.tgz, extracted it, and ran the following from within the directory:

sudo ./configure --enable-shared --prefix=/usr/local

15) Built Python:

sudo make

16) Installed Python:

sudo make install

Installing mod_wsgi

17) Downloaded mod_wsgi source code tar ball mod_wsgi-3.3.tar.gz

18) Unpacked and configured with python from within unpacked directory:

sudo ./configure --with-apxs=/usr/local/apache2/bin/apxs \
  --with-python=/usr/local/bin/python2.7

19) Built the configured package:

sudo make

20) Installed in Apache modules:

sudo make install

21) Downloaded Django-1.3.1.tar.gz

22) Extracted file:

tar xzvf Django-1.3.1.tar.gz

23) Installed Django project from within directory:

sudo python setup.py install

24) Edited Apache httpd.conf file:

sudo nano /usr/local/apache2/conf/httpd.conf

Added the following directive to the end of the file:

LoadModule wsgi_module /usr/local/apache2/modules/mod_wsgi.so
WSGIScriptAlias / /usr/local/lib/python2.7/site-packages/django/test.wsgi
<Directory /usr/local/lib/python2.7/site-packages/django>
Order deny,allow
Allow from all
</Directory>

25) Created a test file in django project directory:

sudo nano /usr/local/lib/python2.7/site-packages/django/test.wsgi

Added the following content to the file:

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'
    response_headers = [('Content-type', 'text/plain'),
    ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]

26) Started Apache:

sudo /usr/local/apache2/bin/apachectl -k start

27) Tested localhost and it printed "Hello World!"

28) Stopped Apache:

sudo /usr/local/apache2/bin/apachectl -k stop

Testing the Dreaded Expat Issue:

29) Edited test.wsgi file:

sudo nano /usr/local/lib/python2.7/site-packages/django/test.wsgi

Added the following content to the top of the file:

import pyexpat

30) Started Apache:

sudo /usr/local/apache2/bin/apachectl -k start

31) It prints "Hello World!" There is a God.

32) Stopped Apache:

$ sudo /usr/local/apache2/bin/apachectl -k stop
Squeteague answered 9/11, 2011 at 21:50 Comment(4)
What version of Python are you using? This is only meant to affect old Python versions unless your distro has screwed with how Python has been built and replaced Python's own expat or forced it to link against different expat.Duron
2.7.2+ Oh, really? I hope so. The reason I'm not so sure is that I tested importing pyexpat, and when I checked localhost, it should have printed "Hello World" but didn't. Then I checked my Apache error log and saw the expected segmentation fault error.Squeteague
The the distro has explicitly built Python in a way to use a external pyexpat implementation, so causing the problem. You may have to complain to the distro people. That or build Python yourself from source code, which will default to using internal expat implementation. Then need to rebuild mod_wsgi against that Python.Duron
Hey Graham, how would I build Python myself from source code? Sorry if it sounds like an obvious question. Also, are you positive I shouldn't just update the version of the expat library used by Apache (as the documentation seems to suggest)? In any case, I don't even know how I would update the version of the expat library used by Apache even if I needed to.Squeteague
R
1

Looking for this? It's pretty well known - I've followed this a couple of times myself.

Rhizocarpous answered 9/11, 2011 at 22:4 Comment(5)
No, that's exactly the same information in the link I posted. It's practically copied and pasted.Squeteague
I know that I need to replace/update the version of the expat library used by Apache. What I need to know is how I would actually go about doing that?Squeteague
The link is dead.Alexisaley
link is DEAD !!!Petersham
The Link is brokenSydel

© 2022 - 2024 — McMap. All rights reserved.