CentOS 6.8 64位(PHP5.6+WHM)启用PHP curl扩展及报错排查
Let's work through your cURL issues one by one, based on your CentOS 6.8 64-bit setup with PHP 5.6 and WHM panel.
First, let's confirm your system-level cURL is installed correctly—your output checks out:
[root@s5 ~]# curl -V curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz [root@s5 ~]#
Step 1: Enable PHP's cURL Extension
Since you mentioned needing to enable this in php.ini, here are two reliable ways to do it with your WHM setup:
Option 1: Use WHM's PHP Configuration Editor
- Log into your WHM panel
- Navigate to Software > MultiPHP INI Editor
- Select the Editor Mode tab, then choose PHP 5.6 from the dropdown
- Look for the line starting with
;extension=curl.so—remove the semicolon (;) at the beginning to uncomment it - Click Save to apply changes, then restart your PHP-FPM or Apache service (you can do this via WHM's Restart Services section)
Option 2: Manual php.ini Edit
- First, find the correct
php.inipath for PHP 5.6. Run this command as root:php56 -i | grep "Loaded Configuration File" - Open the file with a text editor (like
viornano):nano /path/to/your/php.ini - Find the line
;extension=curl.so, remove the leading semicolon to enable the extension - Save the file, then restart your web server or PHP service:
service httpd restart # Or if using PHP-FPM: service php-fpm56 restart - Verify the extension is loaded by running
php56 -m | grep curl—you should seecurlin the output.
Step 2: Fix cURL Error 56 (Received HTTP code 405 from proxy after CONNECT)
This error happens when the proxy server you're using rejects the CONNECT request (which is required to establish a secure tunnel for HTTPS requests). Here are the most common fixes:
Check for unintended proxy settings: If you don't actually need a proxy for your cURL request, make sure your PHP code isn't setting
CURLOPT_PROXYor related options. Also, check system-wide environment variables:echo $http_proxy echo $https_proxyIf these are set but shouldn't be, unset them temporarily with
unset http_proxyandunset https_proxy, then test your cURL request again.Verify proxy supports CONNECT method: If you do need to use a proxy, confirm with your proxy provider that it allows
CONNECTrequests for the target HTTPS port (usually 443). Some proxies blockCONNECTby default for security reasons.Adjust proxy settings in your cURL call: If your proxy requires specific configuration, try explicitly setting the proxy type in your PHP code:
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);Or if you're using a SOCKS proxy, use
CURLPROXY_SOCKS5instead.Check WHM/firewall rules: WHM's built-in security tools (like CSF) or your server firewall might be blocking outgoing
CONNECTrequests. Temporarily disable the firewall (for testing only!) or add a rule to allow outbound traffic to port 443 viaCONNECT.Consider upgrading cURL (last resort): Your system cURL version (7.19.7) is quite old—released in 2010. While it should work for most cases, newer versions have better proxy handling and bug fixes. On CentOS 6, you can install a newer version via EPEL or compile it from source, but be cautious: upgrading system libraries can affect WHM/cPanel functionality, so test in a staging environment first if possible.
内容的提问来源于stack exchange,提问作者DolDurma

