{"id":24059,"library":"mod-wsgi","title":"mod_wsgi","description":"mod_wsgi is an Apache HTTP Server module that provides a WSGI compliant interface for hosting Python web applications under Apache. It supports both embedded and daemon modes, with the ability to run multiple Python versions and virtual environments. Current version 5.0.2 (2024-02-19) requires Python >=3.8. Release cadence is irregular, typically minor updates every few years.","status":"active","version":"5.0.2","language":"python","source_language":"en","source_url":"https://github.com/GrahamDumpleton/mod_wsgi","tags":["apache","wsgi","web-server","deployment"],"install":[{"cmd":"pip install mod-wsgi","lang":"bash","label":"Install mod_wsgi (source build)"}],"dependencies":[{"reason":"Required to compile mod_wsgi from source (system package).","package":"apache2-dev","optional":true},{"reason":"Alternative pre-packaged binary for Debian/Ubuntu instead of pip install.","package":"libapache2-mod-wsgi-py3","optional":true}],"imports":[{"note":"WSGI application callable must be named 'application' (default) or specified via WSGIApplicationGroup directive.","symbol":"application","correct":"def application(environ, start_response): ...  # then assign to module-level 'application'"}],"quickstart":{"code":"# Save as myapp.wsgi\ndef application(environ, start_response):\n    status = '200 OK'\n    output = b'Hello, World!'\n    response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))]\n    start_response(status, response_headers)\n    return [output]","lang":"python","description":"Minimal WSGI application file. Place in your Apache document root or a directory accessible to Apache, then configure Apache with 'WSGIScriptAlias / /path/to/myapp.wsgi'."},"warnings":[{"fix":"Use 'WSGIDaemonProcess' to isolate application in daemon mode with controlled thread count.","message":"Thread limit issues when using embedded mode with threaded MPM (worker/event). Default threads per process may cause crashes if exceeded.","severity":"breaking","affected_versions":"all"},{"fix":"Set 'WSGIApplicationGroup %{GLOBAL}' if using single-threaded frameworks; use 'maximum-requests' to recycle processes.","message":"Memory leak when using Python threads or blocking I/O inside mod_wsgi daemon mode with multiple processes.","severity":"gotcha","affected_versions":"all"},{"fix":"Migrate to Python 3 and upgrade mod_wsgi to >=5.0.0.","message":"Python 2 support removed in 5.0.0; mod_wsgi 4.x still available for Python 2.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Use Apache with mod_wsgi in production; mod_wsgi-express is for testing only.","message":"The 'mod_wsgi-express' command is the recommended development server but is not production-ready.","severity":"deprecated","affected_versions":">=4.6.0"},{"fix":"Set 'WSGIPythonHome /path/to/venv' in Apache config.","message":"Virtual environments: must be activated before Apache start or specify Python home via WSGIPythonHome.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Do not import 'mod_wsgi' in Python scripts. Use 'pip install mod-wsgi' to build the module, then load it in Apache with 'LoadModule wsgi_module modules/mod_wsgi.so'.","cause":"mod_wsgi is an Apache module, not a Python package that can be imported directly in Python code.","error":"ImportError: No module named 'mod_wsgi'"},{"fix":"Run 'sudo apt install libapache2-mod-wsgi-py3' on Debian/Ubuntu or build with 'pip install mod-wsgi' and copy the .so to Apache modules directory.","cause":"mod_wsgi.so is not in Apache's module directory or Apache can't find it.","error":"Unable to load wsgi module: mod_wsgi.so: cannot open shared object file"},{"fix":"Use daemon mode with 'WSGIDaemonProcess' directive instead of embedded mode.","cause":"Occurs when mod_wsgi runs embedded in Apache's child processes that lack proper stdio.","error":"Fatal Python error: init_sys_streams: can't initialize sys standard streams"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}