GrahamDumpleton / mod_wsgi

Source code for Apache/mod_wsgi.
Apache License 2.0
1.02k stars 268 forks source link

Error trying to load module mod_wsgi.so from apache .conf #902

Closed lugearma closed 1 month ago

lugearma commented 2 months ago

Hi everyone,

I've got a django app, I'm building an API rest that I want to consume from an iOS app. For some reason when I send the authentication header from postman it works, but when I send from the iOS app it doesn't work. So i guees mod_wsgi can help me in this case. tbh i don't have almost any experience doing server things.

I already installed the module with pip install mod-wsgi. Also I already modified my apache .conf file like this:

LoadModule wsgi_module "/Users/luisarias/Library/Python/3.9/lib/python/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-darwin.so"

WSGIPassAuthorization On

but for some reason when I run apachectl restart I got this error:

httpd: Syntax error on line 534 of /opt/homebrew/etc/httpd/httpd.conf: Cannot load /Users/luisarias/Library/Python/3.9/lib/python/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-darwin.so into server: dlopen(/Users/luisarias/Library/Python/3.9/lib/python/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-darwin.so, 0x000A): Library not loaded: @rpath/Python3.framework/Versions/3.9/Python3\n Referenced from: <0D7390A5-B72F-3A13-A8B7-7EA7C13F7CE1> /Users/luisarias/Library/Python/3.9/lib/python/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-darwin.so\n Reason: no LC_RPATH's found

and also when I do mod_wsgi-express start-server i get sth like this:

Server URL         : http://localhost:8000/
Server Root        : /var/tmp/mod_wsgi-localhost:8000:501
Server Conf        : /var/tmp/mod_wsgi-localhost:8000:501/httpd.conf
Error Log File     : /var/tmp/mod_wsgi-localhost:8000:501/error_log (warn)
Operating Mode     : daemon
Request Capacity   : 5 (1 process * 5 threads)
Request Timeout    : 60 (seconds)
Startup Timeout    : 15 (seconds)
Queue Backlog      : 100 (connections)
Queue Timeout      : 45 (seconds)
Server Capacity    : 20 (event/worker), 20 (prefork)
Server Backlog     : 500 (connections)
Locale Setting     : en_US.UTF-8
[Tue Aug 13 19:51:46.891636 2024] [so:error] [pid 56567:tid 8621460480] AH06665: No code signing authority for module at /Users/luisarias/Library/Python/3.9/lib/python/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-darwin.so specified in LoadModule directive.
httpd (mod_wsgi-express) : Syntax error on line 163 of /var/tmp/mod_wsgi-localhost:8000:501/httpd.conf: Code signing absent - not loading module at: /Users/luisarias/Library/Python/3.9/lib/python/site-packages/mod_wsgi/server/mod_wsgi-py39.cpython-39-darwin.so

have anyone faced the same issue ?? is there anything i'm doing wrong ?? Hope someone can helpme :)

Thanks

GrahamDumpleton commented 2 months ago

For the first case, where have you got your Python distribution from? It doesn't seem to be a standard distribution from Homebrew or Python Software Foundation since they would not usually use a location under ~/Library.

As to the second issue, you cannot use macOS system Apache httpd package as it requires signing of Apache modules. You need to use Homebrew version of Apache httpd on macOS if you have it available.

If you accidentally used macOS system Apache httpd before Homebrew Apache httpd was installed, ensure when run pip install subsequently that you use:

pip install -U --no-cache-dir mod_wsgi

IOW, use --no-cache-dir else it will use prior version built against macOS system Apache httpd.

lugearma commented 2 months ago

About the python distribution tbh i don't remember how and where i got it :( What should I do ?? should I uninstall it and install it again ??

About the second one, how can i use the httpd from homebrew ? I already installed using brew install httpd then reinstall mod_wsgi as you told me but didn't work, I got same error.

GrahamDumpleton commented 2 months ago

So long as you have /usr/local/bin before macOS paths for Xcode stuff, then /usr/local/bin/apxs should be found in your path first and use that.

If PATH doesn't have /usr/local/bin first or perhaps Xcode uses apxs2 instead, then the latter may be found.

From memory you can do:

APXS=/usr/local/bin/apxs pip install -U --no-cache-dir mod_wsgi

What do you get when you run:

which apxs
which apxs2

As to Python distro, since you likely have /usr/local/bin/python3 being Homebrew version, make sure it is in PATH before your other version.

What do you get when you run:

which python3
ls -las /usr/local/bin/python*
lugearma commented 2 months ago

this is what i get from each command:

which apxs
/opt/homebrew/bin/apxs
which apxs2
apxs2 not found
which python3
/usr/bin/python3
ls -las /usr/local/bin/python*
0 lrwxr-xr-x  1 root  wheel  70 Aug 13 14:44 /usr/local/bin/python3 -> ../../../Library/Frameworks/Python.framework/Versions/3.12/bin/python3
0 lrwxr-xr-x  1 root  wheel  77 Aug 13 14:44 /usr/local/bin/python3-config -> ../../../Library/Frameworks/Python.framework/Versions/3.12/bin/python3-config
0 lrwxr-xr-x  1 root  wheel  78 Aug 13 14:44 /usr/local/bin/python3-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.12/bin/python3-intel64
0 lrwxr-xr-x  1 root  wheel  73 Aug 13 14:44 /usr/local/bin/python3.12 -> ../../../Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12
0 lrwxr-xr-x  1 root  wheel  80 Aug 13 14:44 /usr/local/bin/python3.12-config -> ../../../Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12-config
0 lrwxr-xr-x  1 root  wheel  81 Aug 13 14:44 /usr/local/bin/python3.12-intel64 -> ../../../Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12-intel64
GrahamDumpleton commented 2 months ago

Make sure /usr/local/bin is at the start of PATH. In other words, is set as:

PATH="/usr/local/bin:$PATH"

and not:

PATH=$PATH:/usr/local/bin

That way python3 from /usr/local/bin will be found in preference to system Python.

Otherwise ensure you use Python virtual environments and that when creating the Python virtual environment use:

/usr/local/bin/python3 -m venv path/to/venv

That way when activate the Python virtual environment will use Homebrew Python.

GrahamDumpleton commented 1 month ago

Closing as no further followup and so assumed was resolved.