HOWTO: mod_python 2.7 (Apache 1.3.x) for FreeBSD 5.3

Algorithms

Verified User
Joined
Aug 31, 2005
Messages
6

This is currently deployed on our DA server.
This assumes you have the ports collection installed.
Comments, Suggestions, Improvements welcomed.


Green text is commands and output from the console
Orange-red text is for log and error information
Dark blue is for file contents

This is how I did it on FreeBSD 5.3-RELEASE

First we need a fresh build of Python without thread support. If you tried to install mod_python previously and got a message like this.

Cannot load /usr/lib/apache/mod_python.so into server:
/usr/lib/apache/mod_python.so: Undefined symbol "pthread_attr_init"

That means the Python you compiled mod_python against had threads enabled. To fix this, we need to edit our Python port and reinstall.

$ cd /usr/ports/lang/python
$ su
$ vi Makefile


Current Makefile:
OPTIONS= THREADS "Enable thread support" on \
HUGE_STACK_SIZE "Use a larger thread stack" off \
UCS4 "Use UCS4 for unicode support" on \
PYMALLOC "Use python's internal malloc" on \
IPV6 "Enable IPv6 support" on


Modified Makefile:
WITHOUT_THREADS= yes
OPTIONS= THREADS "Enable thread support" off \
HUGE_STACK_SIZE "Use a larger thread stack" off \
UCS4 "Use UCS4 for unicode support" on \
PYMALLOC "Use python's internal malloc" on \
IPV6 "Enable IPv6 support" on

Now save and exit from vi and build the port. If you have run make previously, you will need to issue a clean first.

$ make clean
$ make install
$ exit

Once Python is installed without threads, you can test by running the shell and attemping to import thread, you should get an error.

$ python
Python 2.3.4 (#2, Jan 18 2006, 16:38:08)
[GCC 3.4.2 [FreeBSD] 20040728] on freebsd5
Type "help", "copyright", "credits" or "license" for more information.
>>> import thread
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ImportError: No module named thread
>>>

Now we can install mod_python. Download and extract the mod_python 2.7 source.

$ cd ~/
$ wget "http://apache.bestwebcover.com/httpd/modpython/mod_python-2.7.11.tgz"
$ tar -zxvf mod_python-2.7.11.tgz
$ cd mod_python-2.7.11
$ ./configure --with-apxs=/usr/sbin/apxs \
--with-apache=/usr/local/directadmin/customapache/apache_1.3.33
$ make
$ su
$ make install

Now we have the mod_python module installed without threads and we are able to restart apache.

When restarting Apache, if you see the following message.

[warn] Loaded DSO modules/mod_python.so uses plain Apache 1.3 API
this module might crash under EAPI! (please recompile it with -DEAPI)

It just means you have mod_ssl enabled. This is a known and listed bug with mod_ssl. Downside is, you cannot use mod_python over a https (SSL) connection or it indeed, will crash.

$ /usr/local/etc/rc.d/httpd restart

Now we can log in to DA and setup the user we want to access mod_python. We do this with custom httpd settings. Login to DA as the admin, go to the custom http conf section. Select the domain and add the following line to the custom area.

<Directory /home/user/domains/xyz.com/public_html/python>
AllowOverride FileInfo
</Directory>

I am not sure if there is a global way to do this, my understanding of Allowoverride it is only allowed at the <Directory> level.

Now we can test that mod_python is working ok. To do this, create a .htaccess file in the directory you allowed the FileInfo override.

$ cd /home/user/domains/xyz.com/public_html/python
$ vi .htaccess


.htaccess contents
AddHandler python-program .py
PythonHandler datest
PythonDebug On


Now we create our test program, datest.py


$ vi datest.py


datest.py contents
from mod_python import apache

def handler(req):
req.send_http_header()
req.write("Hello World!")
return apache.OK


Now load up the test program in your brower and you should see "Hello World!". http://xyz.com/python/datest.py

That is it, done. This all worked for me without problems.
 
Last edited:
same problem with me previous install a month ago
# make
make[1]: Entering directory `/root/mod_python-2.7.11/src'
gcc -I/root/mod_python-2.7.11/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/os/unix -I/usr/local/include/python2.4 -c -o mod_python.o mod_python.c
In file included from /usr/local/include/python2.4/Python.h:8,
from /root/mod_python-2.7.11/src/include/mod_python.h:77,
from mod_python.c:54:
/usr/local/include/python2.4/pyconfig.h:835:1: warning: "_POSIX_C_SOURCE" redefined
In file included from /usr/include/sys/types.h:27,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/ap_config.h:45,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/httpd.h:29,
from /root/mod_python-2.7.11/src/include/mod_python.h:63,
from mod_python.c:54:
/usr/include/features.h:172:1: warning: this is the location of the previous definition
gcc -I/root/mod_python-2.7.11/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/os/unix -I/usr/local/include/python2.4 -c -o _apachemodule.o _apachemodule.c
In file included from /usr/local/include/python2.4/Python.h:8,
from /root/mod_python-2.7.11/src/include/mod_python.h:77,
from _apachemodule.c:51:
/usr/local/include/python2.4/pyconfig.h:835:1: warning: "_POSIX_C_SOURCE" redefined
In file included from /usr/include/sys/types.h:27,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/ap_config.h:45,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/httpd.h:29,
from /root/mod_python-2.7.11/src/include/mod_python.h:63,
from _apachemodule.c:51:
/usr/include/features.h:172:1: warning: this is the location of the previous definition
gcc -I/root/mod_python-2.7.11/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/os/unix -I/usr/local/include/python2.4 -c -o requestobject.o requestobject.c
In file included from /usr/local/include/python2.4/Python.h:8,
from /root/mod_python-2.7.11/src/include/mod_python.h:77,
from requestobject.c:51:
/usr/local/include/python2.4/pyconfig.h:835:1: warning: "_POSIX_C_SOURCE" redefined
In file included from /usr/include/sys/types.h:27,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/ap_config.h:45,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/httpd.h:29,
from /root/mod_python-2.7.11/src/include/mod_python.h:63,
from requestobject.c:51:
/usr/include/features.h:172:1: warning: this is the location of the previous definition
gcc -I/root/mod_python-2.7.11/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/os/unix -I/usr/local/include/python2.4 -c -o tableobject.o tableobject.c
In file included from /usr/local/include/python2.4/Python.h:8,
from /root/mod_python-2.7.11/src/include/mod_python.h:77,
from tableobject.c:51:
/usr/local/include/python2.4/pyconfig.h:835:1: warning: "_POSIX_C_SOURCE" redefined
In file included from /usr/include/sys/types.h:27,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/ap_config.h:45,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/httpd.h:29,
from /root/mod_python-2.7.11/src/include/mod_python.h:63,
from tableobject.c:51:
/usr/include/features.h:172:1: warning: this is the location of the previous definition
gcc -I/root/mod_python-2.7.11/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/os/unix -I/usr/local/include/python2.4 -c -o util.o util.c
In file included from /usr/local/include/python2.4/Python.h:8,
from /root/mod_python-2.7.11/src/include/mod_python.h:77,
from util.c:54:
/usr/local/include/python2.4/pyconfig.h:835:1: warning: "_POSIX_C_SOURCE" redefined
In file included from /usr/include/sys/types.h:27,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/ap_config.h:45,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/httpd.h:29,
from /root/mod_python-2.7.11/src/include/mod_python.h:63,
from util.c:54:
/usr/include/features.h:172:1: warning: this is the location of the previous definition
gcc -I/root/mod_python-2.7.11/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/os/unix -I/usr/local/include/python2.4 -c -o serverobject.o serverobject.c
In file included from /usr/local/include/python2.4/Python.h:8,
from /root/mod_python-2.7.11/src/include/mod_python.h:77,
from serverobject.c:51:
/usr/local/include/python2.4/pyconfig.h:835:1: warning: "_POSIX_C_SOURCE" redefined
In file included from /usr/include/sys/types.h:27,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/ap_config.h:45,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/httpd.h:29,
from /root/mod_python-2.7.11/src/include/mod_python.h:63,
from serverobject.c:51:
/usr/include/features.h:172:1: warning: this is the location of the previous definition
gcc -I/root/mod_python-2.7.11/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/os/unix -I/usr/local/include/python2.4 -c -o connobject.o connobject.c
In file included from /usr/local/include/python2.4/Python.h:8,
from /root/mod_python-2.7.11/src/include/mod_python.h:77,
from connobject.c:56:
/usr/local/include/python2.4/pyconfig.h:835:1: warning: "_POSIX_C_SOURCE" redefined
In file included from /usr/include/sys/types.h:27,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/ap_config.h:45,
from /usr/local/directadmin/customapache/apache_1.3.34/src/include/httpd.h:29,
from /root/mod_python-2.7.11/src/include/mod_python.h:63,
from connobject.c:56:
/usr/include/features.h:172:1: warning: this is the location of the previous definition

Compiling for DSO. For static, do "make static"

/usr/sbin/apxs -I/root/mod_python-2.7.11/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/include -I/usr/local/directadmin/customapache/apache_1.3.34/src/os/unix -I/usr/local/include/python2.4 -c mod_python.o _apachemodule.o requestobject.o tableobject.o util.o serverobject.o connobject.o -lm /usr/local/lib/python2.4/config/libpython2.4.a -lpthread -ldl -lutil -lm
gcc -shared -o mod_python.so mod_python.o _apachemodule.o requestobject.o tableobject.o util.o serverobject.o connobject.o -lm /usr/local/lib/python2.4/config/libpython2.4.a -lpthread -ldl -lutil -lm

Now su and make install
(or, if you only want to perform a partial install,
you can use make install_dso and make install_py_lib)

make[1]: Leaving directory `/root/mod_python-2.7.11/src'
however, it finished the make and make install successfully
but apache crash after restarting:(

here is the error log
[Thu Jan 19 16:49:12 2006] [notice] caught SIGTERM, shutting down
[Thu Jan 19 16:49:18 2006] [warn] Loaded DSO /usr/lib/apache/mod_python.so uses plain Apache 1.3 API, this module might crash under EAPI! (please recompile it with -DEAPI)
[Thu Jan 19 16:49:18 2006] [notice] FastCGI: process manager initialized (pid 26076)
[Thu Jan 19 16:49:19 2006] [notice] Apache configured -- resuming normal operations
[Thu Jan 19 16:49:19 2006] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Thu Jan 19 16:49:19 2006] [notice] Accept mutex: sysvsem (Default: sysvsem)
[Thu Jan 19 16:49:19 2006] [notice] child pid 26082 exit signal Segmentation fault (11)
[Thu Jan 19 16:49:19 2006] [notice] child pid 26083 exit signal Segmentation fault (11)
[Thu Jan 19 16:49:19 2006] [notice] child pid 26084 exit signal Segmentation fault (11)
[Thu Jan 19 16:49:19 2006] [notice] child pid 26085 exit signal Segmentation fault (11)
[Thu Jan 19 16:49:19 2006] [notice] child pid 26090 exit signal Segmentation fault (11)
.
.
.
 
Building mod_python 2.7.x against Python 2.4 has been known to cause problems and usually isn't recommended. I would install the 2.3 port of Python and compile mod_python 2.7.x against that installation.
 
Back
Top