wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz
tar zxvf Python-3.9.4.tgz
cd Python-3.9.4
In order to install later mod_wsgi for our version of python we need to configure with enabling python shared libraries
./configure --prefix=/usr/local --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
sudo make altinstall
sudo apt install apache2-dev
sudo python3.9 -m pip install --upgrade pip
sudo pip install wheel mod_wsgi
Find where latest mod_wsgi.so is placed under the python3.9 find / -iname 'mod_wsgi*' 2>/dev/null
In my case it was in
/usr/local/lib/python3.9/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so
So just copy it to apache modules folder:
sudo cp /usr/local/lib/python3.9/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so /usr/lib/apache2/modules/
And finally point apache to new mod_wsgi:
cd /etc/apache2/mods-available/
Open with any editor (in my case vim) file wsgi.load
and replace first line with LoadModule /usr/lib/apache2/modules/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so
sudo systemctl reload apache2
You must include the
module
name inLoadModule
.Correct command:
LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so