Skip to content

Instantly share code, notes, and snippets.

@geolimber
Last active May 4, 2022 19:08
Show Gist options
  • Save geolimber/71186849a0693bfb82a8adf689976780 to your computer and use it in GitHub Desktop.
Save geolimber/71186849a0693bfb82a8adf689976780 to your computer and use it in GitHub Desktop.
Install Python3.9.4 and Apache mod_wsgi on Debian (AWS Lightsail, EC2)

Install latest Python and Apache mod_wsgi on Debian (AWS Lightsail, EC2)

Step 1. Download python binaries

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

Step 2. Configure building python from sources

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"

Step 3. Install python

sudo make altinstall

Step 4. Make shure we have Apache dev package

sudo apt install apache2-dev

Step 5. Install mod_wsgi for our new python3.9

sudo python3.9 -m pip install --upgrade pip
sudo pip install wheel mod_wsgi

Step 6. Replace new mod_wsgi in Apache

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

Step 7. Finally reload Apache server

sudo systemctl reload apache2
@hasibomi
Copy link

hasibomi commented Oct 4, 2021

You must include the module name in LoadModule.
Correct command: LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment