Skip to content

Instantly share code, notes, and snippets.

@hasibomi
Forked from geolimber/README.md
Last active October 4, 2021 14:23
Show Gist options
  • Save hasibomi/fb6c9a07517700458bd743b95d480e16 to your computer and use it in GitHub Desktop.
Save hasibomi/fb6c9a07517700458bd743b95d480e16 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.7/Python-3.9.7.tgz
tar zxvf Python-3.9.7.tgz
cd Python-3.9.7

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 wsgi_module /usr/lib/apache2/modules/mod_wsgi-py39.cpython-39-x86_64-linux-gnu.so

Step 7. Finally reload Apache server

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