Deploy production django applications with Python2.7 and Python3.5 on same Apache web server

35 views
Skip to first unread message

BIJAL MANIAR

unread,
Aug 28, 2017, 7:20:56 AM8/28/17
to Django users

Hi,

I have existing setup of django app within virtual env (Python 2.7, Django 1.11), running on Apache2.2 on production environment.
On the same server, I want to setup one more django app within virtual env (Python 3.5, Django 1.11).
How can we have two django apps with two different versions of Python running on same Apache server?

Found an alternative mod_wsgi-express. Below is the link
Is it suitable for production environments and has a good community support? Does it have any limitation?

Please let me know if there are any other ways to achieve this.

Any help would be appreciated.

Thanks,
Bijal

Andréas Kühne

unread,
Aug 28, 2017, 7:26:41 AM8/28/17
to django...@googlegroups.com
Hi,

I found this information that could be handy for setting up with multiple environments and mod_wsgi. 


I don't think you really need to use a different setup, just some configuration in your httpd.conf file.

Otherwise you could also use uwsgi - which can handle that sort of thing easily.

Regards,

Andréas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fadfffe1-4597-4e56-9f45-2fe1dcd59c55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

BIJAL MANIAR

unread,
Aug 28, 2017, 8:06:02 AM8/28/17
to Django users

Hi Andreas,
Thanks for the reply. I'll go through link shared by you. Just wanted to confirm just by some configuration changes in httpd.conf, will same apache work for multiple python versions.

I came across below lines by Graham Dumpleton:
So the basic limitation here is that the one running Apache instance can only handle either Python 2 or Python 3 code. This is because the Python interpreter itself is embedded inside of the Apache processes through indirect dynamic linking of the Python interpreter shared library when the mod_wsgi module is loaded into Apache. How library linking works means that it isn’t possible to load two different versions of the same dynamic shared library into the one process at the same time. 

The only solution therefore is to have two separate instances of Apache running, one for Python 2 and one for Python 3 code. 

Thanks,
Bijal


On Monday, August 28, 2017 at 4:56:41 PM UTC+5:30, Andréas Kühne wrote:
Hi,

I found this information that could be handy for setting up with multiple environments and mod_wsgi. 


I don't think you really need to use a different setup, just some configuration in your httpd.conf file.

Otherwise you could also use uwsgi - which can handle that sort of thing easily.

Regards,

Andréas

2017-08-28 13:20 GMT+02:00 BIJAL MANIAR <bij...@gmail.com>:

Hi,

I have existing setup of django app within virtual env (Python 2.7, Django 1.11), running on Apache2.2 on production environment.
On the same server, I want to setup one more django app within virtual env (Python 3.5, Django 1.11).
How can we have two django apps with two different versions of Python running on same Apache server?

Found an alternative mod_wsgi-express. Below is the link
Is it suitable for production environments and has a good community support? Does it have any limitation?

Please let me know if there are any other ways to achieve this.

Any help would be appreciated.

Thanks,
Bijal

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Andréas Kühne

unread,
Aug 28, 2017, 8:26:49 AM8/28/17
to django...@googlegroups.com
Sorry I don't really know.... I use nginx and uwsgi for our production environement, but from what I read in the mod_wsgi documentation, it SHOULD be possible. 

However, if that is not the case, you will probably need to start 2 different apaches OR you could migrate to nginx / uwsgi - but that's probably harder.... 

Regards,

Andréas

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Antonis Christofides

unread,
Aug 28, 2017, 8:28:16 AM8/28/17
to django...@googlegroups.com

Hi,

In that case, you can go with another WSGI server, and as I've said before, I'd recommend Gunicorn. Here are some related articles (of mine):

Which WSGI server should I use?

How to setup Apache with Gunicorn

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

BIJAL MANIAR

unread,
Aug 29, 2017, 2:51:45 AM8/29/17
to Django users

I tried serving both Python2.7 and Python3.5 based django applications through same Apache and it did not work.
Getting below error:

Traceback (most recent call last):
  File "C:/virtualenvs/ecst_venv_D111P36A22M51\lib\site.py", line 67, in <module>
    import os
  File "C:/virtualenvs/ecst_venv_D111P36A22M51\lib\os.py", line 409
    yield from walk(new_path, topdown, onerror, followlinks)
             ^
SyntaxError: invalid syntax

Can anyone please confirm if there is an alternative to using different apache instances.

Thanks,
Bijal

James Schneider

unread,
Aug 29, 2017, 4:15:02 AM8/29/17
to django...@googlegroups.com


On Aug 28, 2017 11:51 PM, "BIJAL MANIAR" <bij...@gmail.com> wrote:

I tried serving both Python2.7 and Python3.5 based django applications through same Apache and it did not work.
Getting below error:

Traceback (most recent call last):
  File "C:/virtualenvs/ecst_venv_D111P36A22M51\lib\site.py", line 67, in <module>
    import os
  File "C:/virtualenvs/ecst_venv_D111P36A22M51\lib\os.py", line 409
    yield from walk(new_path, topdown, onerror, followlinks)
             ^
SyntaxError: invalid syntax

Can anyone please confirm if there is an alternative to using different apache instances.


It is impossible to do what you are asking due to the way mod_wsgi is loaded in to Apache. Only one version of Python may be referenced by an Apache instance at a time. 

Also, you cannot run multiple instances of Apache on the same server of they are using the same ports (default 80 and 443), and the server only has a single IP address. To run seperate instances, you'll either need a second server with its own IP, or you'll need to add a second IP to your existing server and bind each instance of Apache to a specific IP.

A possible third option is to place a proxy process (such as Nginx or even a third Apache instance) in front of both of your Apache instances on the same server (bound to different ports on the localhost adapter). Depending on the resource requested, that process would proxy the request to the local bindings of Apache for the appropriate Python version.

Two separate servers is the cleanest solution.

-James


Reply all
Reply to author
Forward
0 new messages