Apache22 + mod_wsgi + Python 3.2 (help me configure it)

Hello everyone.
I want to set up a local web-server: Apache 22 + mod_wsgi + Python 3.2

I install:
www/apache22
lang/python32
www/mod_wsgi

Add in /etc/rc.conf:
Code:
apache22_enable="YES"
apache22_http_accept_enable="YES"

Add in /boot/loader.conf:
Code:
accf_http_load="YES"

Code:
# kldload accf_http
# rehash

And configure it:
1. In /usr/local/etc/apache22/httpd.conf
1.1. I comment on:
Code:
...
# LoadModule unique_id_module libexec/apache22/mod_unique_id.so
...
1.2. Check availability:
Code:
...
LoadModule wsgi_module libexec/apache22/mod_wsgi.so
...
1.3. Load my config (add in end file):
Code:
...
NameVirtualHost 127.0.0.1:80
Include /usr/local/www/siboo/siboo.conf

2. I create all project:
Code:
# mkdir -p /usr/local/www/siboo/
# cd /usr/local/www/siboo/
# cat siboo.conf
<VirtualHost siboo:80>
    ServerName siboo
    DocumentRoot "/usr/local/www/siboo"
    DirectoryIndex index.html index.htm
    WSGIScriptAlias / /usr/local/www/siboo/application.wsgi
	
    <Directory /usr/local/www/siboo>
        Options All
        Options MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>	
	
    ErrorLog /usr/local/www/siboo/error.log
    CustomLog /usr/local/www/siboo/access.log common
</VirtualHost>

And
Code:
# cat application.wsgi
import sys

def app(environ, start_response):
    " ... "
    message = "You use Python %s version." % sys.version[:3]
    start_response("200 OK", [("Content-Type", "text/html")])
    return [message]

application = app
3. Write in /etc/hosts
Code:
...
127.0.0.1    siboo siboo.my.domain

4. Restart web-server:
Code:
# /usr/local/etc/rc.d/apache22 restart
# w3m siboo
Result:


================================================================================================
You use Python 2.7 version.
================================================================================================


I guess that is installed incorrectly mod_wsgi.
I remove mod_wsgi. And write in /etc/make.conf
Code:
...
PYTHON_VERSION=3.2.1
PYTHON_DEFAULT_VERSION=3.2.1
or
Code:
...
#PYTHON_VERSION=3.2.1
PYTHON_DEFAULT_VERSION=3.2
and or
Code:
...
#PYTHON_VERSION=3.2.1
PYTHON_DEFAULT_VERSION=python3.2
I found the exact version running Python:
Code:
# python3.2
Python 3.2.1 (defult, Sep 2 2011, 18:43:12)
...

Code:
# rehash
And install www/mod_wsgi again.
But I have many ERROR!
 
Yes..
A little reading, I realized that I needed to mod_wsgi 3
It's here: www/mod_wsgi3
I remove the old mod_wsgi.

Code:
# cd /usr/ports/www/mod_wsgi3
# make && make install clean

===>  Building for ap22-mod_wsgi-3.3_2
/usr/local/sbin/apxs -c -I/usr/local/include/python3.2mu -DNDEBUG -D__wchar_t=wchar_t -
DTHREAD_STACK_SIZE=0x20000 -D__wchar_t=wchar_t -DTHREAD_STACK_SIZE=0x20000 -Wc,-O2 -Wc,-pipe -Wc,-fno-
strict-aliasing mod_wsgi.c -L/usr/local/lib -L/usr/local/lib/python3.2/config -lpython3.2 -lutil -lm

/usr/local/share/apr/build-1/libtool --silent --mode=compile cc -prefer-pic -O2 -pipe -I/usr/include -
fno-strict-aliasing   -g -I/usr/local/include -I/usr/local/include/apache22  -I/usr/local/include/
apr-1   -I/usr/local/include/apr-1 -I/usr/local/include -I/usr/local/include/db42 -O2 -pipe -fno-strict-
aliasing -I/usr/local/include/python3.2mu -DNDEBUG -D__wchar_t=wchar_t -DTHREAD_STACK_SIZE=0x20000 -
D__wchar_t=wchar_t -DTHREAD_STACK_SIZE=0x20000  -c -o mod_wsgi.lo mod_wsgi.c && touch mod_wsgi.slo

mod_wsgi.c: In function 'Adapter_environ':
mod_wsgi.c:3601: warning: assignment makes pointer from integer without a cast
mod_wsgi.c: In function 'Dispatch_environ':
mod_wsgi.c:8372: warning: assignment makes pointer from integer without a cast
mod_wsgi.c: In function 'Auth_environ':
mod_wsgi.c:13375: warning: assignment makes pointer from integer without a cast
/usr/local/share/apr/build-1/libtool --silent --mode=link cc -o mod_wsgi.la  -rpath /usr/local/libexec/
apache22 -module -avoid-version    mod_wsgi.lo -L/usr/local/lib -L/usr/local/lib/python3.2/config 
-lpython3.2 -lutil -lm
/usr/bin/ld: cannot find -lpython3.2
apxs:Error: Command failed with rc=65536
.
*** Error code 1
*** Error code 1

Stop in /usr/ports/www/mod_wsgi3.

What is -lpython3.2?
Where and how can I get it?
 
Thank you ericmacmini.
I read this forum now.
But the author compiles mod_wsgi3.
I do that I will try to install it from ports.
In extreme cases I resort to the compilation.
Thank you.
 
I installed python3.2 and the location /usr/local/lib/python3.2/config is linked to the object file -> /usr/local/lib/libpython3.2mu.so. Maybe you could try to link /usr/local/lib/python3.2/config
-lpython3.2
to the same object file.

Good luck.
 
Okay. I reinstalled FreeBSD 8.2 from scratch.
On a clean FreeBSD 8.2, I updated the ports collection.
I install:
www/apache22
lang/python32
www/mod_wsgi3

in the same manner.
mod_wsgi3 - established without problems.


Maybe I'm not truly deleted mod_wsgi in past cases. I did it then as follows:
Code:
# cd /usr/ports/www/mod_wsgi
# make && make deinstall clean


But this time everything was installed.
Made the setting as described in first post.
But not edit the file /etc/make.conf

Run:
Code:
# /usr/local/etc/rc.d/apache22 restart
# w3m siboo
Result:
================================================================================================
You use Python 2.7 version.
================================================================================================
again .... :(

Now try to change settings /etc/make.conf
 
Ok, I rewrite /etc/make.conf many time, use combination:
PYTHON_VERSION=3.2.1 or PYTHON_VERSION=3.2 or PYTHON_VERSION=python3.2.1 or PYTHON_DEFAULT_VERSION=3.2.1 or PYTHON_DEFAULT_VERSION=3.2 or PYTHON_DEFAULT_VERSION=python3.2

After each last combination I use:
Code:
# rehash
# /usr/local/etc/rc.d/apache22 restart
# w3m siboo

And again, again, again, again, again I see You use Python 2.7 version.

I also constantly edited application.wsgi - to be sure that this endorsement does not in the buffer.

How to Make python3.2 the default Apache22?
 
Try following:

Code:
# cd /usr/ports/www/mod_wsgi3/work/mod_wsgi-3.3
# sudo ee Makefile

Change the line LDLIBS = -lpython3.2 -lutil -lm in LDLIBS = -lpython3.2mu -lutil -lm
and reinstall the mod_wsgi3 port.

If not tested this with apache, but I was able to compile the object file.
 
After I rewrite /etc/make.conf (I added)
Code:
...
PYTHON_DEFAULT_VERSION=python3.2

I try reinstall mod_wsgi3
Code:
# cd /usr/ports/www/mod_wsgi3
# make && make reinstall clean
Oh, Error again:
Code:
...
mod_wsgi.c: In function 'Auth_environ':
mod_wsgi.c:13375: warning: assignment makes pointer from integer without a cast
/usr/local/share/apr/build-1/libtool --silent --mode=link cc -o mod_wsgi.la  -rpath /usr/local/libexec/
apache22 -module -avoid-version    mod_wsgi.lo -L/usr/local/lib -L/usr/local/lib/python3.2/config 
-lpython3.2 -lutil -lm
/usr/bin/ld: cannot find -lpython3.2
apxs:Error: Command failed with rc=65536
.
*** Error code 1
*** Error code 1

Stop in /usr/ports/www/mod_wsgi3.
I rewrite /etc/make.conf again, and comment last line:
Code:
# PYTHON_DEFAULT_VERSION=python3.2

Again:
Code:
# cd /usr/ports/www/mod_wsgi3
# make && make reinstall clean

Oh.. Error. Error again.

I use console, and: dvtm, vim-lite, w3m tools.
First I install this tools, after I install Apache22 Python32 and mod_wsgi3,
But system already have a python27.

Now I reinstall my FreeBSD, and first I Install Apache22 Python32 and mod_wsgi3.
After, - other tools.
 
Ok, thank you ericmacmini.
I'll take your advice after the installation of the system. (about 1 hour).

Are You using Python3 on your Web-server?
Are You using Apache + mod_wsgi? or nginx + uWSGI (mod_wsgi)? or Other?

I recently switched from Windows XP to UNIX systems (FreeBSD) so Sorry for stupid questions.
 
After reinstalling the system (with a new order) - the same result.
Sorry, but I do not have /usr/ports/www/mod_wsgi3/work/mod_wsgi-3.3 this folder.
I have:
Code:
/usr/ports/www/mod_wsgi3/
                       |__ Makefile
                       |__ disrinfo
                       |__ files/
                       |        |__ pkg-message.in
                       |__ pkg-descr
                       |__ pkg_plist
                       |__ ..
                       |__ .

And all.
I must create this file yourself?

How critical is when I resort to compile?
If I do not use ports and download sources and compile them mod_wsgi3.
I need to put what the compiler? (probably gcc).
 
At least tell me how to correctly compile mod_wsgi3.
I install bin/wget

Code:
# wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
# tar -xwzf mod_wsgi-3.3.tar.gz
# cd mod_wsgi-3.3
I read README and:
Code:
# ./configure

Now created Makefile.
Code:
# vim Makefile
and rewrite python2.7 on python3.2 (or python3.2mu in LDLIBS =)
Save it, and

Code:
# make install
But It do not installed.
 
Be sure to update the port collection found, excellent documentation can be found on both website and forum.
I use:
Code:
# sudo /usr/sbin/portsnap fetch update
# sudo /usr/sbin/pkg_version -IvL '='
Now, you can use the portupgrade nameofyourport command to upgrade installed ports, if necessary.

Code:
# cd /usr/ports/www/mod_wsgi3
# make fetch

make fetch will retrieve the latest files, but be sure to run portsnap first. After editing the Makefile you can compile the port with the make command.
 
O, I understand.

First
Code:
# sudo /usr/sbin/portsnap fetch update
# sudo /usr/sbin/pkg_version -IvL '='

I go to
Code:
# cd /usr/ports/www/mod_wsgi3
# make
And now create work folder.
(Before I run: make && make install clean , and after install mod_wsgi - "work" directory was deleted).

Ok, now I go to
Code:
# cd /usr/ports/www/mod_wsgi3/work/mod_wsgi-3.3
# vim Makefile
rewrite:
Code:
...
PYTHON = /usr/local/bin/python3.2
...
CPPFLAGS = -I/usr/local/include/python3.2mu -D__wchar_t= ....
...
 LDLIBS = -lpython3.2mu -lutil -lm
...

Save it, and
Code:
# cd ../../
# pwd
pwd: /usr/ports/www/mod_wsgi3
# make install
- Ok, install ok.. no problem..

Code:
# rehash
# /usr/local/etc/rc.d/apache22 restart
# w3m siboo

Python 2.7, again... - why?
 
Don't modify the application source, but the port.
/usr/ports/www/mod_wsgi3/Makefile
Code:
USE_PYTHON=     3.2+

The port should handle substituting the appropriate links and flags when building.

Okay, you may have to modify the application source also. Before you try to install this, make sure python-3.2 is installed. Might be necessary to remove other versions, if nothing depends on them and prevents their removal.

Don't be surprised if it fails, but also be cautious if it seems to work. There could be subtle problems that take a while to be visible.
 
Hi,
Originally Posted by wblock.
Don't modify the application source, but the port.
/usr/ports/www/mod_wsgi3/Makefile
Code:
USE_PYTHON=     3.2+

Ok,
Code:
# cd /usr/ports/www/mod_wsgi3
# make deinstall
... Ok
# rm -Rf work
# vim Makefile
- And edit USE_PYTHON= 3.2+
Code:
# make 
...
mod_wsgi.c: In function 'Auth_environ':
mod_wsgi.c:13375: warning: assignment makes pointer from integer without a cast
/usr/local/share/apr/build-1/libtool --silent --mode=link cc -o mod_wsgi.la  -rpath /usr/local/libexec/
apache22 -module -avoid-version    mod_wsgi.lo -L/usr/local/lib -L/usr/local/lib/python3.2/config 
-lpython3.2 -lutil -lm
/usr/bin/ld: cannot find -lpython3.2
apxs:Error: Command failed with rc=65536
.
*** Error code 1
*** Error code 1

Stop in /usr/ports/www/mod_wsgi3.

Bad,
Code:
# rm -Rf work
# vim Makefile
- And edit USE_PYTHON= 2.5+
Code:
# make 
.... Ok.
Can not install mod_wsgi use this flag USE_PYTHON= 3.2.

Originally Posted by wblock.
Okay, you may have to modify the application source also. Before you try to install this, make sure python-3.2 is installed. Might be necessary to remove other versions, if nothing depends on them and prevents their removal.
Python 3.2 installed!
Code:
# python3.2
Python 3.2.1 (default, Sep 3 2011, 15:48:44)
...
>>> print('Hello World.')
Hello World.
>>>

All that I use:
sysutils/dvtm
editors/vim-lite
japanese/w3m

And for web-server:
www/apache22
lang/python32
www/mod_wsgi3

I do not use GUI and many software.
When was the vim-lite was installed according to python2.7.
I could not remove python2.7.

Originally Posted by wblock.
Don't be surprised if it fails, but also be cautious if it seems to work. There could be subtle problems that take a while to be visible.

Thank you.
I know that python3.x not yet stable. But I've used in Windows XP (Apache2 + mod_wsgi + Python 3.1 in Windows Xp six months ago).
Also, I do not worry if this does not happen.
I can always try FastCGI or nginx + uWSGI or others

Originally Posted by ericmacmini.
I forgot to ask, but are you sure that apache loads the right module?

Yes, of course. All modules are compiled here:
Code:
/usr/local/libexec/apache22/mod_wsgi.so
/usr/local/libexec/apache22/mod_wsgi.la
/usr/local/libexec/apache22/mod_wsgi.a

I load:
Code:
...
LoadModule wsgi_module libexec/apache22/mod_wsgi.so
...
I always check that should have been loaded the correct module.

Code:
Originally Posted by [B]ericmacmini[/B].
You you give this piece of code from the conf file?
I do not quite understand what was going on.
I have difficulties with the translation.
Sorry me.
 
The solution is.
Not that I wanted but I satisfactory by 90%.

Code:
# cd /usr/ports/lang/python31
# make && make install clean
#
# mkdir -p ~/temp && cd ~/temp
# wget http://modwsgi.googlecode.com/files/mod_wsgi-3.3.tar.gz
# tar -xf mod_wsgi-3.3.tar.gz
# cd mod_wsgi-3.3
#
# ./configure --with-python=python3.1 --disable-framework
# make install

Add in /usr/local/etc/apache22/httpd.conf
Code:
LoadModule wsgi_module libexec/apache22/mod_wsgi.so

Code:
# rehash
# /usr/local/etc/rc.d/apache22 restart
# w3m siboo
# >> You use Python 3.1 version.

You use Python 3.1 version. - Okay.


But this method of installation I was not happy. I remove all wsgi.

Code:
# cd /usr/ports/www/mod_wsgi3
# rm -Rf work
# vim Makefile
And rewrite USE_PYTHON= 2.5+ on USE_PYTHON= 3.1 (do not USE_PYTHON= 3.1+ - otherwise it will attempt to install python3.2 and again will not be found -lpython3.2)
Save it.
Code:
# make
...Ok
# make install
#
# rehash
# /usr/local/etc/rc.d/apache22 restart
# w3m siboo
# >> You use Python 3.1 version.

Now I am satisfied by 93%.
I think that the problem in the old mod_wsgi3, which still maintains python3.1 but does not support python3.2.
So what does all this for the library -lpython3.2?

The theme can be put on pause.
Who knows how to put python3.2 - write, will be happy.

Thank you so much user ericmacmini and user wblock that have not thrown in a difficult moment.
 
I don't use python3 (I'm with python 2.7). I don't have problem with ports building, bug I can give you my apache configuration :
in a virtualhost config :
Code:
WSGIDaemonProcess myuser user=myuser group=users threads=25 processes=1
WSGIProcessGroup myuser
WSGIScriptAlias / /u/user/sites/www/wsgi_handler.py

It's a fastcgi process and works with a django framework website.
 
Originally Posted by nORKy.
I don't use python3 (I'm with python 2.7). I don't have problem with ports building, bug I can give you my apache configuration :
in a virtualhost config :

In fact, there are no problems installing Py-2.7 + mod_wsgi.
And there are no problems installing Py-3.1 + mod_wsgi3.
The main problem installing Py-3.2 + mod_wsgi3. Exactly in Python 3.2 Director / usr/local/lib/python3.2/config - "not standard".
At this time in Python 2.7 and 3.1 all good.

I tried to edit / usr/local/lib/python3.2/config.
To do this, I read an article (on the recommendation of user ericmacmini) http://ubuntuforums.org/showthread.php?t=1702377.
I did everything as they have written. Everything turned out .. but as the author and I could not run mod_wsgi.so

The problem is not in the proper setting my.conf. The problem is that I can not bind (establish) mod_wsgi3 + Python 3.2.
But thanks, that took part in the discussion.
 
Hi, ya.

For anyone else who stumbles across this page, in hopes of using mod_wsgi3 with Python 3.x.

If you check out this StackOverflow link, then you'll see that, supposedly, you just need to edit -lpython3.3 to -lpython3.3m in the Makefile.

If you check out the Google Group, it looks like this might be a bug.

Anyway, I haven't actually tried this because I'm not sure how to edit that line in the Makefile :(

Here's what I did.

cd /usr/ports/www/mod_wsgi3
vi Makefile

Then I changed --with-python="${PYTHON_CMD}" to --with-python="/usr/local/bin/python3.3". However, this still causes the error mentioned above. I'm guessing I have to modify mod_wsgi3/work/mod_wsgi-3.4/Makefile, but I'm not sure what to do next. I tried a make install in that folder and stuff happened. No errors. But, when I checked pkg info | grep mod, I didn't see mod_wsgi, which makes me think I didn't install it.

Does anyone with a better understanding of unix/FreeBSD know how to continue installing mod_wsgi? Did make install install it on my system? Why wasn't it at pkg info?
 
Okay, here's how I got it to work after all.

Code:
cd /usr/ports/www/mod_wsgi3
vi Makefile
Change --with-python="${PYTHON_CMD}" to --with-python="/usr/local/bin/python3.3".

cd work/mod_wsgi3.4
vi Makefile
Change -lpython3.3 to -lpython3.3m
make install clean

cd /usr/ports/www/mod_wsgi3
make install clean

This registered it with pkg and installed it just like any other port.
 
I thought I would reinvigorate this thread because I am trying to do something largely similar using www/apache24 and www/mod_wsgi 4-4.4.22.

In summary I would like to use the python web user interface for the document indexer deskutils/recoll. I have taken the below described steps to install the appropriate software and have tried to configure the server based on the following documents:

Apache HTTP Server FreeBSD - https://www.freebsd.org/doc/handbook/network-apache.html

How to install and configure www/mod_wsgi on FreeBSD 8.2 - http://blog.richardknop.com/2012/01/how-to-install-and-configure-mod_wsgi-on-freebsd-8-2/

deskutils/recoll WebUI installation from scratch on a Debian/Ubuntu system - http://www.lesbonscomptes.com/recoll/pages/recoll-webui-install-wsgi.html

Code:
#pkg install apache24 ap24-mod_wsgi4

The following 3 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
   apache24: 2.4.18
   ap24-mod_wsgi4: 4.4.22
   apr: 1.5.2.1.5.4

cd to /usr/local/etc/apache24/ and wget the web module as a zip file
#wget https://github.com/medoc92/recoll-webui/archive/master.zip

Extract the web module
#unzip master.zip

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Navigate to the Apache httpd configuration file
ee /usr/local/etc/apache24/httpd.conf

And then modify the server ip/name
# If your host doesn't have a registered DNS name, enter its IP address
here.
#
ServerName 172.0.0.0:80

After that, remove or comment out ServerRoot, DocumentRoot and their corresponding Directory Apache directives and add this line on the bottom of the the /usr/local/etc/apache22/httpd.conf file:
Include /usr/local/www/apache24/recoll-webui-master/httpd.conf

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Now navigate to edit httpd.conf

ee /usr/local/www/apache24/recoll-webui-master/httpd.conf

By adding the following:

WSGIDaemonProcess recoll user=501 group=20 \
  threads=1 processes=5 display-name=%{GROUP} \
  python-path=/usr/local/www/apache24/recoll-webui-master
WSGIScriptAlias /recoll /usr/local/www/apache24/recoll-webui-master/WebUI-wsgi.py
<Directory /usr/local/www/apache24/recoll-webui-master>
  WSGIProcessGroup recoll
  Order allow,deny
  allow from all
</Directory>


Then start the server process
#service apache24 start

After starting the server process I don't get a response from the address that was configured. I don't have much experience with www/apache24 and I realize that the documentation that I've provided/read spans two versions of www/apache24 and some possible FreeBSD configuration differences with the provided information in the Ubuntu guide.

I'd like to ask for help in configuring this. It seems as though it is not difficult, but I am definitely missing something. I just want this to work, I can deal with the security and fine tuning later. Help would be very appreciated!
 
Last edited by a moderator:
Hmm. I imagine there aren't many people using this in this particular way, but does anyone have any clues as to what might have gone wrong?
 
Back
Top