I am trying to deploy my Django model on an Apache2 server and it is running well on ‘ip’:8000. But when i am trying to run without 8000 port after completing all prerequisites i am getting this error
[Thu Jul 07 10:18:36.178228 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245] File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
[Thu Jul 07 10:18:36.178240 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245] return _bootstrap._gcd_import(name[level:], package, level)
[Thu Jul 07 10:18:36.178247 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245] File "/root/novo-ai-api-main/backend/dj/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 20, in <module>
[Thu Jul 07 10:18:36.178253 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245] from django.db.backends.base.base import BaseDatabaseWrapper, timezone_constructor
[Thu Jul 07 10:18:36.178260 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245] File "/root/novo-ai-api-main/backend/dj/lib/python3.8/site-packages/django/db/backends/base/base.py", line 12, in <module>
[Thu Jul 07 10:18:36.178277 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245] from backports import zoneinfo
[Thu Jul 07 10:18:36.178308 2022] [wsgi:error] [pid 368483:tid 139647379601152] [remote 106.79.194.125:58245] ImportError: cannot import name 'zoneinfo' from 'backports' (unknown location)
These are my all working files
000-default.conf
<VirtualHost *:80>
#ServerAdmin webmaster@localhost
DocumentRoot /root/novo-ai-api-main
ErrorLog /root/novo-ai-api-main/error.log
CustomLog /root/novo-ai-api-main/access.log combine
<Directory /root/novo-ai-api-main/backend/server/server>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /static /root/novo-ai-api-main/static
<Directory /root/novo-ai-api-main/static>
Require all granted
</Directory>
WSGIScriptAlias / /root/novo-ai-api-main/backend/server/server/wsgi.py
WSGIDaemonProcess django_app python-path=/root/novo-ai-api-main/backend/server python-home=/root/novo-ai-api-main/backend/dj/
WSGIProcessGroup django_app
</VirtualHost>
apache2.conf
apache2.conf
ServerRoot "/etc/apache2"
Timeout 300
MaxKeepAliveRequests 100
#KeepAliveTimeout: Number of seconds to wait for the next request from the
#same client on the same connection.
KeepAliveTimeout 5
#These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
LogLevel warn
#Sets the default security model of the Apache2 HTTPD server. It does
<Directory />
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Directory /var/www/>
AllowOverride All
Require all granted
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
#AccessFileName .htaccess
#<FilesMatch "^.ht">
#Require all denied
#</FilesMatch>
IncludeOptional conf-enabled/*.conf
IncludeOptional sites-enabled/*.conf
#vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I installed mod_wsgi correctly for Python 3.8.10
#wsgi.py
import os, sys
import site
site.addsitedir('/root/novo-ai-api-main/backend/dj/lib/python3.8/site-packages')
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'server.settings')
application = get_wsgi_application()
Also I have given permissions to all the working files but nothing happened
####
drwx--x--x 9 root root 4096 Jun 16 22:05 .
drwxr-xr-x 19 root root 4096 Jun 14 14:05 ..
drwxr-xr-x 3 root root 4096 Jun 13 23:38 .local
drwxrwxr-x 8 root root 4096 Jun 16 01:24 mod_wsgi-4.9.2
drwxr-xr-x 5 www-data www-data 4096 Jun 14 23:53 novo-ai-api-main <-(project)
drwxr-xr-x 5 www-data www-data 4096 Jun 14 23:14 backend
drw-r--r-- 8 www-data www-data 4096 Jun 14 00:33 static
drwxr-xr-x 6 www-data www-data 4096 Jun 14 00:16 dj <- (venv) ####
What can I try next?
2
Answers
Finally I have solved this issue by giving permissions to all files and directories in my Django project. Using this command
It solved my many errors related to modules. If you are new to Apache deployment make sure you give right permissions to all files in directories.
ModuleNotFoundError: No module named ‘backports’
I solved this error by first removing the package backports.zoneinfo from my project
and then re-install by typing
pip install backports.zoneinfo[tzdata]