1

I have a project that works very nicely using the dev web server but I'm running into tons of problems getting it to play nice on an old-ish centos box with the system apache (ie installed via yum.) I uninstalled the yum-based wsgi (because it was assuredly compiled against the system python 2.x) and am trying to use the one that got install via pip install mod-wsgi. (where pip is the python3 pip).

Before I get into the details, I want to just ask the internet -- is this even possible / advisable? Should I uninstall apache and try to build a new version from source? Should I be using a virtual-env? Pyenv or Virtualenv? If so, should mod-wsgi be installed in the project's venv or in "system" location of python3 (/usr/local/).

Seems like other poor souls have cried out silently in the dark about the same mix (old centos box, shiny new python version.)

I've read extensively through many online docs, like How to deploy with WSGI and Deploying Django (Django Book), but no one seems to address this particular combination.

I wish IT would let me use a Debian based system, seems like that would be easier.

Here is my apache version info:

apachectl -V
Server version: Apache/2.2.15 (Unix)
Server built:   Aug 18 2015 02:00:22
Server's Module Magic Number: 20051115:25
Server loaded:  APR 1.3.9, APR-Util 1.3.9
Compiled using: APR 1.3.9, APR-Util 1.3.9
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_SYSVSEM_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

Here's a few snips of my httpd.conf file:

LoadModule wsgi_module /opt/deeplogic-django/venv/lib/python3.4/site-packages/mod_wsgi/server/mod_wsgi-py34.cpython-34m.so
# lines omitted....
WSGIScriptAlias / /opt/myproject/myapp/wsgi.py
WSGIPythonPath /opt/myproject:/opt/myproject/venv/lib/python3.4/site-packages                           
WSGIPythonHome /opt/myproject/venv/bin
<Directory /opt/myproject/myapp>
<Files wsgi.py>
       Order deny,allow
       Allow from all
</Files>
</Directory>

And here is the latest error I am encountering when I try to start apache:

Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
[Thu Sep 17 11:51:47 2015] [notice] child pid 1393 exit signal Aborted (6)

Grateful for any pointers, advice, wisdom.

Community
  • 1
  • 1
Owen
  • 3,063
  • 5
  • 30
  • 26

3 Answers3

3

I've had success with Centos 6.5 with Apache and Python 3.x (it's because its at work). Here's the set up I am using (I stick with Python 3.3.x and Python 3.4 had issues with pyodbc).

First, install EPEL...

yum -y -q install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

Then Apache...

yum -y -q install httpd mod_ssl httpd-devel

Then for Python (including some very commonly used pre-reqs):

yum -y -q groupinstall development
yum -y -q install zlib2-devel openssl-devel sqlite-devel bzip2-devel python-devel openssl-devel openssl-perl libjpeg-turbo libjpeg-turbo-devel zlib-devel giflib ncurses-devel gdbm-devel xz-devel tkinter readline-devel tk tk-devel kernel-headers glibc libpng gcc-c++

Install Python 3.3.5 (you can probably use a more current version):

wget 'http://www.python.org/ftp/python/3.3.5/Python-3.3.5.tgz'
tar -xzf 'Python-3.3.5.tgz'
cd ./Python-3.3.5
CXX=g++ ./configure --enable-shared --quiet
make
make altinstall
ln -s /usr/local/bin/python3.3 /usr/bin/python3.3
echo "/usr/local/lib/python3.3" > /etc/ld.so.conf.d/python33.conf
echo "/usr/local/lib" >> /etc/ld.so.conf.d/python33.conf

Make and compile mod_wsgi (again, you can probably use a more current version, or look into MOD WSGI Express!):

wget "https://github.com/GrahamDumpleton/mod_wsgi/archive/4.2.8.tar.gz"
tar -xzf '4.2.8.tar.gz'
cd ./mod_wsgi-4.2.8
./configure --with-python=/usr/local/bin/python3.3
make
make install

Very obtuse compared to Ubuntu, but there you have it. YMMV, good luck!

FlipperPA
  • 13,607
  • 4
  • 39
  • 71
  • I accept this answer because it provides the high level strategy I was looking for (i.e. just compile mod_wsgi from source, don't bother with python packages by the same name.) Also the `--with-python` option is critical and saved me time. Thanks! – Owen Sep 22 '15 at 17:00
0

I found a very similar post here (Apache 2.2.15 on CentOS 6.5). I don't mark it as duplicate because I'm not sure if the problem/solution is the same.

Take care.

Community
  • 1
  • 1
dadiaar
  • 418
  • 5
  • 13
0

I myself tried the same few weeks ago, my vps had centos 6.7 and apache 2.2 and my project was developed using python 2.7 and django 1.8.3 I used to get an error which used to imply that whatever version of python I install inside virtual the mod_wsgi was using default python i.e python 2.6 to compile it and in the python docs its clearly mentioned that for django 1.8 you need python 2.7 or above.

So whatever you are doing is not advisable!

Anuj
  • 994
  • 11
  • 21