|
| 1 | +======================= |
| 2 | +Installation On MacOS X |
| 3 | +======================= |
| 4 | + |
| 5 | +If you are using MacOS X, mod_wsgi can be compiled from source code |
| 6 | +against the standard versions of Python and Apache httpd server supplied |
| 7 | +with the operating system. To do this though you will first need to have |
| 8 | +installed the Xcode command line tools. |
| 9 | + |
| 10 | +The Xcode command line tools package provides a C compiler, along with |
| 11 | +header files and support tools for the Apache httpd server. If you have |
| 12 | +already set up your system so as to be able to install additional Python |
| 13 | +packages which include C extensions, you likely will already have the |
| 14 | +Xcode command line tools. |
| 15 | + |
| 16 | +Install Xcode command line tools |
| 17 | +-------------------------------- |
| 18 | + |
| 19 | +To install the Xcode command line tools you should run the command:: |
| 20 | + |
| 21 | + xcode-select --install |
| 22 | + |
| 23 | +If this gives you back the error message:: |
| 24 | + |
| 25 | + xcode-select: error: command line tools are already installed, use "Software Update" to install updates |
| 26 | + |
| 27 | +then the tools have already been installed. As noted by the warning |
| 28 | +message, do make sure you have run a system software update to ensure |
| 29 | +that you have the latest versions of these tools. |
| 30 | + |
| 31 | +If you do not already have the Xcode command line tools installed, running |
| 32 | +that ``xcode-select`` command should result in you being prompted to |
| 33 | +install them. This may ask you to provide the details of an administrator |
| 34 | +account along with the password for that account. |
| 35 | + |
| 36 | +Note that it is not necessary to install the whole of the Xcode |
| 37 | +developer application from the MacOS X App Store, only the command line |
| 38 | +tools using ``xcode-select``. If you have installed the Xcode developer |
| 39 | +application, still ensure that the command line tools are installed and |
| 40 | +ensure you have run the system software update. |
| 41 | + |
| 42 | +Configuring and building mod_wsgi |
| 43 | +--------------------------------- |
| 44 | + |
| 45 | +If you are using the Python and Apache httpd server packages provided with |
| 46 | +the operating system, all you need to do to configure the mod_wsgi source |
| 47 | +code before building it is to run in the mod_wsgi source code directory:: |
| 48 | + |
| 49 | + ./configure |
| 50 | + |
| 51 | +This should yield output similar to:: |
| 52 | + |
| 53 | + checking for apxs2... no |
| 54 | + checking for apxs... /usr/sbin/apxs |
| 55 | + checking for gcc... gcc |
| 56 | + checking whether the C compiler works... yes |
| 57 | + checking for C compiler default output file name... a.out |
| 58 | + checking for suffix of executables... |
| 59 | + checking whether we are cross compiling... no |
| 60 | + checking for suffix of object files... o |
| 61 | + checking whether we are using the GNU C compiler... yes |
| 62 | + checking whether gcc accepts -g... yes |
| 63 | + checking for gcc option to accept ISO C89... none needed |
| 64 | + checking for prctl... no |
| 65 | + checking Apache version... 2.4.18 |
| 66 | + checking for python... /usr/bin/python |
| 67 | + configure: creating ./config.status |
| 68 | + config.status: creating Makefile |
| 69 | + |
| 70 | +The ``configure`` script should show that it has detected ``apxs`` as being |
| 71 | +located at ``/usr/sbin/apxs`` and ``python`` as being at ``/usr/bin/python``. |
| 72 | + |
| 73 | +If you get different values for ``apxs`` and ``python`` then it means |
| 74 | +that you likely have a separate installation of Python or the Apache |
| 75 | +httpd server installed on your system. If this is the case, to ensure that |
| 76 | +you use the versions of Python and Apache httpd server provided with the |
| 77 | +operating system instead use the command:: |
| 78 | + |
| 79 | + ./configure --with-python=/usr/bin/python --with-apxs=/usr/sbin/apxs |
| 80 | + |
| 81 | +Once you have configured the source code by running ``configure``, you |
| 82 | +can build mod_wsgi using the command:: |
| 83 | + |
| 84 | + make |
| 85 | + |
| 86 | +This will compile the mod_wsgi source code and produce a single |
| 87 | +``mod_wsgi.so`` file which then needs to be installed into a common |
| 88 | +location so that the Apache httpd server can use it. |
| 89 | + |
| 90 | +Installing the mod_wsgi module |
| 91 | +------------------------------ |
| 92 | + |
| 93 | +What you need to do to install the mod_wsgi module depends on which version |
| 94 | +of MacOS X you are using. |
| 95 | + |
| 96 | +For the Apache httpd server provided by the operating system, the directory |
| 97 | +``/usr/libexec/apache2`` is used to store the compiled modules. Prior to |
| 98 | +MacOS X El Capitan (10.11) this directory was writable and the mod_wsgi |
| 99 | +module could be installed here along with all the default modules. With the |
| 100 | +introduction of the System Integrity Protection (SIP_) feature in MacOS X |
| 101 | +El Capitan this directory is not writable, not even to the root user. |
| 102 | + |
| 103 | +Because of this, if you are using a version of MacOS X prior to MacOS X El |
| 104 | +Capitan (10.11) you can use the command:: |
| 105 | + |
| 106 | + sudo make install |
| 107 | + |
| 108 | +to install the mod_wsgi module. As ``sudo`` is being run, you will be |
| 109 | +prompted for your password. The module will be installed into the |
| 110 | +directory ``/usr/libexec/apache2``. Within the Apache httpd server |
| 111 | +configuration file you can then use the standard ``LoadModule`` line |
| 112 | +of:: |
| 113 | + |
| 114 | + LoadModule wsgi_module libexec/apache2/mod_wsgi.so |
| 115 | + |
| 116 | +If however you are using MacOS X El Capitan (10.11) or later, the mod_wsgi |
| 117 | +module will need to be installed into a different location. If you don't |
| 118 | +and try to run just ``sudo make install``, it will fail with the output:: |
| 119 | + |
| 120 | + ./apxs -i -S LIBEXECDIR=/usr/libexec/apache2 -n 'mod_wsgi' src/server/mod_wsgi.la |
| 121 | + /usr/share/httpd/build/instdso.sh SH_LIBTOOL='./libtool' src/server/mod_wsgi.la /usr/libexec/apache2 |
| 122 | + ./libtool --mode=install install src/server/mod_wsgi.la /usr/libexec/apache2/ |
| 123 | + libtool: install: install src/server/.libs/mod_wsgi.so /usr/libexec/apache2/mod_wsgi.so |
| 124 | + install: /usr/libexec/apache2/mod_wsgi.so: Operation not permitted |
| 125 | + apxs:Error: Command failed with rc=4653056 |
| 126 | + . |
| 127 | + make: *** [install] Error 1 |
| 128 | + |
| 129 | +The directory you use to install the mod_wsgi module is up to you, but |
| 130 | +one suggested option is that you use the directory |
| 131 | +``/usr/local/httpd/modules``. Just ensure that this isn't already used |
| 132 | +by a separate installation of the Apache httpd server. |
| 133 | + |
| 134 | +To install the mod_wsgi module into this directory use the command:: |
| 135 | + |
| 136 | + sudo make install LIBEXECDIR=/usr/local/httpd/modules |
| 137 | + |
| 138 | +The output from the command will be similar to:: |
| 139 | + |
| 140 | + mkdir -p /usr/local/httpd/modules |
| 141 | + ./apxs -i -S LIBEXECDIR=/usr/local/httpd/modules -n 'mod_wsgi' src/server/mod_wsgi.la |
| 142 | + /usr/share/httpd/build/instdso.sh SH_LIBTOOL='./libtool' src/server/mod_wsgi.la /usr/local/httpd/modules |
| 143 | + ./libtool --mode=install install src/server/mod_wsgi.la /usr/local/httpd/modules/ |
| 144 | + libtool: install: install src/server/.libs/mod_wsgi.so /usr/local/httpd/modules/mod_wsgi.so |
| 145 | + libtool: install: install src/server/.libs/mod_wsgi.lai /usr/local/httpd/modules/mod_wsgi.la |
| 146 | + libtool: install: install src/server/.libs/mod_wsgi.a /usr/local/httpd/modules/mod_wsgi.a |
| 147 | + libtool: install: chmod 644 /usr/local/httpd/modules/mod_wsgi.a |
| 148 | + libtool: install: ranlib /usr/local/httpd/modules/mod_wsgi.a |
| 149 | + libtool: install: warning: remember to run `libtool --finish /usr/libexec/apache2' |
| 150 | + chmod 755 /usr/local/httpd/modules/mod_wsgi.so |
| 151 | + |
| 152 | +The warning about needing to run ``libtool --finish`` can be ignored as it |
| 153 | +is not required for everything to work. |
| 154 | + |
| 155 | +With the mod_wsgi module installed in this location, the ``LoadModule`` line |
| 156 | +in the Apache httpd configuration file should be:: |
| 157 | + |
| 158 | + LoadModule wsgi_module /usr/local/httpd/modules/mod_wsgi.so |
| 159 | + |
| 160 | +Normal steps to then configure the Apache httpd server and mod_wsgi for |
| 161 | +your specific WSGI application would then be followed. |
| 162 | + |
| 163 | +.. _SIP: https://en.wikipedia.org/wiki/System_Integrity_Protection |
0 commit comments