mod_wsgi configuration on Redhat Alma

23 views
Skip to first unread message

pcar...@gmail.com

unread,
Feb 12, 2025, 3:42:27 PMFeb 12
to modwsgi
Hello all I have been following the documentation to install mod_wsgi and configure it for my django Application but I am getting errors when I start httpd.  Any help is appreciated.... I've been hammering away at this most of the day unfortunately.

Documentation:
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/modwsgi/ 

httpd.conf:
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / /home/django/portal/sec_web/sec_web/wsgi.py
WSGIPythonHome /home/django/portal/env
WSGIPythonPath /home/django/portal/sec_web

<Directory /home/django/portal/sec_web/sec_web>
    <Files wsgi.py>
        Require all granted
    </Files>
</Directory>

Directory structure (Portal is just a directory for organization my project is sec_web):
portal
├── env
│   ├── bin
│   │   ├── activate
│   │   ├── activate.csh
│   │   ├── activate.fish
│   │   ├── Activate.ps1
│   │   ├── mod_wsgi-express
│   │   ├── pip
│   │   ├── pip3
│   │   ├── pip3.9
│   │   ├── python -> python3
│   │   ├── python3 -> /bin/python3
│   │   └── python3.9 -> python3
│   ├── include
│   ├── lib
│   │   └── python3.9
│   ├── lib64 -> lib
│   └── pyvenv.cfg
└── sec_web
    ├── api
    │   ├── admin.py
    │   ├── apps.py
    │   ├── __init__.py
    │   ├── migrations
    │   ├── models.py
    │   ├── __pycache__
    │   ├── serializers.py
    │   ├── tests.py
    │   ├── urls.py
    │   └── views.py
    ├── db.sqlite3
    ├── endpoint
    │   ├── admin.py
    │   ├── apps.py
    │   ├── __init__.py
    │   ├── migrations
    │   ├── models.py
    │   ├── __pycache__
    │   ├── tests.py
    │   ├── urls.py
    │   └── views.py
    ├── logfile.log
    ├── logfile.log.bak
    ├── manage.py
    ├── requirements.txt
    ├── sec_web
    │   ├── asgi.py
    │   ├── __init__.py
    │   ├── migrations
    │   ├── __pycache__
    │   ├── settings.py
    │   ├── urls.py
    │   ├── utils.py
    │   └── wsgi.py
    └── urls.py

/var/log/httpd/error_log:
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

Current thread 0x00007fc56a8de540 (most recent call first):
<no Python frame>
Python path configuration:
  PYTHONHOME = '/home/django/portal/env'
  PYTHONPATH = (not set)
  program name = 'python3'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = '/usr/bin/python3'
  sys.base_prefix = '/home/django/portal/env'
  sys.base_exec_prefix = '/home/django/portal/env'
  sys.platlibdir = 'lib64'
  sys.executable = '/usr/bin/python3'
  sys.prefix = '/home/django/portal/env'
  sys.exec_prefix = '/home/django/portal/env'
  sys.path = [
    '/home/django/portal/env/lib64/python39.zip',
    '/home/django/portal/env/lib64/python3.9',
    '/home/django/portal/env/lib64/python3.9/lib-dynload',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
/var/log/httpd/error_log


Graham Dumpleton

unread,
Feb 12, 2025, 4:00:08 PMFeb 12
to mod...@googlegroups.com
Are you sure the system mod_wsgi package you are using is compiled for same Python version as the Python virtual environment you are using?

This is usually the culprit for this issue.

Also what are the file system permissions on /home/django

ls -lasd /home/django

Some Linux systems will make home directories non readable to other users, which means Apache can't read anything under it, which can result in this error.

Would need to do:

chmod o+rx /home/django

for the home directory.

Also, if you have set up stuff under that directory as root, you can have similar issues with directories/files under the home directory because umask for root is usually such that doesn't allow access to others.

So check directory/file permissions on home directory and project files.

Also ensure that Python is upgraded to latest patch revision at least.

My memory is bad, but on some Linux distros early Python 3.9 patch revisions broke ability to be embedded in other systems, with an error like this. Problem didn't occur with normal upstream Python and only that shipped by the distro. I thought it was Ubuntu though, so may not be relevant.

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/modwsgi/1b7e6f7e-daae-4ff6-849e-529ca0055355n%40googlegroups.com.

pcar...@gmail.com

unread,
Feb 13, 2025, 11:29:16 AMFeb 13
to modwsgi
Thanks Graham for the prompt response. Here is what I discovered based on your questions.

Version Info:
mod_wsgi/4.7.1
Python/3.9.21 (latest revision)
What would be the correct mod_wsgi version for python 3.9?  I couldn't find this in the documentation anywere for mod_wsgi?

(env) [pcarra@ip-10-42-42-120 portal]$ ls -lasd /home/django
0 drwxr-xr-x. 5 django django 185 Feb 13 14:03 /home/django

For directory permissions I have changed everything under /home/django to be owned by django:django and then ran chmod o+rx on /home/django (I had been using root to create somethings)

Graham Dumpleton

unread,
Feb 13, 2025, 4:10:38 PMFeb 13
to mod...@googlegroups.com

On 14 Feb 2025, at 3:29 am, pcar...@gmail.com <pcar...@gmail.com> wrote:

Thanks Graham for the prompt response. Here is what I discovered based on your questions.

Version Info:
mod_wsgi/4.7.1
Python/3.9.21 (latest revision)
What would be the correct mod_wsgi version for python 3.9?  I couldn't find this in the documentation anywere for mod_wsgi?

Ideally you would use the most up to date Python version available.

You can learn more about Python and what versions are available at:


You appear to be using an old OS distro since they have a quite old version of Python if that is the system supplied Python installation.

You are also on an old version of mod_wsgi as well. The latest version is 5.0.2.

Is there a reason you are using that specific Linux distro since it appears to be quite old.

pcar...@gmail.com

unread,
Feb 14, 2025, 2:23:53 PMFeb 14
to modwsgi
Well that was what was supplied when I spun up a server on aws.  We updated the python package and mod_wsgi and it looks like we are working again.  Thanks Graham you have been awesome as always!
Reply all
Reply to author
Forward
0 new messages