1

I wish to deploy multiple Django sites (say 2 for now - www.example.com, www.example2.com) using apache2 mod_wsgi. Here are the steps I followed in a fresh Ubuntu 16.04 installations.

I've set alias python=python3 in my .bashrc as I am working in python3

packages installed:

apache2 - sudo apt-get install apache2

mod_wsgi - sudo apt-get install libapache2-mod-wsgi-py3

Django(V1.11) - sudo apt-get install python3-django

Then I've created two projects inside

/var/www/

django-admin startproject example
django-admin startproject example2

then I did the followings for both the projects (I've mentioned only one, the other one is exactly the same except replacing example with example2)

/var/www/example/example/settings.py

ALLOWED_HOSTS = ['example.com', 'www.example.com']

/var/www/example/example/wsgi.py

#os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
os.environ["DJANGO_SETTINGS_MODULE"] = "example.settings"

/etc/apache2/sites-available/example.conf

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    ServerAdmin admin@example.com

    DocumentRoot /var/www/example
    WSGIScriptAlias / /var/www/example/example/wsgi.py

    ErrorLog /var/www/example/error.log
</VirtualHost>

Also, I've added

/etc/apache2/apache2.conf

WSGIPythonPath /var/www/example

I've called a2ensite for both example.conf and example2.conf

Once I restart apache I could now access www.example.com successfully, but www.example2.com gives an internal server error(500). I thought that's because I've only included one path for WSGIPythonPath in apache2.conf and changed it as

/etc/apache2/apache2.conf

WSGIPythonPath /var/www/example:/var/www/example2

But however, I now get an internal server error(500) for both.

in both cases, the error message is ImportError: No module named example

This is my first deployment by the way. Hense I have no prior experience.

Please direct me what I should do to get both sites up and running.

  • Use mod_wsgi daemon mode. You need to separate each Django instance into separate process groups or you will end up with various issues. Don't use ``WSGIPythonPath``. Learn how to specify ``python-path`` separately for each daemon process group. Using a Python virtual environment for each instance would also be a good idea so you can develop them separately. Some reading http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html http://blog.dscpl.com.au/2012/10/requests-running-in-wrong-django.html http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html – Graham Dumpleton Jul 20 '17 at 11:47
  • 1
    Also, just get one running first. You are just going to complicate things by trying to get both working at the same time when you haven't even got one working properly first. – Graham Dumpleton Jul 20 '17 at 11:48

0 Answers0