I have been trying forever to get my django api to deploy correctly via apache on my new ec2 instance running amazon linux 2. I have installed python3-mod_wsgi.x86_64 and my venv is using python 3.7.15. Trying to go to my django app url I am getting a 500 error. The server runs fine locally.
LoadModule wsgi_module /etc/httpd/modules/
python3-mod_wsgi.x86_64.so
I am pretty new to this set up, happy to provide any additional info needed.
Error log shows:
[Tue Dec 20 21:31:30.690951 2022] [:error] [pid 19216] /usr
[Tue Dec 20 21:31:30.691287 2022] [:error] [pid 19216] mod_wsgi (pid=19216): Target WSGI script '.../project/project/wsgi.py' cannot be loaded as Python module.
[Tue Dec 20 21:31:30.691323 2022] [:error] [pid 19216] mod_wsgi (pid=19216): Exception occurred processing WSGI script '.../project/project/wsgi.py'.
[Tue Dec 20 21:31:30.691393 2022] [:error] [pid 19216] Traceback (most recent call last):
[Tue Dec 20 21:31:30.691423 2022] [:error] [pid 19216] File ".../project/project/wsgi.py", line 19, in <module>
[Tue Dec 20 21:31:30.691428 2022] [:error] [pid 19216] from django.core.wsgi import get_wsgi_application
[Tue Dec 20 21:31:30.691444 2022] [:error] [pid 19216] ModuleNotFoundError: No module named 'django'
[Tue Dec 20 21:31:51.190670 2022] [:error] [pid 19217] 3.7.15 (default, Oct 31 2022, 22:44:31)
[Tue Dec 20 21:31:51.190707 2022] [:error] [pid 19217] [GCC 7.3.1 20180712 (Red Hat 7.3.1-15)]
My apache conf file:
<VirtualHost *:80>
DocumentRoot path/to/project/root
WSGIScriptAlias / /path/to/wsgi.py WSGIDaemonProcess project-name processes=4 threads=1 display-name=%{GROUP} python-path=path/to/lib/python3.7/site-packages:/path/to/project/root WSGIProcessGroup project-group
<Directory "/path/to/project/root">
Require all granted
</Directory>
#SSL stuff...
</VirtualHost>
my wsgi.py file:
I think I originally had the wrong mod_wsgi installed (built for python2). I removed that and installed python3-mod_wsgi.x86_64.
I then realized that my mod_wsgi was for python version 3.7, but my application venv was running python 3.6.8. I then wiped the venv and created a new one with python 3.7.15. Changed the conf path to the correct 3.7 site-packages (my venv). Still same error
Would appreciate any help with this, and again, happy to provide more info if needed.