0
votes

So this is driving me crazy I have python3 and modwsgi and apache and a virtual host, that work great, as I have several other wsgi scripts that work fine on the server. I also have a django app that works great when I run the dev server.

I have checked that "ldd mod_wsgi.so" is linked correctly against python3.5

Whenever I try to access my site, I get an error and the apache log states: ImportError: No module named 'protectionprofiles' protection profiles is mysite name the following is my virtual host config

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName <my ip>
WSGIScriptAlias /certs /var/www/scripts/CavsCertSearch/CavsCertSearch/certstrip.wsgi
        WSGIScriptAlias /testcerts /var/www/scripts/CavsCertSearchTest/CavsCertSearch/certstriptest.wsgi
        WSGIScriptAlias /protectionprofiles /var/www/protectionprofiles/protectionprofiles/wsgi.py
        <Directory /var/www/protectionprofiles/protectionprofiles>
        <Files wsgi.py>
        Require all granted
        </Files>
        </Directory>
</VirtualHost>

my site app is the protection profiles alias. I have no idea what the issue is I have tried following dozens of different apache tutorials and none of them seem to work. Any help is greatly appreciated.

------ To add something else I tried -------- so I added the following 2 commands inside the virtual host

WSGIDaemonProcess protectionprofiles python-path=/var/www/protectionprofiles/
WSGIProcessGroup protectionprofiles

and no I get a different error

Error was: No module named 'django.db.backends.postgresql'

which is my backend, but the dev server works fine? Below is my database configuration

DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.postgresql',
            'USER': 'myuser',
            'PASSWORD': 'abcd1234',
            'HOST': '127.0.0.1',
            'PORT': '5432',
            'NAME': 'protectionprofile',
        }
    }

----Another error ---- Occasional I get

RuntimeError: populate() isn't reentrant

---- Another error!!--- Now when I update

WSGIDaemonProcess protectionprofiles python-path=/var/www/protectionprofiles/:/usr/lib/python3/dist-packages/django

I get

 ImportError: cannot import name 'SimpleCookie'

---Another wierd thng is that when I have

WSGIProcessGroup protectionprofiles

enabled I dont get the error that it can't find the module "protectionprofiles" but when then non of my other wsgi scripts work!. They only work when thats no in there. Any explanation of that would be very helpful

2
Where is Django installed? Is it really installed in your system Python installation, or are you using a virtual environment? What version of Python is mod_wsgi compiled for and what version are you wanting to use? modwsgi.readthedocs.io/en/develop/user-guides/… - Graham Dumpleton
django was installed with pip3 install django , I don't think I am using a virtual environment? everything was installed with apt or pip. Also all my wsgi scripts (the other two) that aren't django scripts work fine. Let me figure out the viersion of everything - noone392
The populate() error is a side effect of the error occurring on trying to load the WSGI application. So that can be ignored at this point. - Graham Dumpleton
Do you have Python package psycopg2 installed? - Graham Dumpleton
You should need to add any extra paths for packages installed into the Python installation. That you are suggests your mod_wsgi isn't actually compiled for the Python installation you want. Find the mod_wsgi.so module and run ldd on it to see what it is linked to modwsgi.readthedocs.io/en/develop/user-guides/… - Graham Dumpleton

2 Answers

1
votes

You probably need to tell mod_wsgi where your project code is. For embedded mode this is done with WSGIPythonPath directive. You should preferably though use daemon mode, in which case you would use python-path option to WSGIDaemonProcess directive.

0
votes

ok I finally figured out how to fix the issue but not sure exactly why. First off when I was mixing my own wsgi scipts and django I had to specify the daemon process only for the script alias that was django

WSGIScriptAlias /certs /var/www/scripts/CavsCertSearch/CavsCertSearch/certstrip.wsgi
    WSGIScriptAlias /testcerts /var/www/scripts/CavsCertSearchTest/CavsCertSearch/certstriptest.wsgi
    WSGIScriptAlias /debug /var/www/scripts/debug/debug.wsgi
    WSGIScriptAlias / /var/www/protectionprofiles/protectionprofiles/wsgi.py process-group=protectionprofiles
    WSGIDaemonProcess protectionprofiles python-path=/var/www/protectionprofiles/
WSGIProcessGroup protectionprofiles

Then in the app/settings.py in dev mode one backend worked but when ran in mod_wsgi I needed a different one: settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'databse',
        'USER': 'user',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}

In the development server "'django.db.backends.postgresql" worked fine but in release I had to specify the exact module type. I am not sure why but it works now!!