I run Apache2 in a Docker container and want to host my Django site using mod_wsgi. Anyway WSGI process fails to start and I get the error below. I tried using Python paths of the container and of a separate virtual environment, but I get the same error. What am I doing wrong?
[Thu Jan 11 10:39:44.447690 2024] [wsgi:warn] [pid 316:tid 140618355098752] (2)No such file or directory: mod_wsgi (pid=316): Unable to stat Python home /var/www/html/my-site.com.com/python3.7. Python interpreter may not be able to be initialized correctly. Verify the supplied path and access permissions for whole of the path.
Fatal Python error: initfsencoding: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Here is my Dockerfile:
FROM python:3.7.17-buster
WORKDIR /var/www/html/my-site.com
SHELL ["/bin/bash", "-c"]
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV VIRTUAL_ENV=/var/www/html/my-site.com/python3.7
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
COPY ./dev .
COPY ./requirements.txt .
RUN apt update
RUN apt upgrade -y
RUN apt install apache2 libapache2-mod-wsgi-py3 -y
RUN a2enmod ssl rewrite wsgi headers macro
RUN python -m venv $VIRTUAL_ENV
RUN source $VIRTUAL_ENV/bin/activate
RUN pip install --upgrade pip && \
pip install --upgrade setuptools && \
pip install -r requirements.txt
Here is a relevant Apache config segment:
WSGIScriptAlias / /var/www/html/my-site.com/main/wsgi.py
WSGIDaemonProcess prod_$site python-home=/var/www/html/my-site.com/python3.7 python-path=/var/www/html/my-site.com/python3.7/site-packages
WSGIProcessGroup prod_$site
Okay, I figured it. I applied the suggestions in the comments by removing virtual environment. Also, I updated
WSGIDaemonProcessdirective to use Python paths of the container.Dockerfilemy-site.conf