fb_pixel

Python App Deployment in Windows (Apache-Server, mod_wsgi)

Development | Programming languages
Description
Deploying Python web app in Windows Server (Apache 2.4) using WSGI module. Step by step tutorial Total 25 steps ..
Attachments
No attachments
Info
Description
01. Download latest Apache 2.4 64bit from https://www.apachelounge.com/download/ 
02. Unzip httpd-2.4.43-win64-VS16.zip to "c:\Apache24" directory
03. Install Apache as a service. Open command prompt as Administrator and type: c:\Apache24\bin\httpd.exe -k install
04. Start Apache service (Windows + type: "services") and press Enter
05. Look at Apache24 service and right click -> Start
06. Open http://localhost
07. When you see "It works!" everithing is ok

08. Download latest Python 3.8 64bit from https://www.python.org/ftp/python/3.8.2/python-3.8.2-amd64.exe
09. Install python-3.8.2-amd64.exe to "c:\Python38" directory
10. Download WSGI module for Python from  https://pypi.org/project/mod-wsgi/#files
11. The best option is Downloaded Binaries for Python Extension Pachages from http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
12. Download "mod_wsgi-4.7.1+ap24vc15-cp38-cp38-win_amd64.whl" file
13. Run "python pip3 install mod_wsgi-4.7.1+ap24vc15-cp38-cp38-win_amd64.whl"
14. Now we make WSGI configuration for Python 3.8
15. Run the command and generate a config "c:\Python38\Scripts\mod_wsgi-express.exe module-config > config.txt"
16. Open config.txt and all lines paste to "c:\Apache24\conf\httpd.conf" (at the end of the file)

17. Create sample WSGI aplication
18. Make directory "c:\WSGI"
19. Create a new file "c:\WSGI\web.wsgi" 

#!c:\Python38\python.exe

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

20. Open "c:\Apache24\conf\httpd.conf" and Enable Virtual hosts, line 510
21. Open Apache vHosts file "c:\Apache24\conf\extra\httpd-vhosts.conf" and paste new configuration

<VirtualHost *:80>
    DocumentRoot "C:/Apache24/htdocs"
    ErrorLog "C:/Apache24/logs/wsgi.error.log"
    LogLevel warn
    CustomLog "C:/Apache24/logs/wsgi.access.log" combined
    WSGIScriptAlias /wsgi "C:/WSGI/web.wsgi"
    <Directory "C:/WSGI">
        Options Indexes FollowSymLinks ExecCGI
        AllowOverride All
        Require all granted
        AddHandler cgi-script .cgi .py
     </Directory>
</VirtualHost>

22. Now Restart Apache Service (Windows + type: "services") and press Enter
23. Look at Apache24 service and right click -> Restart
24. Now open http://localhost/ default application
25. And http://localhost/wsgi sample WSGI application


on April 15th, 2020 (3:57 pm)
All coments
This job has not been commented yet.