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: