I have set up a basic site in Django and am trying to serve it using Apache 2, however when trying i get an error:
[Tue Jul 07 08:03:50.274206 2020] [mpm_event:notice] [pid 21614:tid 140492525521856] AH00489: Apache/2.4.29 (Ubuntu) mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
[Tue Jul 07 08:03:50.274292 2020] [core:notice] [pid 21614:tid 140492525521856] AH00094: Command line: '/usr/sbin/apache2'
[Tue Jul 07 08:03:55.841352 2020] [wsgi:error] [pid 21616:tid 140492373808896] [remote myip:myport] mod_wsgi (pid=21616): Target WSGI script '/home/ubuntu/Django/customspiritco/wsgi.py' cannot be loaded as Python module.
[Tue Jul 07 08:03:55.841401 2020] [wsgi:error] [pid 21616:tid 140492373808896] [remote myip:myport] mod_wsgi (pid=21616): Exception occurred processing WSGI script '/home/ubuntu/Django/customspiritco/wsgi.py'.
[Tue Jul 07 08:03:55.841626 2020] [wsgi:error] [pid 21616:tid 140492373808896] [remote myip:myport] Traceback (most recent call last):
[Tue Jul 07 08:03:55.841655 2020] [wsgi:error] [pid 21616:tid 140492373808896] [remote myip:myport] File "/home/ubuntu/Django/customspiritco/wsgi.py", line 3, in <module>
[Tue Jul 07 08:03:55.841661 2020] [wsgi:error] [pid 21616:tid 140492373808896] [remote myip:myport] from django.core.wsgi import get_wsgi_application
[Tue Jul 07 08:03:55.841669 2020] [wsgi:error] [pid 21616:tid 140492373808896] [remote myip:myport] File "/home/ubuntu/Django/env/lib/python3.6/site-packages/django/__init__.py", line 1, in <module>
[Tue Jul 07 08:03:55.841745 2020] [wsgi:error] [pid 21616:tid 140492373808896] [remote myip:myport] from django.utils.version import get_version
[Tue Jul 07 08:03:55.841768 2020] [wsgi:error] [pid 21616:tid 140492373808896] [remote myip:myport] ImportError: cannot import name 'get_version'
My installed version are: Apache/2.4.29 (Ubuntu), mod_wsgi/4.5.17, Python/3.6, Django/2.2.10
My djangoproject.conf for apache2 is:
<VirtualHost *:80>
ServerAdmin admin@customspirit.co
ServerName customspirit.co
DocumentRoot /home/ubuntu/Django
<Directory /home/ubuntu/Django>
Require all granted
</Directory>
Alias /static /home/ubuntu/Django/static_in_env
<Directory /home/ubuntu/Django/static_in_env>
Options FollowSymLinks
Order allow,deny
Allow from all
Require all granted
</Directory>
Alias /media /home/ubuntu/Django/media_root
<Directory /home/ubuntu/Django/media_root>
Options FollowSymLinks
Order allow,deny
Allow from all
Require all granted
</Directory>
# adjust the following line to match your Python path
WSGIDaemonProcess customspiritco python-home=/home/ubuntu/Django/env python-path=/home/ubuntu/Django
WSGIProcessGroup customspiritco
WSGIScriptAlias / /home/ubuntu/Django/customspiritco/wsgi.py
<Directory /home/ubuntu/Django/custompspiritco>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
</VirtualHost>
The init.py file where the error is looks like:
from django.utils.version import get_version
VERSION = (2, 2, 10, 'final', 0)
__version__ = get_version(VERSION)
def setup(set_prefix=True):
"""
Configure the settings (this happens as a side effect of accessing the
first setting), configure logging and populate the app registry.
Set the thread-local urlresolvers script prefix if `set_prefix` is True.
"""
from django.apps import apps
from django.conf import settings
from django.urls import set_script_prefix
from django.utils.log import configure_logging
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
if set_prefix:
set_script_prefix(
'/' if settings.FORCE_SCRIPT_NAME is None else settings.FORCE_SCRIPT_NAME
)
apps.populate(settings.INSTALLED_APPS)
The wgsi.py file looks like:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'customspiritco.settings.production')
application = get_wsgi_application()
I get an Internal Server Error(500) every time i try and load anything and the error repeats in the log.
I have now reinstalled Django to version 2.2.14 which has solved the issue and brought a new issue
[Tue Jul 07 09:03:28.291015 2020] [wsgi:error] [pid 25208:tid 139979472283392] [remote myip:myport] ModuleNotFoundError: No module named 'django'
After compiling mod_wgsi for my version of python this error has now been replaced by:
[Tue Jul 07 10:43:39.699154 2020] [wsgi:info] [pid 1305:tid 140703057624000] mod_wsgi (pid=1305): Adding '/home/ubuntu/Django' to path.
[Tue Jul 07 10:43:39.699699 2020] [mpm_event:debug] [pid 1305:tid 140702956263168] event.c(2218): AH02471: start_threads: Using epoll (wakeable)
[Tue Jul 07 10:44:08.714222 2020] [authz_core:debug] [pid 1304:tid 140702826608384] mod_authz_core.c(809): [client myip:myport] AH01626: authorization result of Require all granted: granted
[Tue Jul 07 10:44:08.714265 2020] [authz_core:debug] [pid 1304:tid 140702826608384] mod_authz_core.c(809): [client myip:myport] AH01626: authorization result of <RequireAny>: granted
[Tue Jul 07 10:44:08.714312 2020] [authz_core:debug] [pid 1304:tid 140702826608384] mod_authz_core.c(809): [client myip:myport] AH01626: authorization result of Require all granted: granted
[Tue Jul 07 10:44:08.714319 2020] [authz_core:debug] [pid 1304:tid 140702826608384] mod_authz_core.c(809): [client myip:myport] AH01626: authorization result of <RequireAny>: granted
[Tue Jul 07 10:44:08.727681 2020] [wsgi:info] [pid 1303:tid 140702905882368] mod_wsgi (pid=1303): Create interpreter 'customspirit.co|'.
[Tue Jul 07 10:44:08.740572 2020] [wsgi:info] [pid 1303:tid 140702905882368] mod_wsgi (pid=1303): Adding '/home/ubuntu/Django' to path.
[Tue Jul 07 10:44:08.740929 2020] [wsgi:info] [pid 1303:tid 140702905882368] [remote myip:myport] mod_wsgi (pid=1303, process='customspiritco', application='customspirit.co|'): Loading Python script file '/home/ubuntu/Django/customspiritco/wsgi.py'.
[Tue Jul 07 10:44:08.741202 2020] [wsgi:error] [pid 1303:tid 140702905882368] [remote myip:myport] mod_wsgi (pid=1303): Failed to exec Python script file '/home/ubuntu/Django/customspiritco/wsgi.py'.
[Tue Jul 07 10:44:08.741229 2020] [wsgi:error] [pid 1303:tid 140702905882368] [remote myip:myport] mod_wsgi (pid=1303): Exception occurred processing WSGI script '/home/ubuntu/Django/customspiritco/wsgi.py'.
[Tue Jul 07 10:44:08.741396 2020] [wsgi:error] [pid 1303:tid 140702905882368] [remote myip:myport] Traceback (most recent call last):
[Tue Jul 07 10:44:08.741421 2020] [wsgi:error] [pid 1303:tid 140702905882368] [remote myip:myport] File "/home/ubuntu/Django/customspiritco/wsgi.py", line 3, in <module>
[Tue Jul 07 10:44:08.741427 2020] [wsgi:error] [pid 1303:tid 140702905882368] [remote myip:myport] from django.core.wsgi import get_wsgi_application
[Tue Jul 07 10:44:08.741441 2020] [wsgi:error] [pid 1303:tid 140702905882368] [remote myip:myport] ModuleNotFoundError: No module named 'django'