0

Problem: There is a similar question on Stack Overflow: "Can I deploy both Python 2 and 3 Django app with Apache using mod_wsgi?" From the answer there I know that it is possible two have multiple Django projects (written in Python 2 and 3) on one Apache server. However, I can't manage to make this work.

What I have so far:

  1. I'm using Linux (Debian/Ubuntu).
  2. Three Django projects are stored in three separate Python Virtual Environments (i.e. py3venv1, py3venv2, py2venv1):

    /var/www/
    
    .........py3venv1/                             <-- Python 3 venv
    ..................bin/
    ..................include/
    ..................lib/
    ..................project1/                    <-- Python 3 Django Project
    ........................../manage.py
    ........................../project1/wsgi.py
    ........................../myapp
    
    .........py3venv2/                             <-- Python 3 venv
    ..................bin/
    ..................include/
    ..................lib/
    ..................project2/                    <-- Python 3 Django Project
    ........................../manage.py
    ........................../project2/wsgi.py
    ........................../myapp
    
    .........py2venv1/                             <-- Python 2 venv
    ..................bin/
    ..................include/
    ..................lib/
    ..................project3/                    <-- Python 2 Django Project
    ........................../manage.py
    ........................../project3/wsgi.py
    ........................../myapp
    
  3. I installed mod_wsgi for Python3 (pip3 install mod_wsgi)

  4. Apache configuration: /etc/apache2/sites-available/000-default.conf for Projects 1 and 2 (Python3 only), Project 3 (Python 2) is not configured:

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        # Project 1 (Python3)
        WSGIScriptAlias /project1 /var/www/py3venv1/project1/project1/wsgi.py process-group=group1
        WSGIDaemonProcess group1 python-home=/var/www/py3venv1/lib/python3.5 python-path=/var/www/py3venv1/project1
        WSGIProcessGroup group1
        Alias /project1/static /var/www/py3env1/project1/assets
        <Directory /var/www/py3venv1/project1/project1>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>
    
        # Project 2 (Python3)
        WSGIScriptAlias /project2 /var/www/py3venv2/project2/project2/wsgi.py process-group=group2
        WSGIDaemonProcess group2 python-home=/var/www/py3venv2/lib/python3.5 python-path=/var/www/py3venv2/project2
        WSGIProcessGroup group2
        Alias /project2/static /var/www/py3env2/project2/assets
        <Directory /var/www/py3venv2/project2/project2>
            <Files wsgi.py>
                Require all granted
            </Files>
        </Directory>
    
    </VirtualHost>
    

Outcome: Both Python 3 projects work fine. Python 2 project does not work.

Question: How can I make all three Django projects work on Apache?

0

1 Answer 1

1

The other question you link clearly says you can't have both Python 2 and 3 applications in the same Apache server instance. How do you read it as saying you can?

If you want different Python versions, you need to use mod_wsgi-express mentioned in that other post and run it as separate instance and have front end Apache proxy requests for specific site through to the other instance.

Have you looked at mod-wsgi-express at all and tried to get it installed and running?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.