I have two sites, site-one is a django app and site-two is a wordpress site.
I have two .conf files inside /etc/apache2/sites-available:
site-one.com.conf
<VirtualHost *:80>
ServerAdmin adminmail#gmail.com
ServerName site-one.com
ServerAlias www.site-one.com
DocumentRoot /var/www/site-one.com/public_html
ErrorLog ${APACHE_LOG_DIR}/site-one.com.error.log
CustomLog ${APACHE_LOG_DIR}/site-one.com.access.log combined
Alias /static /var/www/site-one.com/public_html/static
<Directory /var/www/site-one.com/public_html/static>
Require all granted
</Directory>
<Directory /var/www/site-one.com/public_html/MyApp>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIScriptAlias / /var/www/site-one.com/public_html/MyApp/wsgi.py
WSGIDaemonProcess django_app python-path=/var/www/site-one.com/public_html
WSGIProcessGroup django_app
</VirtualHost>
site-two.com.conf
<VirtualHost *:80>
ServerAdmin adminmail#gmail.com
ServerName site-two.com
ServerAlias www.site-two.com
DocumentRoot /var/www/site-two.com/public_html
ErrorLog ${APACHE_LOG_DIR}/site-two.com.error.log
CustomLog ${APACHE_LOG_DIR}/site-two.com.access.log combined
</VirtualHost>
The site-one.com is 100% working but when I load site-two.com I get this error:
Internal Server Error The server encountered an internal error or
misconfiguration and was unable to complete your request.
The site-two.com.error.log shows this:
[Mon Nov 02 09:09:48.629460 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] mod_wsgi (pid=2396): Failed to exec Python script file '/var/www/site-one.com/public_html/MyApp/wsgi.py'.
[Mon Nov 02 09:09:48.631915 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] mod_wsgi (pid=2396): Exception occurred processing WSGI script '/var/www/site-one.com/public_html/MyApp/wsgi.py'.
[Mon Nov 02 09:09:48.632702 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] Traceback (most recent call last):
[Mon Nov 02 09:09:48.632776 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/var/www/site-one.com/public_html/MyApp/wsgi.py", line 16, in <module>
[Mon Nov 02 09:09:48.632784 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] application = get_wsgi_application()
[Mon Nov 02 09:09:48.632794 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/local/lib/python3.8/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Mon Nov 02 09:09:48.632799 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] django.setup(set_prefix=False)
[Mon Nov 02 09:09:48.632808 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/local/lib/python3.8/dist-packages/django/__init__.py", line 19, in setup
[Mon Nov 02 09:09:48.632813 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Nov 02 09:09:48.632822 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/local/lib/python3.8/dist-packages/django/conf/__init__.py", line 83, in __getattr__
[Mon Nov 02 09:09:48.632827 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] self._setup(name)
[Mon Nov 02 09:09:48.632835 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/local/lib/python3.8/dist-packages/django/conf/__init__.py", line 70, in _setup
[Mon Nov 02 09:09:48.632840 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] self._wrapped = Settings(settings_module)
[Mon Nov 02 09:09:48.632849 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/local/lib/python3.8/dist-packages/django/conf/__init__.py", line 177, in __init__
[Mon Nov 02 09:09:48.632854 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] mod = importlib.import_module(self.SETTINGS_MODULE)
[Mon Nov 02 09:09:48.632862 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
[Mon Nov 02 09:09:48.632867 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] return _bootstrap._gcd_import(name[level:], package, level)
[Mon Nov 02 09:09:48.632875 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[Mon Nov 02 09:09:48.632884 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[Mon Nov 02 09:09:48.632893 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
[Mon Nov 02 09:09:48.632902 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
[Mon Nov 02 09:09:48.632910 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[Mon Nov 02 09:09:48.632919 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[Mon Nov 02 09:09:48.632928 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
[Mon Nov 02 09:09:48.632948 2020] [wsgi:error] [pid 2396] [remote 151.49.10.216:63056] ModuleNotFoundError: No module named 'MyApp'
I am not an expert on apache config files so I can't understand why WSGI is called when I'm requesting site-two.
How can I solve this problem?
The site-one.com.eror.log file is empty by the way
Related
I am trying to host two Django websites on Windows (so no WSGIdaemonprocess). When I did host only one of them it worked perfectly. Now it still works (main path "/" named magazyn). But the second one (path "/awizacje" named awizacje) throws an Internal Server Error. Full error message in Apache logs looks like this:
C:\A\34\s\Modules\_decimal\libmpdec\context.c:57: warning: mpd_setminalloc: ignoring request to set MPD_MINALLOC a second time
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] mod_wsgi (pid=6268): Failed to exec Python script file 'C:/var/www2/awizacje/rootkat/awizacje/wsgi.py'.
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] mod_wsgi (pid=6268): Exception occurred processing WSGI script 'C:/var/www2/awizacje/rootkat/awizacje/wsgi.py'.
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] Traceback (most recent call last):\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:/var/www2/awizacje/rootkat/awizacje/wsgi.py", line 19, in <module>\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] application = get_wsgi_application()\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\core\\wsgi.py", line 12, in get_wsgi_application\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] django.setup(set_prefix=False)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\__init__.py", line 19, in setup\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\conf\\__init__.py", line 76, in __getattr__\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] self._setup(name)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\conf\\__init__.py", line 63, in _setup\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] self._wrapped = Settings(settings_module)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\var\\www\\magazyn\\env39\\Lib\\site-packages\\django\\conf\\__init__.py", line 142, in __init__\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] mod = importlib.import_module(self.SETTINGS_MODULE)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "C:\\Python39\\lib\\importlib\\__init__.py", line 127, in import_module\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] return _bootstrap._gcd_import(name[level:], package, level)\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 1030, in _gcd_import\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 1007, in _find_and_load\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 1030, in _gcd_import\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 1007, in _find_and_load\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked\r
[Mon Oct 11 14:57:35.251409 2021] [wsgi:error] [pid 6268:tid 992] [client 192.168.2.54:25532] ModuleNotFoundError: No module named 'awizacje'\r
My httpd.conf looks like this:
WSGIPythonHome "C:/var/www/magazyn/env39"
WSGIPythonPath "C:/var/www/magazyn/venv/Lib/site-packages;C:/var/www/magazyn/rootkat/"
ServerName www.magazyn-stolarz.pl
LoadFile "C:/Python39/python39.dll"
LoadModule wsgi_module "C:/var/www/magazyn/env39/lib/site-packages/mod_wsgi/server/mod_wsgi.cp39-win_amd64.pyd"
WSGIScriptAlias /awizacje "C:/var/www2/awizacje/rootkat/awizacje/wsgi.py"
WSGIScriptAlias / "C:/var/www/magazyn/rootkat/magazyn/wsgi.py"
<Directory "C:/var/www/magazyn/rootkat/magazyn/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static "C:/var/www/static/"
<Directory "C:/var/www/static/">
Require all granted
</Directory>
<Directory "C:/var/www2/awizacje/rootkat/awizacje/">
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /statica "C:/var/www2/static/"
<Directory "C:/var/www2/static/">
Require all granted
</Directory>
My wsgi.py settings in 'awizacje' project:
"""
WSGI config for magazyn project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
import sys
import site
from django.core.wsgi import get_wsgi_application
#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awizacje.settings')
os.environ["DJANGO_SETTINGS_MODULE"] = "awizacje.settings"
application = get_wsgi_application()
site.addsitedir('C:/var/www2/awizacje/venv/Lib/site-packages')
sys.path.append('C:/var/www2/awizacje')
sys.path.append('C:/var/www2/awizacje/rootkat')
What am I doing wrong? I sadly can't use Linux which would be pretty straightforward.
It looks like what I was missing was appending directories BEFORE get_wsgi_application() command in wsgi.py
"""
WSGI config for magazyn project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
import sys
import site
from django.core.wsgi import get_wsgi_application
#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'awizacje.settings')
os.environ["DJANGO_SETTINGS_MODULE"] = "awizacje.settings"
application = get_wsgi_application()
site.addsitedir('C:/var/www2/awizacje/venv/Lib/site-packages')
sys.path.append('C:/var/www2/awizacje')
sys.path.append('C:/var/www2/awizacje/rootkat')
I am trying to start my first django app with Apache2 (2.4.18).
Unfortunately, I got a bit stuck. This is the error code i get in my log file:
[Wed Mar 11 06:31:32.668937 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] mod_wsgi (pid=14849): Target WSGI script '/home/nigsdtm/srv/portal/mysite/wsgi.py' cannot be loaded as Python module.
[Wed Mar 11 06:31:32.669026 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] mod_wsgi (pid=14849): Exception occurred processing WSGI script '/home/nigsdtm/srv/portal/mysite/wsgi.py'.
[Wed Mar 11 06:31:32.669734 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] Traceback (most recent call last):
[Wed Mar 11 06:31:32.669779 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "/home/nigsdtm/srv/portal/mysite/wsgi.py", line 16, in <module>
[Wed Mar 11 06:31:32.669783 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] application = get_wsgi_application()
[Wed Mar 11 06:31:32.669789 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Wed Mar 11 06:31:32.669792 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] django.setup(set_prefix=False)
[Wed Mar 11 06:31:32.669809 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 24, in setup
[Wed Mar 11 06:31:32.669812 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] apps.populate(settings.INSTALLED_APPS)
[Wed Mar 11 06:31:32.669817 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 112, in populate
[Wed Mar 11 06:31:32.669820 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] app_config.import_models()
[Wed Mar 11 06:31:32.669824 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "/usr/local/lib/python3.5/dist-packages/django/apps/config.py", line 198, in import_models
[Wed Mar 11 06:31:32.669827 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] self.models_module = import_module(models_module_name)
[Wed Mar 11 06:31:32.669832 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Wed Mar 11 06:31:32.669834 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] return _bootstrap._gcd_import(name[level:], package, level)
[Wed Mar 11 06:31:32.669839 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Wed Mar 11 06:31:32.669843 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Wed Mar 11 06:31:32.669848 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
[Wed Mar 11 06:31:32.669852 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
[Wed Mar 11 06:31:32.669857 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "<frozen importlib._bootstrap_external>", line 665, in exec_module
[Wed Mar 11 06:31:32.669861 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Wed Mar 11 06:31:32.669866 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "/usr/local/lib/python3.5/dist-packages/polls/models.py", line 14, in <module>
[Wed Mar 11 06:31:32.669869 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] class Choice(models.Model):
[Wed Mar 11 06:31:32.669873 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] File "/usr/local/lib/python3.5/dist-packages/polls/models.py", line 15, in Choice
[Wed Mar 11 06:31:32.669886 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] question = models.ForeignKey(Question)
[Wed Mar 11 06:31:32.669900 2020] [wsgi:error] [pid 14849:tid 140433834096384] [remote 10.150.29.220:33874] TypeError: __init__() missing 1 required positional argument: 'on_delete'
[Wed Mar 11 06:31:47.868251 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] mod_wsgi (pid=15027): Target WSGI script '/home/nigsdtm/srv/portal/mysite/wsgi.py' cannot be loaded as Python module.
[Wed Mar 11 06:31:47.868326 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] mod_wsgi (pid=15027): Exception occurred processing WSGI script '/home/nigsdtm/srv/portal/mysite/wsgi.py'.
[Wed Mar 11 06:31:47.869029 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] Traceback (most recent call last):
[Wed Mar 11 06:31:47.869078 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "/home/nigsdtm/srv/portal/mysite/wsgi.py", line 16, in <module>
[Wed Mar 11 06:31:47.869082 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] application = get_wsgi_application()
[Wed Mar 11 06:31:47.869087 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Wed Mar 11 06:31:47.869090 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] django.setup(set_prefix=False)
[Wed Mar 11 06:31:47.869098 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 24, in setup
[Wed Mar 11 06:31:47.869101 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] apps.populate(settings.INSTALLED_APPS)
[Wed Mar 11 06:31:47.869105 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 112, in populate
[Wed Mar 11 06:31:47.869108 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] app_config.import_models()
[Wed Mar 11 06:31:47.869112 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "/usr/local/lib/python3.5/dist-packages/django/apps/config.py", line 198, in import_models
[Wed Mar 11 06:31:47.869115 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] self.models_module = import_module(models_module_name)
[Wed Mar 11 06:31:47.869119 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Wed Mar 11 06:31:47.869122 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] return _bootstrap._gcd_import(name[level:], package, level)
[Wed Mar 11 06:31:47.869127 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Wed Mar 11 06:31:47.869132 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Wed Mar 11 06:31:47.869136 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
[Wed Mar 11 06:31:47.869141 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
[Wed Mar 11 06:31:47.869146 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "<frozen importlib._bootstrap_external>", line 665, in exec_module
[Wed Mar 11 06:31:47.869158 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Wed Mar 11 06:31:47.869163 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "/usr/local/lib/python3.5/dist-packages/polls/models.py", line 14, in <module>
[Wed Mar 11 06:31:47.869166 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] class Choice(models.Model):
[Wed Mar 11 06:31:47.869170 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] File "/usr/local/lib/python3.5/dist-packages/polls/models.py", line 15, in Choice
[Wed Mar 11 06:31:47.869172 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] question = models.ForeignKey(Question)
[Wed Mar 11 06:31:47.869186 2020] [wsgi:error] [pid 15027:tid 140380136130304] [remote 10.150.29.220:57041] TypeError: __init__() missing 1 required positional argument: 'on_delete'
[Wed Mar 11 06:31:48.530646 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] mod_wsgi (pid=15027): Target WSGI script '/home/nigsdtm/srv/portal/mysite/wsgi.py' cannot be loaded as Python module.
[Wed Mar 11 06:31:48.530748 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] mod_wsgi (pid=15027): Exception occurred processing WSGI script '/home/nigsdtm/srv/portal/mysite/wsgi.py'.
[Wed Mar 11 06:31:48.530861 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] Traceback (most recent call last):
[Wed Mar 11 06:31:48.530888 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] File "/home/nigsdtm/srv/portal/mysite/wsgi.py", line 16, in <module>
[Wed Mar 11 06:31:48.530891 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] application = get_wsgi_application()
[Wed Mar 11 06:31:48.530897 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Wed Mar 11 06:31:48.530897 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Wed Mar 11 06:31:48.530899 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] django.setup(set_prefix=False)
[Wed Mar 11 06:31:48.530904 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 24, in setup
[Wed Mar 11 06:31:48.530907 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] apps.populate(settings.INSTALLED_APPS)
[Wed Mar 11 06:31:48.530911 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 81, in populate
[Wed Mar 11 06:31:48.530914 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] raise RuntimeError("populate() isn't reentrant")
[Wed Mar 11 06:31:48.530927 2020] [wsgi:error] [pid 15027:tid 140380018607872] [remote 10.150.29.220:42180] RuntimeError: populate() isn't reentrant
This is my apache2 config file:
Listen 80
<VirtualHost *:80>
ServerAdmin alexandru.bran#nokia.com
ServerName app.gdceur.eecloud.dynamic.nsn-net.net
DocumentRoot /home/nigsdtm/srv
Alias /static /home/nigsdtm/srv/portal/mysite/static
<Directory "/home/nigsdtm/srv/portal/mysite/static">
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/portal_error.log
CustomLog ${APACHE_LOG_DIR}/portal_access.log combined
WSGIDaemonProcess mysite python-home=/home/nigsdtm/srv/portal/ python-path=/home/nigsdtm/srv/portal/venv
WSGIProcessGroup mysite
WSGIScriptAlias / /home/nigsdtm/srv/portal/mysite/wsgi.py
<Directory /home/nigsdtm/srv/portal/mysite>
<Files wsgi.py>
Allow from all
</Files>
</Directory>
</VirtualHost>
This is my wsgi file:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
application = get_wsgi_application()
Project folder name (where manage.py is) is called 'portal'
Folder containing wsgi: 'mysite'
App works if I run server from python environment.
I am running Django 2.1.15 with Python 3.5.2
Could you please give me a hint?
Thanks,
Alexandru
I see this line of error:
TypeError: __init__() missing 1 required positional argument: 'on_delete'
This one I recognized as a missing on_delete statement in a ForeignKey attribute.
According to Django2 changelog:
The on_delete argument for ForeignKey and OneToOneField is now required in models and migrations. Consider squashing migrations so that you have fewer of them to update.
You might have developed your application on Django1 and trying to deploy it with Django2.
You should check that you installed the same dependencies on your production server than on your development machine.
I want to serve my Django applications using Apache2 and the mod_wsgi module. I have setup an Apache virtualhost at /etc/apache2/sites-available/mysite.confand I have made some configuration changes to WSGI at home/username/development/mysite/mysite/wsgi.py However, when I navigate to mydomain.com, I am being presented with the 500 Internal Server Error: The server encountered an internal error or misconfiguration and was unable to complete your request.. I am very new to server development and have never used Apache2 before so I am unsure as to where I have gone wrong in my configuration. Below you will find my virtualhost configuration file as well as my WSGI file. Additionally, I have provided the structure layout of my project directory in case this helps. Any help is greatly appreciated.
directory structure
>> home
>> username
>> development
>> mysite
>> mysite
>> settings.py
>> wsgi.py
>> website
>> static
>> manage.py
>> venv
mysite.conf
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /home/username/development/mysite
WSGIScriptAlias / /home/username/development/mysite/mysite/wsgi.py
WSGIDaemonProcess mydomain.com processes=2 threads=15 display-name=%{GROUP} python-home=/home/username/development/venv/lib/python3.5
WSGIProcessGroup mydomain.com
<directory /home/username/development/mysite>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/username/development/mysite/website/static/
<Directory /home/username/development/mysite/website/static>
Require all granted
</Directory>
</VirtualHost>
wsgi.py
import os
import time
import traceback
import signal
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/home/username/development/mysite')
# adjust the Python version in the line below as needed
sys.path.append('/home/username/development/venv/lib/python3.5/site-packages')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
try:
application = get_wsgi_application()
except Exception:
# Error loading applications
if 'mod_wsgi' in sys.modules:
traceback.print_exc()
os.kill(os.getpid(), signal.SIGINT)
time.sleep(2.5)
error.log
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/pdo_mysql.so' - /usr/lib/php/20151012/pdo_mysql.so: undefined symbol: mysqlnd_connect in Unknown on line 0
[Mon Aug 05 06:25:02.417656 2019] [wsgi:warn] [pid 11931] mod_wsgi: Compiled for Python/3.5.1+.
[Mon Aug 05 06:25:02.417679 2019] [wsgi:warn] [pid 11931] mod_wsgi: Runtime using Python/3.5.2.
[Mon Aug 05 06:25:02.418568 2019] [mpm_prefork:notice] [pid 11931] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/3.5.2 configured -- resuming normal operations
[Mon Aug 05 06:25:02.418590 2019] [core:notice] [pid 11931] AH00094: Command line: '/usr/sbin/apache2'
[Mon Aug 05 10:09:39.950527 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] mod_wsgi (pid=23705): Target WSGI script '/home/username/development/mysite/mysite/wsgi.py' cannot be loaded as Python module.
[Mon Aug 05 10:09:39.950606 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] mod_wsgi (pid=23705): Exception occurred processing WSGI script '/home/username/development/mysite/mysite/wsgi.py'.
[Mon Aug 05 10:09:39.951482 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] Traceback (most recent call last):
[Mon Aug 05 10:09:39.951546 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/mysite/mysite/wsgi.py", line 16, in <module>
[Mon Aug 05 10:09:39.951552 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] application = get_wsgi_application()
[Mon Aug 05 10:09:39.951564 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Mon Aug 05 10:09:39.951569 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] django.setup(set_prefix=False)
[Mon Aug 05 10:09:39.951577 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/__init__.py", line 19, in setup
[Mon Aug 05 10:09:39.951597 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Mon Aug 05 10:09:39.951607 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 79, in __getattr__
[Mon Aug 05 10:09:39.951612 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] self._setup(name)
[Mon Aug 05 10:09:39.951619 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 66, in _setup
[Mon Aug 05 10:09:39.951623 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] self._wrapped = Settings(settings_module)
[Mon Aug 05 10:09:39.951630 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 157, in __init__
[Mon Aug 05 10:09:39.951634 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] mod = importlib.import_module(self.SETTINGS_MODULE)
[Mon Aug 05 10:09:39.951640 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "/home/username/development/venv/lib/python3.5/importlib/__init__.py", line 126, in import_module
[Mon Aug 05 10:09:39.951644 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] return _bootstrap._gcd_import(name[level:], package, level)
[Mon Aug 05 10:09:39.951651 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Mon Aug 05 10:09:39.951657 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Mon Aug 05 10:09:39.951664 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked
[Mon Aug 05 10:09:39.951671 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
[Mon Aug 05 10:09:39.951678 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 986, in _gcd_import
[Mon Aug 05 10:09:39.951696 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 969, in _find_and_load
[Mon Aug 05 10:09:39.951704 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
[Mon Aug 05 10:09:39.951725 2019] [wsgi:error] [pid 23705] [remote 10.100.60.43:0] ImportError: No module named 'mysite'
[Mon Aug 05 10:52:33.048933 2019] [mpm_prefork:notice] [pid 11931] AH00169: caught SIGTERM, shutting down
mysite.conf edit
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /home/username/development/mysite
WSGIScriptAlias / /home/username/development/mysite/mysite/wsgi.py
WSGIDaemonProcess mydomain.com python-home=/home/username/development/venv python-path=/home/username/developement/mysite
WSGIProcessGroup mydomain.com
<directory /home/username/development/mysite>
AllowOverride all
Require all granted
Options FollowSymlinks
</directory>
Alias /static/ /home/username/development/mysite/website/static/
<Directory /home/username/development/mysite/website/static>
Require all granted
</Directory>
</VirtualHost>
I developed a platform with django + wsgi + pypy + postgresql + postgis, everything works fine in development environment, but in production it sends error 500 and in the apache log it says ImproperlyConfigured: Error loading psycopg2 module: No module named cffi
my config apache:
<VirtualHost *:80>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /home/user/plataform/project/project/wsgi.py
WSGIDaemonProcess project python-path=/home/user/plataform/project:/home/user/env/site-packages
WSGIProcessGroup project
WSGIPassAuthorization On
<Directory /home/user/plataform/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /media /home/user/plataform/project/media/
Alias /static /home/user/plataform/project/static/
<Directory /home/user/plataform/project/static>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/user/plataform/project/media>
Require all granted
</Directory>
my pip freeze
cffi==1.6.0
Django==1.11.7
django-cors-headers==2.1.0
django-filter==1.1.0
djangorestframework==3.7.3
greenlet==0.4.9
Markdown==2.6.9
olefile==0.44
Pillow==4.3.0
psycopg2cffi==2.7.7
python-stdnum==1.7
pytz==2017.3
readline==6.2.4.1
six==1.11.0
uWSGI==2.0.15
Log Apache:
[Tue Dec 12 11:15:49.727998 2017] [wsgi:warn] [pid 4975:tid 139854422423424] mod_wsgi: Compiled for Python/2.7.11.
[Tue Dec 12 11:15:49.728151 2017] [wsgi:warn] [pid 4975:tid 139854422423424] mod_wsgi: Runtime using Python/2.7.12.
[Tue Dec 12 11:15:49.729853 2017] [mpm_event:notice] [pid 4975:tid 139854422423424] AH00489: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/2.7.12 configured -- resuming normal operations
[Tue Dec 12 11:15:49.729893 2017] [core:notice] [pid 4975:tid 139854422423424] AH00094: Command line: '/usr/sbin/apache2'
[Tue Dec 12 11:15:59.608678 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] mod_wsgi (pid=4978): Target WSGI script '/home/user/plataform/project/project/wsgi.py' cannot be loaded as Python module.
[Tue Dec 12 11:15:59.608785 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] mod_wsgi (pid=4978): Exception occurred processing WSGI script '/home/user/plataform/project/project/wsgi.py'.
[Tue Dec 12 11:15:59.608821 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] Traceback (most recent call last):
[Tue Dec 12 11:15:59.608859 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/plataform/project/project/wsgi.py", line 16, in <module>
[Tue Dec 12 11:15:59.608957 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] application = get_wsgi_application()
[Tue Dec 12 11:15:59.608974 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Tue Dec 12 11:15:59.609017 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] django.setup(set_prefix=False)
[Tue Dec 12 11:15:59.609032 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/__init__.py", line 27, in setup
[Tue Dec 12 11:15:59.609090 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] apps.populate(settings.INSTALLED_APPS)
[Tue Dec 12 11:15:59.609112 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/apps/registry.py", line 108, in populate
[Tue Dec 12 11:15:59.609256 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] app_config.import_models()
[Tue Dec 12 11:15:59.609277 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/apps/config.py", line 202, in import_models
[Tue Dec 12 11:15:59.609366 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] self.models_module = import_module(models_module_name)
[Tue Dec 12 11:15:59.609389 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Tue Dec 12 11:15:59.609451 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] __import__(name)
[Tue Dec 12 11:15:59.609465 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/contrib/auth/models.py", line 4, in <module>
[Tue Dec 12 11:15:59.609580 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
[Tue Dec 12 11:15:59.609593 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
[Tue Dec 12 11:15:59.609671 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] class AbstractBaseUser(models.Model):
[Tue Dec 12 11:15:59.609686 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/models/base.py", line 124, in __new__
[Tue Dec 12 11:15:59.610123 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] new_class.add_to_class('_meta', Options(meta, app_label))
[Tue Dec 12 11:15:59.610139 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/models/base.py", line 325, in add_to_class
[Tue Dec 12 11:15:59.610194 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] value.contribute_to_class(cls, name)
[Tue Dec 12 11:15:59.610216 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/models/options.py", line 214, in contribute_to_class
[Tue Dec 12 11:15:59.610429 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Tue Dec 12 11:15:59.610446 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/__init__.py", line 33, in __getattr__
[Tue Dec 12 11:15:59.610507 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] return getattr(connections[DEFAULT_DB_ALIAS], item)
[Tue Dec 12 11:15:59.610521 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/utils.py", line 211, in __getitem__
[Tue Dec 12 11:15:59.610608 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] backend = load_backend(db['ENGINE'])
[Tue Dec 12 11:15:59.610621 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/utils.py", line 115, in load_backend
[Tue Dec 12 11:15:59.610637 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] return import_module('%s.base' % backend_name)
[Tue Dec 12 11:15:59.610646 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Tue Dec 12 11:15:59.610660 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] __import__(name)
[Tue Dec 12 11:15:59.610668 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 2, in <module>
[Tue Dec 12 11:15:59.610706 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] from django.db.backends.postgresql.base import (
[Tue Dec 12 11:15:59.610733 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] File "/home/user/env/site-packages/django/db/backends/postgresql/base.py", line 25, in <module>
[Tue Dec 12 11:15:59.610870 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
[Tue Dec 12 11:15:59.610901 2017] [wsgi:error] [pid 4978:tid 139854259615488] [remote ::1:30039] ImproperlyConfigured: Error loading psycopg2 module: No module named cffi
I made a clean installation of pypy and created a new virtual environment, then changed the conf. of apache for this
<VirtualHost *:80>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
WSGIScriptAlias / /home/user/plataform/project/project/wsgi.py
WSGIDaemonProcess project python-path=/home/user/plataform/project:/home/user/env/site-packages
WSGIProcessGroup project
WSGIPassAuthorization On
<Directory /home/user/plataform/project/project>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /media/ /home/user/plataform/project/media
Alias /static/ /home/user/plataform/project/static
<Directory /home/user/plataform/project/static>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/user/plataform/project/media>
Require all granted
</Directory>
</Virtualhost>
and everything worked well
I try to deploy Django application under Django 1.8 and Apache mod_wsgi (python 3.4.3, ubuntu 14.04)
I have solved the previous error with import ( Django WSGI deployment. cannot import name 'SimpleCookie' ) but then I meet another one:
Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'
Here bigger piece of the error log:
[Wed Jun 10 18:33:44.021939 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "<frozen importlib._bootstrap>", line 1448, in exec_module
[Wed Jun 10 18:33:44.021960 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
[Wed Jun 10 18:33:44.022198 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/contrib/auth/models.py", line 41, in <module>
[Wed Jun 10 18:33:44.022207 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] class Permission(models.Model):
[Wed Jun 10 18:33:44.022760 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/db/models/base.py", line 139, in __new__
[Wed Jun 10 18:33:44.022770 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] new_class.add_to_class('_meta', Options(meta, **kwargs))
[Wed Jun 10 18:33:44.022807 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/db/models/base.py", line 324, in add_to_class
[Wed Jun 10 18:33:44.022814 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] value.contribute_to_class(cls, name)
[Wed Jun 10 18:33:44.023151 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/db/models/options.py", line 250, in contribute_to_class
[Wed Jun 10 18:33:44.023161 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
[Wed Jun 10 18:33:44.023296 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/db/__init__.py", line 36, in __getattr__
[Wed Jun 10 18:33:44.023304 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] return getattr(connections[DEFAULT_DB_ALIAS], item)
[Wed Jun 10 18:33:44.023514 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/db/utils.py", line 240, in __getitem__
[Wed Jun 10 18:33:44.023558 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] backend = load_backend(db['ENGINE'])
[Wed Jun 10 18:33:44.023603 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/db/utils.py", line 111, in load_backend
[Wed Jun 10 18:33:44.023610 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] return import_module('%s.base' % backend_name)
[Wed Jun 10 18:33:44.023642 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "/usr/local/lib/python3.4/importlib/__init__.py", line 109, in import_module
[Wed Jun 10 18:33:44.023649 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] return _bootstrap._gcd_import(name[level:], package, level)
[Wed Jun 10 18:33:44.023669 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
[Wed Jun 10 18:33:44.023690 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
[Wed Jun 10 18:33:44.023711 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "<frozen importlib._bootstrap>", line 2203, in _find_and_load_unlocked
[Wed Jun 10 18:33:44.023732 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
[Wed Jun 10 18:33:44.023752 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "<frozen importlib._bootstrap>", line 1129, in _exec
[Wed Jun 10 18:33:44.023773 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "<frozen importlib._bootstrap>", line 1448, in exec_module
[Wed Jun 10 18:33:44.023793 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
[Wed Jun 10 18:33:44.023826 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] File "/var/www/.virtualenvs/cp/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 36, in <module>
[Wed Jun 10 18:33:44.023833 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
[Wed Jun 10 18:33:44.023862 2015] [:error] [pid 19282:tid 140071189554944] [client 192.168.1.1:16780] django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'
When running development server no errors appear. There is no errors as well when running in python interpreter in virtualenv cp
>>>import sqlite3
My wsgi.py file is:
import os, sys, site
sys.path.insert(0,'/var/www/.virtualenvs/cp/lib/python3.4/site-packages')
sys.path.insert(0,'/var/www/django_projects/cp')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
exec(open("/var/www/.virtualenvs/cp/bin/activate_this.py").read())
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Here is Apache's virtualhost's conf for the site:
<VirtualHost *:80>
ServerName cp.mysite.com
WSGIDaemonProcess cp user=www-data group=www-data threads=5
WSGIApplicationGroup cp
WSGIScriptAlias / /var/www/django_projects/cp/mysite/wsgi.py
<Directory /var/www/django_projects/cp/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
ErrorLog /var/www/errlogs/cperror.log
</VirtualHost>
Finaly, after making a debug with a help of simple wsgi.py (thanks to #GrahamDumpleton for the link), I've found that my resulting sys.path is not too clean.
So I have manually changed sys.path in wsgi.py taking it from python started in virtualenv cp and then added project directory to this list at the begining in wsgi.py:
import os, sys
virtual_env = '/var/www/.virtualenvs/cp'
sys.path=['%s/lib/python34.zip' % (virtual_env,),
'%s/lib/python3.4' % (virtual_env,),
'%s/lib/python3.4/plat-linux' % (virtual_env,),
'%s/lib/python3.4/lib-dynload' % (virtual_env,),
'%s/lib/python3.4/site-packages' % (virtual_env,),
#'/var/www/python/3.4.3/lib/python3.4',
]
sys.path.insert(0,'/var/www/django_projects/cp')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Possibly this is not the "best practice" solution, but it does remove magic functions and easy to understand and repeat for new user like me :)