Why?


Search This Blog

Saturday, June 2, 2018

CentOS 7 install and load mod_wsgi in Apache for Python

CentOS 7 install and load mod_wsgi in Apache for Python

Must have httpd-develinstalled

yum install httpd-devel

Source code tar balls can be obtained from:

https://github.com/GrahamDumpleton/mod_wsgi/releases

wget the file you want

uncompress and untar

tar xvfz mod_wsgi-X.Y.tar.gz

cd into the mod_wsgi dir

Now configure, make, and make install

./configure

make

make install

Make sure the module gets loaded in Apache at restart by adding into the main Apache “httpd.conf” configuration file by adding the following

LoadModule wsgi_module modules/mod_wsgi.so

Now restart Apache

systemctl restart httpd

Now check to make sure mod is loaded

apachectl -M


Now to setup for WSGIScriptAlias. This was taken from

https://modwsgi.readthedocs.io/en/master/configuration-directives/WSGIScriptAlias.html

add the following to the httpd.conf file

WSGIScriptAlias /wsgi-scripts/ /var/www/wsgi-scripts/
<Directory /var/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>


mkdir /var/www/wsgi-scripts/

vi /var/www/wsgi-scripts/myapp.wsgi

def application(environ, start_response):
    status = '200 OK'
    output = b'Hello World!'
    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]

Now chmod the file to 705

chmod 705 /var/www/wsgi-scripts/myapp.wsgi

Restart httpd with

systemctl restart httpd

Now see your app in the web browser at

http://your-ip-here/wsgi-scripts/myapp.wsgi

No comments:

Post a Comment