Apache 2.4 + mod_wsgi + Python 3.7 + Django installation on Centos 7.10

How to Apache 2.4 + mod_wsgi + Python 3.7 + Django installation

 

Httpd 2.4

1. Install  httpd
yum install httpd
 
2. Install  httpd-devel
yum install httpd-devel 

Python 3.7 on Centos 7.10


1. Download the newest python

cd /opt/
wget -dvS --no-check-certificate https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz

2. Unpack and install


tar xzf Python-3.7.0.tgz

cd /opt/Python-3.7.0/

./configure --prefix=/usr/local --enable-shared --with-threads --enable-optimizations

make altinstall

 
to test if works: 
python3.7 -V

mod_wsgi

0. (optional) uninstall current mod_wsgi

yum erase mod_wsgi



1. Download the newest mod_wsgi and install

cd /opt/

wget https://files.pythonhosted.org/packages/9e/37/dd336068ece37c43957aa337f25c59a9a6afa98086e5507908a2d21ab807/mod_wsgi-4.6.4.tar.gz


tar xzf mod_wsgi-4.6.4.tar.gz


cd mod_wsgi-4.6.4.tar.gz


 ./configure --with-python=/usr/local/bin/python3.7


LD_RUN_PATH=/usr/local/lib make


make install



2. Add path to  /etc/ld.so.conf
include ld.so.conf.d/*.conf

/usr/local/lib

3. Run


ldconfig 



4. check if mod_wsgi is linked correctly

ldd /usr/lib64/httpd/modules/mod_wsgi.so
        linux-vdso.so.1 =>  (0x00007ffc465bb000)
        libpython3.7m.so.1.0 => /usr/local/lib/libpython3.7m.so.1.0 (0x00007f2d23842000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2d23626000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f2d23422000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007f2d2321f000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f2d22f1d000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f2d22b50000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f2d23fe3000)

Install Django

pip3.7 install --upgrade pip

pip3.7 install Django

Configure apache to use wsgi

Add new config at /etc/httpd/conf.d/project1.conf

<IfModule mod_ssl.c>
Listen 8443 https
<VirtualHost *:8443>

        ServerAdmin email@domain
        ServerName tester.com
        ServerAlias tester.com
        DocumentRoot /var/www/html/project1

        ErrorLog /var/log/httpd/project1-error.log
        CustomLog /var/log/httpd/project1-access.log combined
        CustomLog logs/project1-ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

        # Django project
        Alias /django_1 /opt/py/django_1
        <Directory /opt/py/django_1>
                Require all granted
        </Directory>

        Alias /static /opt/py/django_1/static
        <Directory /opt/py/django_1/static>
                Require all granted
        </Directory>

        <Directory /opt/py/django_1>
                <Files wsgi.py>
                    Require all granted
                </Files>
        </Directory>

        WSGIDaemonProcess django_1 python-path=/opt/py/django_1 python-home=/opt/py/django_1/venv
        WSGIProcessGroup django_1
        WSGIScriptAlias / /opt/py/django_1/django_1/wsgi.py
        WSGIPassAuthorization On


        SSLCertificateFile /etc/letsencrypt/live/tester.com/cert.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/tester.com/privkey.pem
        Include /etc/letsencrypt/options-ssl-apache.conf
        SSLCertificateChainFile /etc/letsencrypt/live/tester.com/chain.pem

</VirtualHost>
</IfModule>



Test if everything works:

https://tester.com:8443/admin/login/?next=/admin/


Don`t forget to add ALLOWED_HOSTS in your  settings.py

Also add
STATIC_URL = '/static/'
STATIC_ROOT = '/opt/py/django_1/static/'







Comments

Post a Comment

Popular posts from this blog

How to clean DB from old logs in Magento 1.x

Reduce (shrink) and resize raw disk at Proxmox