CentOS 6服务器下如何为编译后的二进制CGI脚本启用32位支持?
Hey there! Let's get that 32-bit CGI binary up and running smoothly on your CentOS 6 Apache server. Here's a step-by-step breakdown to fix this:
1. Install Required 32-bit System Libraries
CentOS 6 64-bit systems don't include 32-bit libraries by default. You'll need to install the essential 32-bit runtime dependencies first:
yum install glibc.i686 libgcc.i686
These packages provide the core 32-bit C library and GCC runtime support that your compiled binary needs to execute. If your CGI script relies on additional libraries (like OpenSSL, MySQL, etc.), you'll need to install their corresponding 32-bit packages too (e.g., openssl.i686, mysql-libs.i686).
2. Verify 32-bit Dependencies for Your CGI Binary
To check if all required 32-bit libraries are installed, run:
ldd /path/to/your/cgi-binary
Look for any lines marked not found—those indicate missing libraries you'll need to install via yum (using the .i686 package name). If all dependencies are listed with valid paths, you're good to go.
3. Ensure Apache CGI Configuration is Correct
Double-check your Apache config (usually in /etc/httpd/conf/httpd.conf or /etc/httpd/conf.d/ files) to make sure CGI execution is enabled for your script's directory:
# Example CGI configuration ScriptAlias /cgi-bin/ /var/www/cgi-bin/ <Directory "/var/www/cgi-bin"> AllowOverride None Options +ExecCGI Order allow,deny Allow from all # Explicitly set handler for binary CGI scripts AddHandler cgi-script .cgi .bin </Directory>
Don't forget to set executable permissions on your CGI binary:
chmod +x /path/to/your/cgi-binary
4. Test the Binary Directly (Before Apache)
To rule out Apache-specific issues, run the CGI binary directly from the command line:
/path/to/your/cgi-binary
If it executes without errors and outputs valid CGI content (like Content-Type: text/html followed by HTML), then the binary itself is working correctly. Any errors here will help you pinpoint remaining dependency or compilation issues.
5. Restart Apache to Apply Changes
Once everything checks out, restart the Apache service to ensure all config changes take effect:
service httpd restart
Additional Notes
- If you compiled the CGI script yourself, ensure you either compiled it on a 32-bit CentOS 6 system, or used cross-compilation flags targeting the i386 architecture (e.g.,
gcc -m32for C/C++ code). - If you still encounter issues, check Apache's error logs (
/var/log/httpd/error_log) for specific error messages—they'll often give you clues about missing libraries or permission problems.
内容的提问来源于stack exchange,提问作者Justin Duncan

