CentOS6环境下Apache2.4安装mod_wsgi出错,寻求技术支持
Hey there, sorry to hear you're hitting snags getting mod_wsgi set up with Apache 2.4 on CentOS 6—this combo has a few quirks thanks to CentOS 6's outdated base packages and default Apache 2.2 setup. Let's break down the most common issues and fixes step by step:
First, Confirm Your Environment
Before diving into fixes, double-check these basics to avoid going down the wrong path:
- Verify your Apache version with:
Make sure it returns Apache 2.4.x. If you're still on 2.2, you'll need to install Apache 2.4 first (typically via third-party repos like IUS or EPEL).httpd -v - Check your Python version with:
This ensures you're targeting the correct Python runtime during installation.python -V
Common Error 1: Missing Apache 2.4 Development Headers
If you see errors like apxs: command not found or cannot find Apache apxs during compilation, you're missing the Apache 2.4 development packages required to build mod_wsgi.
Fix:
Install the matching Apache 2.4 development tools for your repo:
# For IUS repo users (common for CentOS 6 Apache 2.4 installs) yum install httpd24-devel # For EPEL (if you used this repo for Apache 2.4) yum install httpd-devel
Note: Make sure the devel package matches your installed Apache 2.4 version to avoid compatibility issues.
Common Error 2: Missing Python Development Files
Compiling mod_wsgi requires Python's header files. Errors like Python.h: No such file or directory are a dead giveaway for this problem.
Fix:
Install the Python development package that matches your version:
# For Python 2.7 (default on CentOS 6) yum install python-devel # For Python 3.x (if you installed it via IUS/EPEL) yum install python36-devel # Adjust the version number to match your Python 3 install
Common Error 3: Compilation Fails Due to Outdated System Libraries
CentOS 6's default system libraries (like OpenSSL) are pretty old, which can cause linker or compilation errors (e.g., SSL-related failures).
Fix:
Install the required system development libraries to fill these gaps:
yum install openssl-devel gcc make
Step-by-Step Source Compilation Guide (If Pre-Built Packages Fail)
If pre-built mod_wsgi packages aren't working for your setup, compile from source:
- Download the mod_wsgi source tarball that matches your Python and Apache 2.4 versions.
- Extract the tarball:
tar -xzf mod_wsgi-X.X.X.tar.gz cd mod_wsgi-X.X.X - Configure the build with your specific Apache and Python paths:
Replace./configure --with-apxs=/usr/bin/apxs24 --with-python=/usr/bin/python2.7/usr/bin/apxs24with your actual apxs path (usewhich apxsto find it) and adjust the Python path if you're using a non-default version. - Compile and install:
make && make install
Common Error 4: Apache Can't Load mod_wsgi.so
If Apache fails to start with an error like Cannot load modules/mod_wsgi.so into server, check these quick fixes:
- Confirm
mod_wsgi.soexists in your Apache modules directory (e.g.,/usr/lib64/httpd24/modules/). - Add the correct module load line to your Apache config (e.g.,
/etc/httpd24/conf/httpd.conf):LoadModule wsgi_module modules/mod_wsgi.so - Restart Apache to apply changes:
service httpd24 restart
Alternative: Use Pip to Install mod_wsgi
If compiling feels too tedious, try using pip (make sure you have pip installed first):
pip install mod_wsgi
Then generate the Apache module config with:
mod_wsgi-express module-config
Copy the output lines (they'll look like LoadModule wsgi_module ... and WSGIPythonHome ...) into your Apache config file, then restart Apache.
A quick heads-up: CentOS 6 reached end-of-life in 2020, so you're running on an unsupported system. If possible, upgrading to a newer CentOS/RHEL release would avoid many of these compatibility headaches long-term.
内容的提问来源于stack exchange,提问作者NewbieInWeb

