httpd赢得了从自定义conf文件开始,mod_wsgi用python 3.9构建

发布于 2025-02-06 08:15:56 字数 4594 浏览 3 评论 0 原文

我正在使用Redhat Centos 7盒子工作。我已经将Python 3.9.2安装到/opt/python3.9 下的文件夹中。我正在将Django服务器移至生产中,并选择使用Apache(我已经安装了MOD_WSGI安装 httpd-devel )。我正遵循他们的 >确保其配置正确。

我安装了Apache:

sudo yum install httpd
sudo yum install httpd-devel

然后

wget https://github.com/GrahamDumpleton/mod_wsgi/archive/refs/tags/4.9.2.tar.gz
mv 4.9.2.tar.gz ./mod_wsgi_4.9.2.tar.gz
tar xvfz mod_wsgi-4.9.2.tar.gz
cd mod_wsgi*
./configure --with-python=/opt/python3.9/bin/python39
make
sudo make install

全部没有错误。

sudo systemctl enable httpd
sudo systemctl start httpd

但是,一旦我尝试使用demo (基本上需要将conf文件添加到 /etc/httpd/conf.d/,称为 wsgi.conf ,以及响应文件到/var/www/html/,称为 test_wsgi.py ,然后重新启动apache),它会引发错误,并告诉我检查 journe> journal> journalctl -xe

Jun 08 21:04:01 ip-172-31-18-8.ec2.internal httpd[11893]: AH00526: Syntax error on line 2 of /etc/httpd/conf.d/wsgi.conf:
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal httpd[11893]: Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the server configuration
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit httpd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit httpd.service has failed.
--
-- The result is failed.
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: Unit httpd.service entered failed state.
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: httpd.service failed.
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal sudo[11888]: pam_unix(sudo:session): session closed for user root

我95%肯定的是,如果我做了建议的在这里想要使用python2.7 ...这就是为什么我为python 3.9.2编译了mod_wsgi。

如果我尝试使用我的django.conf文件,而不是我在演示中链接的文件,我会收到一个不同的错误,可能对slue更有帮助:

httpd.conf: Syntax error on line 3 of /etc/httpd/conf.d/django.conf: Cannot load /usr/lib64/httpd/modules/mod_wsgi.so into server: libpython3.9.so.1.0: cannot open shared object file: No such file or directory

第3行是:

LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so

ldd/usr/lib64/httpd的输出。 /modules/mod_wsgi.so

[ec2-user@ip-172-31-18-8 ~]$ ldd /usr/lib64/httpd/modules/mod_wsgi.so
        linux-vdso.so.1 (0x00007ffd7b50d000)
        libpython3.9.so.1.0 => /opt/python39/lib/libpython3.9.so.1.0 (0x00007ff0ebf85000)
        libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007ff0ebd4e000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff0ebb30000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007ff0eb92c000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007ff0eb729000)
        libm.so.6 => /lib64/libm.so.6 (0x00007ff0eb3e9000)
        libc.so.6 => /lib64/libc.so.6 (0x00007ff0eb03e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff0ec781000)

我可以验证/opt/python39/lib/libpython3.9.so.1.0存在,并且我将其保存在我的 ld_run_path和

ld_library_path代码> sudo apachectl -v :

Server version: Apache/2.4.53 ()
Server built:   Apr 12 2022 12:00:44
Server's Module Magic Number: 20120211:124
Server loaded:  APR 1.7.0, APR-UTIL 1.6.1, PCRE 8.32 2012-11-30
Compiled using: APR 1.7.0, APR-UTIL 1.6.1, PCRE 8.32 2012-11-30
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_PROC_PTHREAD_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="/run/httpd/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

I am working on a RedHat Centos 7 box. I have installed python 3.9.2 into a folder under /opt/python3.9. I am in the midst of moving my Django server to production, and have chosen to use Apache (I have installed httpd-devel) with mod_wsgi. I was in the midst of following their instructions to make sure it gets configured correctly.

I installed Apache:

sudo yum install httpd
sudo yum install httpd-devel

then

wget https://github.com/GrahamDumpleton/mod_wsgi/archive/refs/tags/4.9.2.tar.gz
mv 4.9.2.tar.gz ./mod_wsgi_4.9.2.tar.gz
tar xvfz mod_wsgi-4.9.2.tar.gz
cd mod_wsgi*
./configure --with-python=/opt/python3.9/bin/python39
make
sudo make install

all with no errors.

sudo systemctl enable httpd
sudo systemctl start httpd

But as soon as I try to use the demo here (which basically entails adding a conf file to /etc/httpd/conf.d/, called wsgi.conf, and a response file to /var/www/html/, called test_wsgi.py, then restarting Apache), it throws an error and tells me to check journalctl -xe.

Jun 08 21:04:01 ip-172-31-18-8.ec2.internal httpd[11893]: AH00526: Syntax error on line 2 of /etc/httpd/conf.d/wsgi.conf:
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal httpd[11893]: Invalid command 'WSGIScriptAlias', perhaps misspelled or defined by a module not included in the server configuration
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: Unit httpd.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit httpd.service has failed.
--
-- The result is failed.
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: Unit httpd.service entered failed state.
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal systemd[1]: httpd.service failed.
Jun 08 21:04:01 ip-172-31-18-8.ec2.internal sudo[11888]: pam_unix(sudo:session): session closed for user root

I am 95% certain that if I did what was suggested here that it would compile mod_wsgi for Python 2.7 and I don't want to use python2.7... that's why I compiled mod_wsgi for python 3.9.2.

If I try to use my django.conf file instead of the one I linked in the demo, I get a different error that might be more helpful for the slue:

httpd.conf: Syntax error on line 3 of /etc/httpd/conf.d/django.conf: Cannot load /usr/lib64/httpd/modules/mod_wsgi.so into server: libpython3.9.so.1.0: cannot open shared object file: No such file or directory

Line 3 is:

LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so

Output of ldd /usr/lib64/httpd/modules/mod_wsgi.so:

[ec2-user@ip-172-31-18-8 ~]$ ldd /usr/lib64/httpd/modules/mod_wsgi.so
        linux-vdso.so.1 (0x00007ffd7b50d000)
        libpython3.9.so.1.0 => /opt/python39/lib/libpython3.9.so.1.0 (0x00007ff0ebf85000)
        libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007ff0ebd4e000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff0ebb30000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007ff0eb92c000)
        libutil.so.1 => /lib64/libutil.so.1 (0x00007ff0eb729000)
        libm.so.6 => /lib64/libm.so.6 (0x00007ff0eb3e9000)
        libc.so.6 => /lib64/libc.so.6 (0x00007ff0eb03e000)
        /lib64/ld-linux-x86-64.so.2 (0x00007ff0ec781000)

I can verify that /opt/python39/lib/libpython3.9.so.1.0 exists and I have it in my LD_RUN_PATH and LD_LIBRARY_PATH variables

Output of sudo apachectl -V:

Server version: Apache/2.4.53 ()
Server built:   Apr 12 2022 12:00:44
Server's Module Magic Number: 20120211:124
Server loaded:  APR 1.7.0, APR-UTIL 1.6.1, PCRE 8.32 2012-11-30
Compiled using: APR 1.7.0, APR-UTIL 1.6.1, PCRE 8.32 2012-11-30
Architecture:   64-bit
Server MPM:     prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_PROC_PTHREAD_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="/run/httpd/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想你的星星会说话 2025-02-13 08:15:57

您正在看到此错误...

libpython3.9.so.1.0: cannot open shared object file: No such file or directory

...因为 httpd 不知道它应该在/opt/python3.9/lib 中查找必要的共享库。解决此问题有几种方法:

  1. set -rpath 链接模块时。

    这嵌入到编译二进制中的库中的路径。您将通过在 mod_wsgi-4.9.2 目录中运行 make 来设置它。目录:

      make ldflags =' -  l/opt/python3.9/lib -wl,-rpath,/opt/python3.9/lib'
     
  2. set ld_library_path in httpd 的环境。这提供了
    httpd 带有其他目录列表以搜索共享
    库。我们可以这样测试:

      ld_library_path =/opt/python3.9/lib httpd -dforeground
     

    要持续设置它,您需要自定义 httpd
    服务单位:

    • 运行 SytemCtl编辑httpd

    • 在出现的编辑器中,添加以下内容:

        [服务]
      环境= ld_library_path =/opt/python3.9/lib
       

      这会创造
      /etc/systemd/system/httpd.service.d/override.conf

    • 运行 Systemctl守护程序 - reload 刷新单元文件的缓存版本。

    • 重新启动您的 httpd 服务。

  3. 通过创建编辑全局库搜索路径
    /etc/ld.so.conf.d/python3.9.conf 带有以下内容:

     /opt/python3.9/lib
     

    然后运行:

      ldconfig
     

以上任何选项都应使您为您运行。

You are seeing this error...

libpython3.9.so.1.0: cannot open shared object file: No such file or directory

...because httpd has no idea it's supposed to look in /opt/python3.9/lib to find the necessary shared library. There are several ways of resolving this problem:

  1. Set -rpath when linking the module.

    This embeds a path to the library in the compiled binary. You would set it by running make like this inside the mod_wsgi-4.9.2 directory:

    make LDFLAGS='-L/opt/python3.9/lib -Wl,-rpath,/opt/python3.9/lib'
    
  2. Set LD_LIBRARY_PATH in httpd's environment. This provides
    httpd with an additional list of directories to search for shared
    libraries. We can test it like this:

    LD_LIBRARY_PATH=/opt/python3.9/lib httpd -DFOREGROUND
    

    To set it persistently, you'd want to customize the httpd
    service unit:

    • Run systemctl edit httpd

    • In the editor that comes up, add the following content:

      [Service]
      Environment=LD_LIBRARY_PATH=/opt/python3.9/lib
      

      This creates
      /etc/systemd/system/httpd.service.d/override.conf.

    • Run systemctl daemon-reload to refresh the cached version of the unit file.

    • Restart your httpd service.

  3. Edit the global library search path by creating
    /etc/ld.so.conf.d/python3.9.conf with the following content:

    /opt/python3.9/lib
    

    Then run:

    ldconfig
    

Any of the above options should get things running for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文