mod-wsgi


Namemod-wsgi JSON
Version 5.0.1 PyPI version JSON
download
home_pagehttps://www.modwsgi.org/
SummaryInstaller for Apache/mod_wsgi.
upload_time2024-10-01 00:17:00
maintainerGraham Dumpleton
docs_urlNone
authorGraham Dumpleton
requires_python>=3.8
licenseApache License, Version 2.0
keywords mod_wsgi wsgi apache
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Overview
--------

The mod_wsgi package provides an Apache module that implements a WSGI
compliant interface for hosting Python based web applications on top of the
Apache web server.

*Note that the major version 5.0 was introduced not because of any new major
features but because from version 5.0 onwards compatability with Python 2.7 is
no longer guaranteed. A minimum Python version of 3.8 will be enforced by the
Python package installation configuration.*

Installation of mod_wsgi from source code can be performed in one of two
ways.

The first way of installing mod_wsgi is the traditional way that has been
used by many software packages. This is where it is installed as a module
directly into your Apache installation using the commands ``configure``,
``make`` and ``make install``, a method sometimes referred to by the
acronym CMMI. This method works with most UNIX type systems. It cannot
be used on Windows.

The second way of installing mod_wsgi is to install it as a Python package
into your Python installation using the Python ``pip install`` command.
This can be used on all platforms, including Windows.

This second way of installing mod_wsgi will compile not only the Apache
module for mod_wsgi, but will also install a Python module and admin
script, which on UNIX type systems can be used to start up a standalone
instance of Apache directly from the command line with an auto generated
configuration.

This later mechanism for installing mod_wsgi using Python ``pip`` is a much
simpler way of getting starting with hosting your Python web application.
In particular, this installation method makes it very easy to use
Apache/mod_wsgi in a development environment without the need to perform
any Apache configuration yourself.

The Apache module for mod_wsgi created when using the ``pip install``
method can still be used with the main Apache installation, via manual
configuration if necessary. As detailed later in these instructions, the
admin script installed when you use ``pip install`` can be used to generate
the configuration to manually add to the Apache configuration to load
mod_wsgi.

Note that although MacOS X is a UNIX type system, the ``pip install``
method is the only supported way for installing mod_wsgi.

Since MacOS X Sierra, Apple has completely broken the ability to install
third party Apache modules using the ``apxs`` tool normally used for this
task. History suggests that Apple will never fix the problem as they have
broken things in the past in other ways and workarounds were required as
they never fixed those problems either. This time there is no easy
workaround as they no longer supply certain tools which are required to
perform the installation.

The ``pip install`` method along with the manual configuration of Apache
is also the method you need to use on Windows.

System Requirements
-------------------

With either installation method for mod_wsgi, you must have Apache
installed. This must be a complete Apache installation. It is not enough to
have only the runtime packages for Apache installed. You must have the
corresponding development package for Apache installed, which contains the
Apache header files, as these are required to be able to compile and install
third party Apache modules.

Similarly with Python, you must have a complete Python installation which
includes the corresponding development package, which contains the header
files for the Python library.

If you are running Debian or Ubuntu Linux with Apache 2.2 system packages,
and were using the Apache prefork MPM you would need both:

* apache2-mpm-prefork
* apache2-prefork-dev

If instead you were using the Apache worker MPM, you would need both:

* apache2-mpm-worker
* apache2-threaded-dev

If you are running Debian or Ubuntu Linux with Apache 2.4 system packages,
regardless of which Apache MPM is being used, you would need both:

* apache2
* apache2-dev

If you are running RHEL, CentOS or Fedora, you would need both:

* httpd
* httpd-devel

If you are using the Software Collections Library (SCL) packages with
RHEL, CentOS or Fedora, you would need:

* httpd24
* httpd24-httpd-devel

If you are running MacOS X, Apache is supplied with the operating system.
If running a recent MacOS X version, you will though need to have the Xcode
command line tools installed as well as the Xcode application. The command
line tools can be installed by running ``xcode-select --install``. The
Xcode application can be installed from the MacOS X App Store. If you are
using older MacOS X versions, you may be able to get away with having just
the command line tools.

If you are running Windows, it is recommended you use the Apache
distribution from Apache Lounge (www.apachelounge.com). Other Apache
distributions for Windows aren't always complete and are missing the files
needed to compile additional Apache modules. By default, it is expected
that Apache is installed in the directory ``C:/Apache24`` on Windows.

If you are on Linux, macOS or other UNIX type operating system and can't
or don't want to use the system package for Apache, you can use ``pip``
to install mod_wsgi, but you should use use the ``mod_wsgi-standalone``
package on PyPi instead of the ``mod_wsgi`` package.

Installation into Apache
------------------------

For installation directly into your Apache installation using the CMMI
method, see the full documentation at:

* http://www.modwsgi.org/

Alternatively, use the following instructions to install mod_wsgi into your
Python installation and then either copy the mod_wsgi module into your
Apache installation, or configure Apache to use the mod_wsgi module from
the Python installation.

When using this approach, you will still need to manually configure Apache
to have mod_wsgi loaded into Apache, and for it to know about your WSGI
application.

Installation into Python
------------------------

To install mod_wsgi directly into your Python installation, from within the
source directory of the mod_wsgi package you can run::

    python setup.py install

This will compile mod_wsgi and install the resulting package into your
Python installation.

If wishing to install an official release direct from the Python Package
Index (PyPi), you can instead run::

    pip install mod_wsgi

If you wish to use a version of Apache which is installed into a non
standard location, you can set and export the ``APXS`` environment variable
to the location of the Apache ``apxs`` script for your Apache installation
before performing the installation.

If you are using Linux, macOS or other UNIX type operating system, and you
don't have Apache available, you can instead install mod_wsgi using::

    pip install mod_wsgi-standalone

When installing ``mod_wsgi-standalone``, it will also install a version
of Apache into your Python distribution. You can only use ``mod_wsgi-express``
when using this variant of the package. The ``mod_wsgi-standalone`` package
follows the same version numbering as the ``mod_wsgi`` package on PyPi.

If you are on Windows and your Apache distribution is not installed into
the directory ``C:/Apache24``, first set the environment variable
``MOD_WSGI_APACHE_ROOTDIR`` to the directory containing the Apache
distribution. Ensure you use forward slashes in the directory path. The
directory path should not include path components with spaces in the name.

Note that nothing will be copied into your Apache installation at this
point. As a result, you do not need to run this as the root user unless
installing it into a site wide Python installation rather than a Python
virtual environment. It is recommended you always use Python virtual
environments and never install any Python package directly into the system
Python installation.

On a UNIX type system, to verify that the installation was successful, run
the ``mod_wsgi-express`` script with the ``start-server`` command::

    mod_wsgi-express start-server

This will start up Apache/mod_wsgi on port 8000. You can then verify that
the installation worked by pointing your browser at::

    http://localhost:8000/

When started in this way, the Apache web server will stay in the
foreground. To stop the Apache server, use CTRL-C.

For a simple WSGI application contained in a WSGI script file called
``wsgi.py``, in the current directory, you can now run::

    mod_wsgi-express start-server wsgi.py

This instance of the Apache web server will be completely independent of,
and will not interfere with any existing instance of Apache you may have
running on port 80.

If you already have another web server running on port 8000, you can
override the port to be used using the ``--port`` option::

    mod_wsgi-express start-server wsgi.py --port 8080

For a complete list of options you can run::

    mod_wsgi-express start-server --help

For further information related to using ``mod_wsgi-express`` see the main
mod_wsgi documentation.

Non standard Apache installations
---------------------------------

Many Linux distributions have a tendency to screw around with the standard
Apache Software Foundation layout for installation of Apache. This can
include renaming the Apache ``httpd`` executable to something else, and in
addition to potentially renaming it, replacing the original binary with a
shell script which performs additional actions which can only be performed
as the ``root`` user.

In the case of the ``httpd`` executable simply being renamed, the
executable will obviously not be found and ``mod_wsgi-express`` will fail
to start at all.

In this case you should work out what the ``httpd`` executable was renamed
to and use the ``--httpd-executable`` option to specify its real location.

For example, if ``httpd`` was renamed to ``apache2``, you might need to use::

    mod_wsgi-express start-server wsgi.py --httpd-executable=/usr/sbin/apache2

In the case of the ``httpd`` executable being replaced with a shell script
which performs additional actions before then executing the original
``httpd`` executable, and the shell script is failing in some way, you will
need to use the location of the original ``httpd`` executable the shell
script is in turn executing.

Running mod_wsgi-express as root
--------------------------------

The primary intention of ``mod_wsgi-express`` is to make it easier for
users to run up Apache on non privileged ports, especially during the
development of a Python web application. If you want to be able to run
Apache using ``mod_wsgi-express`` on a privileged port such as the standard
port 80 used by HTTP servers, then you will need to run
``mod_wsgi-express`` as root. In doing this, you will need to perform
additional steps.

The first thing you must do is supply the ``--user`` and ``--group``
options to say what user and group your Python web application should run
as. Most Linux distributions will predefine a special user for Apache to
run as, so you can use that. Alternatively you can use any other special
user account you have created for running the Python web application::

    mod_wsgi-express start-server wsgi.py --port=80 \
        --user www-data --group www-data

This approach to running ``mod_wsgi-express`` will be fine so long as you
are using a process supervisor which expects the process being run to remain
in the foreground and not daemonize.

If however you are directly integrating into the system init scripts where
separate start and stop commands are expected, with the executing process
expected to be daemonized, then a different process is required to setup
``mod_wsgi-express``.

In this case, instead of simply using the ``start-server`` command to
``mod_wsgi-express`` you should use ``setup-server``::

    mod_wsgi-express setup-server wsgi.py --port=80 \
        --user www-data --group www-data \
        --server-root=/etc/mod_wsgi-express-80

In running this command, it will not actually startup Apache. All it will do
is create the set of configuration files and the startup script to be run.

So that these are not created in the default location of a directory under
``/tmp``, you should use the ``--server-root`` option to specify where they
should be placed.

Having created the configuration and startup script, to start the Apache
instance you can now run::

    /etc/mod_wsgi-express-80/apachectl start

To subsequently stop the Apache instance you can run::

    /etc/mod_wsgi-express-80/apachectl stop

You can also restart the Apache instance as necessary using::

    /etc/mod_wsgi-express-80/apachectl restart

Using this approach, the original options you supplied to ``setup-server``
will be cached with the same configuration used each time. If you need to
update the set of options, run ``setup-server`` again with the new set of
options.

Note that even taking all these steps, it is possible that running up
Apache as ``root`` using ``mod_wsgi-express`` may fail on systems where
SELinux extensions are enabled. This is because the SELinux profile may not
match what is being expected for the way that Apache is being started, or
alternatively, the locations that Apache has been specified as being
allowed to access, don't match where the directory specified using the
``--server-root`` directory was placed. You may therefore need to configure
SELinux or move the directory used with ``--server-root`` to an allowed
location.

In all cases, any error messages will be logged to a file under the server
root directory. If you are using ``mod_wsgi-express`` with a process
supervisor, or in a container, where log messages are expected to be sent
to the terminal, you can use the ``--log-to-terminal`` option.

Using mod_wsgi-express with Django
----------------------------------

To use ``mod_wsgi-express`` with Django, after having installed the
mod_wsgi package into your Python installation, edit your Django settings
module and add ``mod_wsgi.server`` to the list of installed apps.

::

    INSTALLED_APPS = (
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'mod_wsgi.server',
    )

To prepare for running ``mod_wsgi-express``, ensure that you first collect
up any Django static file assets into the directory specified for them in
the Django settings file::

    python manage.py collectstatic

You can now run the Apache server with mod_wsgi hosting your Django
application by running::

    python manage.py runmodwsgi

If working in a development environment and you would like to have any code
changes automatically reloaded, then you can use the ``--reload-on-changes``
option.

::

    python manage.py runmodwsgi --reload-on-changes

If wanting to have Apache started as root in order to listen on port 80,
instead of using ``mod_wsgi-express setup-server`` as described above,
use the ``--setup-only`` option to the ``runmodwsgi`` management command.

::

    python manage.py runmodwsgi --setup-only --port=80 \
        --user www-data --group www-data \
        --server-root=/etc/mod_wsgi-express-80
 
This will set up all the required files and you can use ``apachectl`` to
start and stop the Apache instance as explained previously.

Connecting into Apache installation
-----------------------------------

If you want to use mod_wsgi in combination with your system Apache
installation, the CMMI method for installing mod_wsgi would normally be
used.

If you are on MacOS X Sierra that is no longer possible. Even prior to
MacOS X Sierra, the System Integrity Protection (SIP) system of MacOS X,
prevented installing the mod_wsgi module into the Apache modules directory.

If you are using Windows, the CMMI method was never supported as Windows
doesn't supply the required tools to make it work.

The CMMI installation method also involves a bit more work as you need to
separately download the mod_wsgi source code, run the ``configure`` tool
and then run ``make`` and ``make install``.

The alternative to using the CMMI installation method is to use the Apache
mod_wsgi module created by running ``pip install``. This can be directly
referenced from the Apache configuration, or copied into the Apache modules
directory.

To use the Apache mod_wsgi module from where ``pip install`` placed it,
run the command ``mod_wsgi-express module-config``. This will output
something like::

    LoadModule wsgi_module /usr/local/lib/python2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so
    WSGIPythonHome /usr/local/lib

These are the directives needed to configure Apache to load the mod_wsgi
module and tell mod_wsgi where the Python installation directory or virtual
environment was located.

This would be placed in the Apache ``httpd.conf`` file, or if using a Linux
distribution which separates out module configuration into a
``mods-available`` directory, in the ``wsgi.load`` file within the
``mods-available`` directory. In the latter case where a ``mods-available``
directory is used, the module would then be enabled by running
``a2enmod wsgi`` as ``root``. If necessary Apache can then be restarted to
verify the module is loading correctly. You can then configure Apache as
necessary for your specific WSGI application.

Note that because in this scenario the mod_wsgi module for Apache could be
located in a Python virtual environment, if you destroy the Python virtual
environment the module will also be deleted. In that case you would need to
ensure you recreate the Python virtual environment and reinstall the
mod_wsgi package using ``pip``, or, take out the mod_wsgi configuration
from Apache before restarting Apache, else it will fail to startup.

Instead of referencing the mod_wsgi module from the Python installation,
you can instead copy the mod_wsgi module into the Apache installation. To
do that, run the ``mod_wsgi-express install-module`` command, running it as
``root`` if necessary. This will output something like::

    LoadModule wsgi_module modules/mod_wsgi-py27.so
    WSGIPythonHome /usr/local/lib

This is similar to above except that the mod_wsgi module was copied to the
Apache modules directory first and the ``LoadModule`` directive references
it from that location. You should take these lines and configure Apache in
the same way as described above.

Do note that copying the module like this will not work on recent versions
of MacOS X due to the SIP feature of MacOS X.

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.modwsgi.org/",
    "name": "mod-wsgi",
    "maintainer": "Graham Dumpleton",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Graham.Dumpleton@gmail.com",
    "keywords": "mod_wsgi wsgi apache",
    "author": "Graham Dumpleton",
    "author_email": "Graham.Dumpleton@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e9/02/36597a3e2478e20ec55432dd153fd23067d2dc5ec736ae16ccc08905f8cb/mod_wsgi-5.0.1.tar.gz",
    "platform": null,
    "description": "Overview\n--------\n\nThe mod_wsgi package provides an Apache module that implements a WSGI\ncompliant interface for hosting Python based web applications on top of the\nApache web server.\n\n*Note that the major version 5.0 was introduced not because of any new major\nfeatures but because from version 5.0 onwards compatability with Python 2.7 is\nno longer guaranteed. A minimum Python version of 3.8 will be enforced by the\nPython package installation configuration.*\n\nInstallation of mod_wsgi from source code can be performed in one of two\nways.\n\nThe first way of installing mod_wsgi is the traditional way that has been\nused by many software packages. This is where it is installed as a module\ndirectly into your Apache installation using the commands ``configure``,\n``make`` and ``make install``, a method sometimes referred to by the\nacronym CMMI. This method works with most UNIX type systems. It cannot\nbe used on Windows.\n\nThe second way of installing mod_wsgi is to install it as a Python package\ninto your Python installation using the Python ``pip install`` command.\nThis can be used on all platforms, including Windows.\n\nThis second way of installing mod_wsgi will compile not only the Apache\nmodule for mod_wsgi, but will also install a Python module and admin\nscript, which on UNIX type systems can be used to start up a standalone\ninstance of Apache directly from the command line with an auto generated\nconfiguration.\n\nThis later mechanism for installing mod_wsgi using Python ``pip`` is a much\nsimpler way of getting starting with hosting your Python web application.\nIn particular, this installation method makes it very easy to use\nApache/mod_wsgi in a development environment without the need to perform\nany Apache configuration yourself.\n\nThe Apache module for mod_wsgi created when using the ``pip install``\nmethod can still be used with the main Apache installation, via manual\nconfiguration if necessary. As detailed later in these instructions, the\nadmin script installed when you use ``pip install`` can be used to generate\nthe configuration to manually add to the Apache configuration to load\nmod_wsgi.\n\nNote that although MacOS X is a UNIX type system, the ``pip install``\nmethod is the only supported way for installing mod_wsgi.\n\nSince MacOS X Sierra, Apple has completely broken the ability to install\nthird party Apache modules using the ``apxs`` tool normally used for this\ntask. History suggests that Apple will never fix the problem as they have\nbroken things in the past in other ways and workarounds were required as\nthey never fixed those problems either. This time there is no easy\nworkaround as they no longer supply certain tools which are required to\nperform the installation.\n\nThe ``pip install`` method along with the manual configuration of Apache\nis also the method you need to use on Windows.\n\nSystem Requirements\n-------------------\n\nWith either installation method for mod_wsgi, you must have Apache\ninstalled. This must be a complete Apache installation. It is not enough to\nhave only the runtime packages for Apache installed. You must have the\ncorresponding development package for Apache installed, which contains the\nApache header files, as these are required to be able to compile and install\nthird party Apache modules.\n\nSimilarly with Python, you must have a complete Python installation which\nincludes the corresponding development package, which contains the header\nfiles for the Python library.\n\nIf you are running Debian or Ubuntu Linux with Apache 2.2 system packages,\nand were using the Apache prefork MPM you would need both:\n\n* apache2-mpm-prefork\n* apache2-prefork-dev\n\nIf instead you were using the Apache worker MPM, you would need both:\n\n* apache2-mpm-worker\n* apache2-threaded-dev\n\nIf you are running Debian or Ubuntu Linux with Apache 2.4 system packages,\nregardless of which Apache MPM is being used, you would need both:\n\n* apache2\n* apache2-dev\n\nIf you are running RHEL, CentOS or Fedora, you would need both:\n\n* httpd\n* httpd-devel\n\nIf you are using the Software Collections Library (SCL) packages with\nRHEL, CentOS or Fedora, you would need:\n\n* httpd24\n* httpd24-httpd-devel\n\nIf you are running MacOS X, Apache is supplied with the operating system.\nIf running a recent MacOS X version, you will though need to have the Xcode\ncommand line tools installed as well as the Xcode application. The command\nline tools can be installed by running ``xcode-select --install``. The\nXcode application can be installed from the MacOS X App Store. If you are\nusing older MacOS X versions, you may be able to get away with having just\nthe command line tools.\n\nIf you are running Windows, it is recommended you use the Apache\ndistribution from Apache Lounge (www.apachelounge.com). Other Apache\ndistributions for Windows aren't always complete and are missing the files\nneeded to compile additional Apache modules. By default, it is expected\nthat Apache is installed in the directory ``C:/Apache24`` on Windows.\n\nIf you are on Linux, macOS or other UNIX type operating system and can't\nor don't want to use the system package for Apache, you can use ``pip``\nto install mod_wsgi, but you should use use the ``mod_wsgi-standalone``\npackage on PyPi instead of the ``mod_wsgi`` package.\n\nInstallation into Apache\n------------------------\n\nFor installation directly into your Apache installation using the CMMI\nmethod, see the full documentation at:\n\n* http://www.modwsgi.org/\n\nAlternatively, use the following instructions to install mod_wsgi into your\nPython installation and then either copy the mod_wsgi module into your\nApache installation, or configure Apache to use the mod_wsgi module from\nthe Python installation.\n\nWhen using this approach, you will still need to manually configure Apache\nto have mod_wsgi loaded into Apache, and for it to know about your WSGI\napplication.\n\nInstallation into Python\n------------------------\n\nTo install mod_wsgi directly into your Python installation, from within the\nsource directory of the mod_wsgi package you can run::\n\n    python setup.py install\n\nThis will compile mod_wsgi and install the resulting package into your\nPython installation.\n\nIf wishing to install an official release direct from the Python Package\nIndex (PyPi), you can instead run::\n\n    pip install mod_wsgi\n\nIf you wish to use a version of Apache which is installed into a non\nstandard location, you can set and export the ``APXS`` environment variable\nto the location of the Apache ``apxs`` script for your Apache installation\nbefore performing the installation.\n\nIf you are using Linux, macOS or other UNIX type operating system, and you\ndon't have Apache available, you can instead install mod_wsgi using::\n\n    pip install mod_wsgi-standalone\n\nWhen installing ``mod_wsgi-standalone``, it will also install a version\nof Apache into your Python distribution. You can only use ``mod_wsgi-express``\nwhen using this variant of the package. The ``mod_wsgi-standalone`` package\nfollows the same version numbering as the ``mod_wsgi`` package on PyPi.\n\nIf you are on Windows and your Apache distribution is not installed into\nthe directory ``C:/Apache24``, first set the environment variable\n``MOD_WSGI_APACHE_ROOTDIR`` to the directory containing the Apache\ndistribution. Ensure you use forward slashes in the directory path. The\ndirectory path should not include path components with spaces in the name.\n\nNote that nothing will be copied into your Apache installation at this\npoint. As a result, you do not need to run this as the root user unless\ninstalling it into a site wide Python installation rather than a Python\nvirtual environment. It is recommended you always use Python virtual\nenvironments and never install any Python package directly into the system\nPython installation.\n\nOn a UNIX type system, to verify that the installation was successful, run\nthe ``mod_wsgi-express`` script with the ``start-server`` command::\n\n    mod_wsgi-express start-server\n\nThis will start up Apache/mod_wsgi on port 8000. You can then verify that\nthe installation worked by pointing your browser at::\n\n    http://localhost:8000/\n\nWhen started in this way, the Apache web server will stay in the\nforeground. To stop the Apache server, use CTRL-C.\n\nFor a simple WSGI application contained in a WSGI script file called\n``wsgi.py``, in the current directory, you can now run::\n\n    mod_wsgi-express start-server wsgi.py\n\nThis instance of the Apache web server will be completely independent of,\nand will not interfere with any existing instance of Apache you may have\nrunning on port 80.\n\nIf you already have another web server running on port 8000, you can\noverride the port to be used using the ``--port`` option::\n\n    mod_wsgi-express start-server wsgi.py --port 8080\n\nFor a complete list of options you can run::\n\n    mod_wsgi-express start-server --help\n\nFor further information related to using ``mod_wsgi-express`` see the main\nmod_wsgi documentation.\n\nNon standard Apache installations\n---------------------------------\n\nMany Linux distributions have a tendency to screw around with the standard\nApache Software Foundation layout for installation of Apache. This can\ninclude renaming the Apache ``httpd`` executable to something else, and in\naddition to potentially renaming it, replacing the original binary with a\nshell script which performs additional actions which can only be performed\nas the ``root`` user.\n\nIn the case of the ``httpd`` executable simply being renamed, the\nexecutable will obviously not be found and ``mod_wsgi-express`` will fail\nto start at all.\n\nIn this case you should work out what the ``httpd`` executable was renamed\nto and use the ``--httpd-executable`` option to specify its real location.\n\nFor example, if ``httpd`` was renamed to ``apache2``, you might need to use::\n\n    mod_wsgi-express start-server wsgi.py --httpd-executable=/usr/sbin/apache2\n\nIn the case of the ``httpd`` executable being replaced with a shell script\nwhich performs additional actions before then executing the original\n``httpd`` executable, and the shell script is failing in some way, you will\nneed to use the location of the original ``httpd`` executable the shell\nscript is in turn executing.\n\nRunning mod_wsgi-express as root\n--------------------------------\n\nThe primary intention of ``mod_wsgi-express`` is to make it easier for\nusers to run up Apache on non privileged ports, especially during the\ndevelopment of a Python web application. If you want to be able to run\nApache using ``mod_wsgi-express`` on a privileged port such as the standard\nport 80 used by HTTP servers, then you will need to run\n``mod_wsgi-express`` as root. In doing this, you will need to perform\nadditional steps.\n\nThe first thing you must do is supply the ``--user`` and ``--group``\noptions to say what user and group your Python web application should run\nas. Most Linux distributions will predefine a special user for Apache to\nrun as, so you can use that. Alternatively you can use any other special\nuser account you have created for running the Python web application::\n\n    mod_wsgi-express start-server wsgi.py --port=80 \\\n        --user www-data --group www-data\n\nThis approach to running ``mod_wsgi-express`` will be fine so long as you\nare using a process supervisor which expects the process being run to remain\nin the foreground and not daemonize.\n\nIf however you are directly integrating into the system init scripts where\nseparate start and stop commands are expected, with the executing process\nexpected to be daemonized, then a different process is required to setup\n``mod_wsgi-express``.\n\nIn this case, instead of simply using the ``start-server`` command to\n``mod_wsgi-express`` you should use ``setup-server``::\n\n    mod_wsgi-express setup-server wsgi.py --port=80 \\\n        --user www-data --group www-data \\\n        --server-root=/etc/mod_wsgi-express-80\n\nIn running this command, it will not actually startup Apache. All it will do\nis create the set of configuration files and the startup script to be run.\n\nSo that these are not created in the default location of a directory under\n``/tmp``, you should use the ``--server-root`` option to specify where they\nshould be placed.\n\nHaving created the configuration and startup script, to start the Apache\ninstance you can now run::\n\n    /etc/mod_wsgi-express-80/apachectl start\n\nTo subsequently stop the Apache instance you can run::\n\n    /etc/mod_wsgi-express-80/apachectl stop\n\nYou can also restart the Apache instance as necessary using::\n\n    /etc/mod_wsgi-express-80/apachectl restart\n\nUsing this approach, the original options you supplied to ``setup-server``\nwill be cached with the same configuration used each time. If you need to\nupdate the set of options, run ``setup-server`` again with the new set of\noptions.\n\nNote that even taking all these steps, it is possible that running up\nApache as ``root`` using ``mod_wsgi-express`` may fail on systems where\nSELinux extensions are enabled. This is because the SELinux profile may not\nmatch what is being expected for the way that Apache is being started, or\nalternatively, the locations that Apache has been specified as being\nallowed to access, don't match where the directory specified using the\n``--server-root`` directory was placed. You may therefore need to configure\nSELinux or move the directory used with ``--server-root`` to an allowed\nlocation.\n\nIn all cases, any error messages will be logged to a file under the server\nroot directory. If you are using ``mod_wsgi-express`` with a process\nsupervisor, or in a container, where log messages are expected to be sent\nto the terminal, you can use the ``--log-to-terminal`` option.\n\nUsing mod_wsgi-express with Django\n----------------------------------\n\nTo use ``mod_wsgi-express`` with Django, after having installed the\nmod_wsgi package into your Python installation, edit your Django settings\nmodule and add ``mod_wsgi.server`` to the list of installed apps.\n\n::\n\n    INSTALLED_APPS = (\n        'django.contrib.admin',\n        'django.contrib.auth',\n        'django.contrib.contenttypes',\n        'django.contrib.sessions',\n        'django.contrib.messages',\n        'django.contrib.staticfiles',\n        'mod_wsgi.server',\n    )\n\nTo prepare for running ``mod_wsgi-express``, ensure that you first collect\nup any Django static file assets into the directory specified for them in\nthe Django settings file::\n\n    python manage.py collectstatic\n\nYou can now run the Apache server with mod_wsgi hosting your Django\napplication by running::\n\n    python manage.py runmodwsgi\n\nIf working in a development environment and you would like to have any code\nchanges automatically reloaded, then you can use the ``--reload-on-changes``\noption.\n\n::\n\n    python manage.py runmodwsgi --reload-on-changes\n\nIf wanting to have Apache started as root in order to listen on port 80,\ninstead of using ``mod_wsgi-express setup-server`` as described above,\nuse the ``--setup-only`` option to the ``runmodwsgi`` management command.\n\n::\n\n    python manage.py runmodwsgi --setup-only --port=80 \\\n        --user www-data --group www-data \\\n        --server-root=/etc/mod_wsgi-express-80\n \nThis will set up all the required files and you can use ``apachectl`` to\nstart and stop the Apache instance as explained previously.\n\nConnecting into Apache installation\n-----------------------------------\n\nIf you want to use mod_wsgi in combination with your system Apache\ninstallation, the CMMI method for installing mod_wsgi would normally be\nused.\n\nIf you are on MacOS X Sierra that is no longer possible. Even prior to\nMacOS X Sierra, the System Integrity Protection (SIP) system of MacOS X,\nprevented installing the mod_wsgi module into the Apache modules directory.\n\nIf you are using Windows, the CMMI method was never supported as Windows\ndoesn't supply the required tools to make it work.\n\nThe CMMI installation method also involves a bit more work as you need to\nseparately download the mod_wsgi source code, run the ``configure`` tool\nand then run ``make`` and ``make install``.\n\nThe alternative to using the CMMI installation method is to use the Apache\nmod_wsgi module created by running ``pip install``. This can be directly\nreferenced from the Apache configuration, or copied into the Apache modules\ndirectory.\n\nTo use the Apache mod_wsgi module from where ``pip install`` placed it,\nrun the command ``mod_wsgi-express module-config``. This will output\nsomething like::\n\n    LoadModule wsgi_module /usr/local/lib/python2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so\n    WSGIPythonHome /usr/local/lib\n\nThese are the directives needed to configure Apache to load the mod_wsgi\nmodule and tell mod_wsgi where the Python installation directory or virtual\nenvironment was located.\n\nThis would be placed in the Apache ``httpd.conf`` file, or if using a Linux\ndistribution which separates out module configuration into a\n``mods-available`` directory, in the ``wsgi.load`` file within the\n``mods-available`` directory. In the latter case where a ``mods-available``\ndirectory is used, the module would then be enabled by running\n``a2enmod wsgi`` as ``root``. If necessary Apache can then be restarted to\nverify the module is loading correctly. You can then configure Apache as\nnecessary for your specific WSGI application.\n\nNote that because in this scenario the mod_wsgi module for Apache could be\nlocated in a Python virtual environment, if you destroy the Python virtual\nenvironment the module will also be deleted. In that case you would need to\nensure you recreate the Python virtual environment and reinstall the\nmod_wsgi package using ``pip``, or, take out the mod_wsgi configuration\nfrom Apache before restarting Apache, else it will fail to startup.\n\nInstead of referencing the mod_wsgi module from the Python installation,\nyou can instead copy the mod_wsgi module into the Apache installation. To\ndo that, run the ``mod_wsgi-express install-module`` command, running it as\n``root`` if necessary. This will output something like::\n\n    LoadModule wsgi_module modules/mod_wsgi-py27.so\n    WSGIPythonHome /usr/local/lib\n\nThis is similar to above except that the mod_wsgi module was copied to the\nApache modules directory first and the ``LoadModule`` directive references\nit from that location. You should take these lines and configure Apache in\nthe same way as described above.\n\nDo note that copying the module like this will not work on recent versions\nof MacOS X due to the SIP feature of MacOS X.\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "Installer for Apache/mod_wsgi.",
    "version": "5.0.1",
    "project_urls": {
        "Documentation": "https://modwsgi.readthedocs.io/",
        "Homepage": "https://www.modwsgi.org/",
        "Source": "https://github.com/GrahamDumpleton/mod_wsgi",
        "Tracker": "https://github.com/GrahamDumpleton/mod_wsgi/issues"
    },
    "split_keywords": [
        "mod_wsgi",
        "wsgi",
        "apache"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e90236597a3e2478e20ec55432dd153fd23067d2dc5ec736ae16ccc08905f8cb",
                "md5": "ac64e24fededa325df649854fb804275",
                "sha256": "8ed00c45ff04ac0a29b8c022e12b57bc588c99bf3eaba0c43f68a9a32bb74e71"
            },
            "downloads": -1,
            "filename": "mod_wsgi-5.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ac64e24fededa325df649854fb804275",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 498570,
            "upload_time": "2024-10-01T00:17:00",
            "upload_time_iso_8601": "2024-10-01T00:17:00.724995Z",
            "url": "https://files.pythonhosted.org/packages/e9/02/36597a3e2478e20ec55432dd153fd23067d2dc5ec736ae16ccc08905f8cb/mod_wsgi-5.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-01 00:17:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "GrahamDumpleton",
    "github_project": "mod_wsgi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "mod-wsgi"
}
        
Elapsed time: 0.35215s